问题
I have a small app that sends Server Sent Events. I would like to load test my app so I can benchmark the latency from the time a message is pushed to the time the message is received so I can know when/where the performance breaks down. What tools are available to be able to do this?
回答1:
Since Server-Sent Events
it is just HTTP you can use siege
utility. Here is the example:
siege -b -t 1m -c45 http://127.0.0.1:9292/streaming
Where:
-b
benchmark mode i.e. don't wait between connections-t 1m
benchmark for 1 minute-c45
number of concurrent connectionshttp://127.0.0.1:9292
my dev server host and custom port/streaming
HTTP-endpoint which respond withContent-Type: text/event-stream
Output:
Lifting the server siege... done.
Transactions: 79 hits
Availability: 100.00 %
Elapsed time: 59.87 secs
Data transferred: 0.01 MB
Response time: 23.43 secs
Transaction rate: 1.32 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 30.91
Successful transactions: 79
Failed transactions: 0
Longest transaction: 30.12
Shortest transaction: 10.04
回答2:
I took a simple path of creating a shell script that initiates N background jobs of cURL which connected to the SSE endpoint of my service. To get the exact cURL syntax, open your Chrome web dev tools -> Network tab -> right click on the entry of the request to the SSE endpoint and choose from the context menu "Copy as cURL"
Then you paste that command in a shell script that roughly looks like:
#!/bin/bash
i=0;
while [ $i -lt 50 ] ;do
[PASTE YOUR cURL COMMAND HERE] -s -o /dev/null &
i=`expr $i + 1`;
done
This will add 50 background cURL jobs each time it's run. Notice that I added to Chrome's cURL command the params -s -o /dev/null
. This is to run cURL in silent mode and to suppress any output.
In my case the service was implemented in NodeJs, so I used process.hrtime() for high precision timing to measure the delay of looping through the N connected clients to broadcast the data.
The results were ok: it served 1000+ active connections in ~0.02sec
Keep in mind that if you run server + cURL clients from the same machine, you'll probably hit OS limits of open files
. To see open file
limits on your linux box (common case is 1024) run:
$ ulimit -n
To avoid reaching the 1000+ active cURLs I got, you can:
- start them from multiple machines
- or increase this limit (see sysctl)
The problem I faced was that eventually node crushed with an ELIFECYCLE error and the log was not very helpful in diagnosing the problem. Any suggestions are welcome.
来源:https://stackoverflow.com/questions/18089085/how-to-load-test-server-sent-events