Why node uses 100% of the CPU?
i'm using Express web framework and Node.js.
I'm doing a simple test with ab:
ab -n 1000 -c 100 http://127.0.0.1:3000/
i'm using the default middleware of Express and only one get()
app.ge开发者_运维技巧t('/', function(req, res){
res.send("hello");
});
how can load the CPU at 100%, is not really async ?
THANK YOU
Just because something is asynchronous, doesn't mean that it is incapable of using all processing resources available. Let's look at your sample server:
// when you get a request for "/", perform the
// following function as quickly as you can.
app.get('/', function(req, res) {
// this is the function to perform. It is CPU
// bound when serving a client *on the same machine*.
res.send("hello");
});
When you request ab to make 100 concurrent requests to your sample app, you're obviously going to spike 100% CPU utilization, because node is trying to satisfy those requests as quickly as it can. Just because it's asynchronous, doesn't mean it isn't going to work as hard as it can to do what you tell it to.
精彩评论