开发者

Why node uses 100% of the CPU?

开发者 https://www.devze.com 2023-03-16 23:42 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消