如何最大化 HTTP 网络吞吐量?
我在 CouchDB 上运行基准测试时发现,即使进行大量插入,并行运行其中一些插入的速度也几乎是原来的两倍。我还知道网络浏览器使用许多并行连接来加速页面加载。
多个连接比一个连接快的原因是什么?它们通过同一条线路,甚至是本地主机。
如何确定理想的并行请求数?是否有经验法则,例如“线程池大小 = # 核心数 + 1”?
I was running a benchmark on CouchDB when I noticed that even with large bulk inserts, running a few of them in parallel is almost twice as fast. I also know that web browsers use a number of parallel connections to speed up page loading.
What is the reason multiple connections are faster than one? They go over the same wire, or even to localhost.
How do I determine the ideal number of parallel requests? Is there a rule of thumb, like "threadpool size = # cores + 1"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
选通因素不是线路本身,毕竟它运行得相当快(忽略路由器延迟),而是每一端的软件开销。每次物理传输都必须进行设置、发送和存储数据,然后完全处理,然后才能进行其他操作。因此,每个连接实际上都是同步的,无论它在套接字级别如何声称:一个异步操作的套接字仍然以同步方式来回移动数据,因为软件要求同步。
第二个连接可以利用延迟(线路上的死区时间),该延迟是由软件为第一个连接执行操作而产生的。因此,尽管每个连接都是同步的,但多个连接可以让事情发生得更快。事情似乎(但当然只是似乎)是并行发生的。
您可能需要查看 RFC 2616 ,HTTP 规范。它会告诉您发生 HTTP 连接的交换情况。
我无法谈论最佳并行请求数量,这是浏览器和服务器之间的问题。
The gating factor is not the wire itself which, after all, runs pretty quick (ignoring router delays) but the software overhead at each end. Each physical transfer has to be set up, the data sent and stored, and then completely handled before anything can go the other way. So each connection is effectively synchronous, no matter what it claims to be at the socket level: one socket operating asynchronously is still moving data back and forth in a synchronous way because the software demands synchronicity.
A second connection can take advantage of the latency -- the dead time on the wire -- that arises from the software doing its thing for first connection. So, even though each connection is synchronous, multiple connections let things happen much faster. Things seem (but of course only seem) to happen in parallel.
You might want to take a look at RFC 2616, the HTTP spec. It will tell you about the interchanges that happen to get an HTTP connection going.
I can't say anything about optimal number of parallel requests, which is a matter between the browser and the server.
每个连接消耗一个自己的线程。每个线程都有一个消耗CPU、网络和其他资源的量程。主要是CPU。
当您开始并行调用时,线程将争夺 CPU 时间并“同时”运行。
这是对事物的高层次概述。我建议您阅读异步调用和线程编程以更好地理解它。
[]的,
以及过去
Each connection consume one own thread. Each thread, have a quantum for consume CPU, network and other resources. Mainly, CPU.
When you start a parallel call, thread will dispute CPU time and run things "at the same time".
It's a high level overview of the things. I suggest you to read about asynchronous calls and thread programming to understand it better.
[]'s,
And Past