npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hammer-time

v2.0.1

Published

Flood a socket.io server with messages

Downloads

86

Readme

build status

hammer-time

Greenkeeper badge

Create a swarm of socket.io clients to stress test your socket-based application. Provides hooks to allow for HTTP based authentication to be passed into the socket connection requests if necessary, as well as listening to and responding to various socket events.

Install/Run

npm i -g hammer-time
hammer-time example.com --port 9000 --concurrent 50 --frequency 6000 --duration 100000 --generator my-gen.js

Usage

Usage: hammer-time [host] -p [port] -c [concurrency] -f [frequency] -d [duration] -g [generator]

Options:
  --version     Print the version number
  -p, --port        What port to use. Default = 80
  -c, --concurrent  How many clients to run concurrently. Default = 100
  -f, --frequency   Frequency of client messages (ms). Default = 50
  -d, --duration    Length of test (ms). Default = 60000 (1 minute)
  -g, --generator   Name of generator file to load, if any. This will specify
                    the details of how to connect and authenticate to your socket server
  -v, --verbose     Be extremely loud about what it is doing

Programmatic Access

hammer-time is also available as module that can be used outside of the scope of the CLI. (This is how the tests are run!). The arguments to the method are the same (and in the same order!) as the CLI, with the addition of an optional callback to be called when the tests are complete. The method returns an event emitter which you can use for monitoring the process. The CLI interface is a great example of how this works.

var ht = require('hammer-time');
ht(host, port, concurrent, frequency, duration, generator)
	.on('start', function(){
		console.log('hammer time is starting');
	})
	.on('error', function(err){
		console.log(err);
	});

Events

  • start → The client has started, but not asked any clients to yet connect
  • client-connected → A client has connected to the server and the handshake is complete. If you have an event named connect, in your exports.events object, that method will be called immediately after this message is emitted.
  • message → A client has sent a message to the server, the message is passed as an argument
  • disconnect → A client has disconnected from the server
  • end → hammer-time has run for the set duration
  • error → hammer-time encountered as an error. The error is passed as an argument

Generator

Generators allow you to set custom authentication methods, listeners for the socket, and what message(s) the client should send to flood the server.

The generator should export the following symbols (none of these are required, but it might not do much if you don't provide one).

See examples/default-generator.js for an example of how this works.

  • exports.eventsobject of functions where the key is the event name, and the value is the function to run for that event
{
  [eventname]: function(event name, cookies, username, password, message data, socket object, emitter returned from API)
}

The function's signature is:

/**
 * Respond to an event
 * @method event
 * @param  {string} the name of the event you're responding to
 * @param  {object} any cookies returned from your auth method
 * @param  {string} the username that was used for authenticating this socket
 * @param  {string} the password that was used for authenticating this socket
 * @param  {object} the message from the socket.io server
 * @param  {object} the socket client
 * @param  {object} the emitter returned from the function. Allows you to emit data to the CLI or other listeners
 */
  • exports.authenticatefunction(host, port, iteration, cb)
/**
 * Authenticate for a client
 * @method  authenticate
 * @async
 * @param   {string} host hostname
 * @param   {integer} port portname
 * @param   {integer} iteration what client number to generate
 * @param   {Function} cb `err` on error, `err`, `cookies`, `username`, `password` on success
 * @returns {object} undefined
 */

note: cookies should be an object of parsed cookies, and username, password will be the credentials used to authenicate. If authenication fails, the callback should receive an error

  • exports.getSocketUrlfunction(host, port, cookies)
/**
 * Returns the URL to send to the `io.connect` method.
 * @method  getSocketURL
 * @param   {string} host host name
 * @param   {integer} port port
 * @param   {object} cookies if you need them
 * @returns {string} The URL that should be passed to the socket.io constructor
 */
  • exports.clientIterateMessagefunction(cookies, user, pass)
/**
 * Returns a message to send to the client
 * @method  clientIterateMessage
 * @param   {object} cookies Any cookies you might need
 * @param   {string} user the name of the user who authenciated
 * @param   {string} pass the password of the user who authenciated
 * @returns {object} The message you'd like to pass to the server, or `false` if there is no message
 */

License

Copyright ©2014 Scripto, LLC. Available under the MIT license