为什么node使用100%的CPU?

发布于 2024-11-18 06:58:12 字数 306 浏览 3 评论 0原文

我正在使用 Express Web 框架和 Node.js。

我正在用 ab 做一个简单的测试:

ab -n 1000 -c 100 http://127.0.0.1:3000/

我使用的是 Express 的默认中间件,只有一个 get()

app.get('/', function(req, res){
  res.send("hello");    
});

如何才能以 100% 加载 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山田美奈子 2024-11-25 06:58:13

仅仅因为某些东西是异步的,并不意味着它无法使用所有可用的处理资源。让我们看看您的示例服务器:

// 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");    
});

当您请求 ab 向示例应用程序发出 100 个并发请求时,显然 CPU 利用率将达到 100%,因为 Node 正在尝试尽快满足这些请求。仅仅因为它是异步的,并不意味着它不会尽力执行您告诉它的操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文