Thor is WebSocket benchmark utility
Thor is WebSocket benchmarking/load generator. There are a lot of benchmarking tools for HTTP servers. You've got ab, siege, wrk and more. But all these tools only work plain ol HTTP and have no support for WebSockets and even if they did they wouldn't be suitable as they would be testing short running HTTP requests instead of long running HTTP requests with a lot of messaging traffic. Thor fixes all of this.
Thor requires Node.js to be installed on your system. If you don't have Node.js installed you can download it from http://nodejs.org or build it from the github source repository: http://github.com/joyent/node.
Once you have Node.js installed, you can use bundled package manager
install this module:
npm install -g thor
-g command flag tells
npm to install the module globally on your system.
thor [options] <urls>
Thor can hit multiple URL's at once, this is useful if you are testing your
reverse proxies, load balancers or just simply multiple applications. The url
that you supply to
thor should be written in a WebSocket compatible format
thor --amount 5000 ws://localhost:8080 wss://localhost:8081
The snippet above will open up
5000 connections against the regular
ws://localhost:8080 and also
5000 connections against the secured
wss://localhost:8081 server. So a total of
10000 connections will be made.
One thing to keep in mind is that you probably need to bump the amount of file
descriptors on your local machine if you start testing WebSockets. Set the
ulimit -n on machine as high as possible. If you do not know how to do this,
Usage: thor [options] ws://localhostOptions:-h, --help output usage information-A, --amount <connections> the amount of persistent connections to generate-C, --concurrent <connections> how many concurrent-connections per second-M, --messages <messages> messages to be send per connection-P, --protocol <protocol> WebSocket protocol version-B, --buffer <size> size of the messages that are send-W, --workers <cpus> workers to be spawned-G, --generator <file> custom message generators-M, --masked send the messaged with a mask-b, --binary send binary messages instead of utf-8-V, --version output the version number
Some small notes about the options:
--protocolis the protocol version number. If you want to use the HyBi drafts 07-12 use
8as argument or if you want to use the HyBi drafts 13-17 drafts which are the default version use
--buffershould be size of the message in bytes.
--workersas Node.js is single threaded this sets the amount of sub processes to handle all the heavy lifting.
Some WebSocket servers have their own custom messaging protocol. In order to
work with those servers we introduced a concept called
generators a generator
binary messages. It uses
a really simple generator by default.
Checkout https://github.com/observing/thor/blob/master/generator.js for an example of a generator.
thor --amount 1000 --generator <file.js> ws://localhost:8080
thor --amount 1000 --messages 100 ws://localhost:8080
This will hit the WebSocket server that runs on localhost:8080 with 1000
connections and sends 100 messages over each established connection. Once
is done with smashing your connections it will generate a detailed report:
Thor: version: 1.0.0God of Thunder, son of Odin and smasher of WebSockets!Thou shall:- Spawn 4 workers.- Create all the concurrent/parallel connections.- Smash 1000 connections with the mighty Mjölnir.The answers you seek shall be yours, once I claim what is mine.Connecting to ws://localhost:8080Opened 100 connectionsOpened 200 connectionsOpened 300 connectionsOpened 400 connectionsOpened 500 connectionsOpened 600 connectionsOpened 700 connectionsOpened 800 connectionsOpened 900 connectionsOpened 1000 connectionsOnline 15000 millisecondsTime taken 31775 millisecondsConnected 1000Disconnected 0Failed 0Total transferred 120.46MBTotal received 120.43MBDurations (ms):min mean stddev median maxHandshaking 217 5036 4094 3902 14451Latency 0 215 104 205 701Percentile (ms):50% 66% 75% 80% 90% 95% 98% 98% 100%Handshaking 3902 6425 8273 9141 11409 12904 13382 13945 14451Latency 205 246 266 288 371 413 437 443 701