node.js - How to test nodejs concurrent Request -
i want write simple code test nodejs concurrency when receives many requests.
and use loadtest module simulate send many requests server command :
loadtest -c 10 --rps 200 http://localhost:3000/
my simple code write in server.js :
var http = require('http'); var server = http.createserver(); var cun=0; var step=0; function handlerequest(req,res) { console.log(step++); while(100000000>cun){ cun++; } cun=0; } server.on('request', handlerequest); server.listen(3000);
but requests wait until while loop down
and know solve problem should use callback function , don't know how write it.
var http = require('http'); var url = require("url"); var server = http.createserver(); function handlerequest(req, res) { res.writehead(200, { 'content-type': 'text/plain'}); var params = url.parse(request.url, true).query; var input = params.number; /* 1- use input param in algorithm , process 2- insert data in db 3- select on db , return client */ res.end(); } server.on('request', handlerequest); server.listen(3000);
problem : requests wait in queue until last request process(process-insert-select) down
Comments
Post a Comment