简体   繁体   中英

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.get('/', 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.

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