GithubHelp home page GithubHelp logo

sirithink / wsbench Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pgriess/wsbench

0.0 2.0 0.0 60 KB

A benchmarking tool for Web Socket servers

License: BSD 3-Clause "New" or "Revised" License

wsbench's Introduction

wsbench is a scriptable benchmarking tool for Web Socket servers.

An installation of NodeJS is required, but there are no other external dependencies. See Benchmarking Web Socket servers with wsbench for more background on the motivation and intended usage of this tool.

Basic usage

At its simplest, wsbench can be invoked with a Web Socket URL pointing to the server. For example, this opens and closes 100 connections in serial to the server running on localhost, port 8080. No messages are sent down the connections.

% wsbench ws://localhost:8080

A parallel, rate-driven model is available using the -r option. For example, the following opens and closes 10 connections per second and runs indefinitely. This uses -c NNN to specify termination after NNN connections, with 0 indicating no limit.

% wsbench -r 10 ws://localhost:8080

We can also send messages over each connection using the -m NNN option to indicate how many messages to send. The -s NNN option can be used to set the size of each message in bytes. When operating in this mode, the websocket connection is guaranteed to remain open until all messages have been transmitted.

Session scripting

The wsbench tool supports execution of arbitrary JavaScript code to drive the interaction over open connections (e.g. to send and receive messages) using the -S FILE option. This allows testing of rich, application-specific behavior. As a trivial example, the following file will send a Hello message for the first 10 connections and world! for each connection after and then close the connection. Note that the session function is invoked once for each web socket opened, so we keep our counter in the module scope.

var cnt = 0;

module.exports = function(ws) {
    ws.onopen = function() {
        ws.send((++cnt <= 10) ? 'Hello' : 'world!');
        ws.close();
    };
};

A more involved example is available in the examples/echo/ directory.

Finally, the session logic can use any NodeJS module installed in the system. Significantly, this provides access to the built-in HTTP stack; constructing heterogeneous workloads consisting of a mix of Web Socket and HTTP requests is trivial.

Full usage

The complete usage is

usage: wsbench [options] <url>

Kick off a benchmarking run against the given ws:// URL.

We can execute our workload in one of two ways: serially, wherein each
connection is closed before the next is initiated; or in parallel, wherein
a desired rate is specified and connections initiated to meet this rate,
independent of the state of other connections. Serial execution is the
default, and parallel execution can be specified using the -r <rate>
option. Parallel execution is bounded by the total number of connections
to be made, specified by the -c option.

Available options:
  -c, --num-conns NUMBER   number of connections to open (default: 100)
  -h, --help               display this help
  -m, --num-msgs NUMBER    number of messages per connection (dfeault: 0)
  -p, --protocol PROTO     set the Web Socket protocol to use (default: empty)
  -r, --rate NUMBER        number of connections per second (default: 0)
  -s, --msg-size NUMBER    size of messages to send, in bytes (default: 32)
  -S, --session FILE       file to use for session logic (default: None)

wsbench's People

Contributors

pgriess avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.