简体   繁体   中英

Sending large number of requests to server on node.js

I have the following:

 var tempServer=require("./myHttp");

 tempServer.startServer(8008,{'/fun1':fun1 , '/fun2': fun2 , '/fun3':fun3 , '/fun4':fun4},"www");

which creates a server on localhost:8008.

and if i type in the url line in my browser the following:

 localhost:http://localhost:8008/fun2

it will call fun2 function and will perform what is needed.

having said that,

how can i write a script function (fun2) which simulates a call for a large number

of requests (say 10000) to tempServer?

any help will be much appreciated!

You could try this on your laptop, but you would find that your computer will not really be able to create 10,000 requests to a temp server (or anyplace) at the same time. Most modern machines top out around 1000 or so simultaneous connections.

You can create something in code that will certainly do this one connection after another, but this is not the same as a true load test where you ramp up and ramp down the number of requests per second. You will quickly find that this is IO and connection-bound and not a true test for your application.

Your best bet, if you are trying to benchmark/stress your server, is to put your server on a box or service that is internet accessible like nodejitsu or nodester (both free services) and then use another service (free or otherwise) to hit your server's URL. You don't say if this is what you're doing, but this is the usual way to do load and stress testing.

Two companies that I have used in the past are Load Impact and Blitz.io to get the number of simultaneous user requests to your server. for 10,000 users you will need to pay a bit but it's not too large a fee.

You may also want to look into the libraries from New Relic to help you monitor the server/service itself and how it behaves under stress. They have some great capabilities in helping find bottlenecks in applications.

This may be a bit more than what you were looking for, but I hope that it's helpful. If I am off the mark, let me know and I'll be happy to amend this to be closer to what it is you are looking for.

Are you interested in scripting 10,000 calls to fun2 via http2 or issuing 10,000 requests from fun2 within node?

If it is within Node and as you probably know all the code is written as sequential but the events are executed asynchronously.

Check the EventEmitter for dispatching function calls on evens:

http://nodejs.org/docs/v0.4.7/api/all.html#events.EventEmitter

and see this example as an inspiration for issuing calls in parallel:

http://ricochen.wordpress.com/2011/10/15/node-js-example-2-parallel-processing/

Hope this helps.

Edmon

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM