首页 \ 问答 \ 为什么node.js一次只处理六个请求?(Why is node.js only processing six requests at a time?)

为什么node.js一次只处理六个请求?(Why is node.js only processing six requests at a time?)

我们有一个node.js服务器,它实现一个REST API作为中央服务器的代理,它具有稍微不同的,不幸的是不对称的REST API。

我们的客户端在各种浏览器中运行,要求节点服务器从中央服务器获取任务。 节点服务器从中央获取所有任务ID的列表,并将其返回给客户端。 客户端然后通过代理对每个id进行两次REST API调用。

据我所知,这些东西都是异步完成的。 在控制台日志中,当我启动客户端时,它看起来像这样:

Requested GET URL under /api/v1/tasks/*: /api/v1/tasks/

这需要几秒钟的时间才能从中央服务器获取列表。 一旦得到响应,服务器barfs这样很快:

Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/438
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/438
Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/439
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/439
Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/441
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/441

然后,每次这些请求都从中央服务器得到一个结果,那么另外两行就会非常快速地被删除。

所以似乎我们的node.js服务器只愿意一次有六个请求。


We have a node.js server which implements a REST API as a proxy to a central server which has a slightly different, and unfortunately asymmetric REST API.

Our client, which runs in various browsers, asks the node server to get the tasks from the central server. The node server gets a list of all the task ids from the central one and returns them to the client. The client then makes two REST API calls per id through the proxy.

As far as I can tell, this stuff is all done asynchronously. In the console log, it looks like this when I start the client:

Requested GET URL under /api/v1/tasks/*: /api/v1/tasks/

This takes a couple seconds to get the list from the central server. As soon as it gets the response, the server barfs this out very quickly:

Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/438
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/438
Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/439
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/439
Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/441
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/441

Then, each time a pair of these requests gets a result from the central server, another two lines is barfed out very quickly.

So it seems our node.js server is only willing to have six requests out at a time.


原文:https://stackoverflow.com/questions/12060869
更新时间:2022-03-21 07:03

最满意答案

如果您将xargs安装在多核处理器上,您可以从以下情况中受益,以防有人感兴趣。

环境:

Processor: Dual Quad-core 2.4GHz
Memory: 32 GB
Number of files: 584450
Total Size: ~ 35 GB

测试:

1.找到必要的文件,将它们管理到xargs并告诉它执行8个实例。

time find ./ -name "*.ext" -print0 | xargs -0 -n1 -P8 grep -H "string" >> Strings_find8

real    3m24.358s
user    1m27.654s
sys     9m40.316s

2.找到必要的文件,将它们管理到xargs,并告诉它执行4个实例。

time find ./ -name "*.ext" -print0 | xargs -0 -n1 -P4 grep -H "string" >> Strings

real    16m3.051s
user    0m56.012s
sys     8m42.540s

3. @Stephen建议:找到必要的文件,并使用+而不是xargs

time find ./ -name "*.ext" -exec grep -H "string" {} \+ >> Strings

real    53m45.438s
user    0m5.829s
sys     0m40.778s

定期递归grep。

grep -R "string" >> Strings

real    235m12.823s
user    38m57.763s
sys     38m8.301s

为了我的目的,第一个命令工作得很好。


If you have xargs installed on a multi-core processor, you can benefit from the following just in case someone is interested.

Environment:

Processor: Dual Quad-core 2.4GHz
Memory: 32 GB
Number of files: 584450
Total Size: ~ 35 GB

Tests:

1. Find the necessary files, pipe them to xargs and tell it to execute 8 instances.

time find ./ -name "*.ext" -print0 | xargs -0 -n1 -P8 grep -H "string" >> Strings_find8

real    3m24.358s
user    1m27.654s
sys     9m40.316s

2. Find the necessary files, pipe them to xargs and tell it to execute 4 instances.

time find ./ -name "*.ext" -print0 | xargs -0 -n1 -P4 grep -H "string" >> Strings

real    16m3.051s
user    0m56.012s
sys     8m42.540s

3. Suggested by @Stephen: Find the necessary files and use + instead of xargs

time find ./ -name "*.ext" -exec grep -H "string" {} \+ >> Strings

real    53m45.438s
user    0m5.829s
sys     0m40.778s

4. Regular recursive grep.

grep -R "string" >> Strings

real    235m12.823s
user    38m57.763s
sys     38m8.301s

For my purposes, the first command worked just fine.

相关问答

更多
  • 如果您将xargs安装在多核处理器上,您可以从以下情况中受益,以防有人感兴趣。 环境: Processor: Dual Quad-core 2.4GHz Memory: 32 GB Number of files: 584450 Total Size: ~ 35 GB 测试: 1.找到必要的文件,将它们管理到xargs并告诉它执行8个实例。 time find ./ -name "*.ext" -print0 | xargs -0 -n1 -P8 grep -H "string" >> Strings_f ...
  • 你想要-w选项来指定它是单词的结尾。 find . | xargs grep -sw 's:text' You want the -w option to specify that it's the end of a word. find . | xargs grep -sw 's:text'
  • 转义它们会激活它们的元字符属性并将它们转换为GNU grep中的单词边界: $ grep 'foo' file foo foobar $ grep '\' file foo 上面的第二个grep没有查找字符串 ,它正在寻找字符串foo不会在字构成字符之前或之后立即成功。 一般来说,如果不确切知道这意味着什么,就逃脱角色是不安全的。 这是另一个例子: $ printf 'aa\na{2}b\n' aa a{2}b $ printf 'aa\na{2}b\n' ...
  • grep -B3 'Max_value: \(127\|32767\)' proc_*.* grep -B3 'Max_value: \(127\|32767\)' proc_*.*
  • 如果这些是您需要搜索的唯一字符串,请使用-F (grep表示固定字符串): grep -F "directory1 directory2 directory3" file.txt 如果你想使用更高级的正则表达式grep,请使用-E (使用扩展正则表达式): grep -E 'directory[1-3]' file.txt 请注意,某些grep (如GNU grep)不需要-E来运行此示例。 最后,请注意您需要引用正则表达式。 如果不这样做,你的shell可能会首先根据路径名扩展扩展正则表达式(例如,如 ...
  • 这似乎很好。 也许你可以在dup2之后关闭一些fds: // in child process dup2(fd[0], STDIN_FILENO); close(fd[0]); close(fd[1]); 编辑: 似乎有拼写错误: "/bin/grep/" 它应该是: "/bin/grep" It seems to be quite OK. Maybe you could close some fds after dup2: // in child process dup2(fd[0], STDIN_FI ...
  • 在Gnu Awk中,您可以使用\<和\>来匹配单词的开头和结尾,所以 gawk '/\/{++i} END{print i}' 会做同样的事情 grep -wc 'GOOD' file 如果你想计算GOOD这个词的出现总数(不仅是行数,还有给定行/记录中的出现次数),你可以在Gnu Awk版本4中使用FPAT , gawk 'BEGIN { FPAT="\\"; RS="^$" } { print NF }' file 如果要计算给定记录中短语GOOD DI的完全匹配数, ...
  • grep有-c选项只打印事件,你应该利用它而不是产生另一个进程和一个匿名管道: grep -c '' file.txt 要从两次搜索中减去计数,您可以使用命令替换直接减去它们: echo $(( $(grep -c '' file.txt) - $(grep -c '' file.txt) )) 如果您喜欢,也可以使用两个变量: count_1=$(grep -c '' file.txt) count_2=$(grep ...
  • ? 不是grep支持的基本正则表达式的一部分。 GNU grep支持它们作为扩展,但你必须逃避它们: $ grep '^\[\?MyTag\]\?' file.txt [MyTag] hello MyTag world 或者,正如指出的那样,使用grep -E来启用扩展正则表达式。 对于GNU grep, grep和grep -E之间的唯一区别,即使用基本和扩展正则表达式,是你必须逃避的,不是什么。 基本正则表达式 必须转义捕获组和量化: \( \)和\{ \} 零或一( ? ),一个或多个( + )和交 ...
  • 在${CONFIG_FILE}之后,我没有看到x任何目的。 也许有一个早期版本的脚本,他们没有引用变量,所以他们写道 echo -e ${CONFIG_FILE}x 在这种情况下,即使变量为空, x确保有一个echo参数。 但引号解决了这个问题,因此不再需要x 。 grep -q "^-"测试输入的第一个字母是否为- 。 正则表达式^匹配行的开头,并且-匹配自身。 -q选项告诉grep不打印匹配行,它只是根据它是否匹配来设置其退出状态。 I don't see any purpose to the x a ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。