简体   繁体   English

小型 http 请求是否更快?

[英]Are small http requests faster?

I'm implementing an autocomplete-style search in my webapp.我正在我的 web 应用程序中实现自动完成样式的搜索。 Every character that the user types will trigger a search request to the server.用户输入的每个字符都会触发对服务器的搜索请求。 The requests and responses must be fast.请求和响应必须很快。 Milliseconds matter.毫秒很重要。

As part of the app, I'm considering adding a custom request header.作为应用程序的一部分,我正在考虑添加自定义请求标头。 Unfortunately, this extra header will take another 150 bytes.不幸的是,这个额外的标头将占用另外 150 个字节。 The request itself will be only a short URL, plus a few bytes in the POST body, plus standard headers send automatically by the browser.请求本身只是一个简短的 URL,加上 POST 正文中的几个字节,加上浏览器自动发送的标准标头。

Will the custom header affect the speed much?自定义标题对速度影响大吗?

On one hand, it seems obvious that it would.一方面,这似乎很明显。 A bigger request will take longer for the browser to process and send.浏览器处理和发送更大的请求需要更长的时间。

On the other hand, the speed difference might be negligible.另一方面,速度差异可能可以忽略不计。 There might be a lot of other network overhead along the way.在此过程中可能会有很多其他网络开销。

(I'm not concerned about the time it takes the server to process the header. It's definitely going to be well less than a millisecond.) (我不关心服务器处理标头所需的时间。它肯定会少于一毫秒。)

Will the custom header affect the speed much?自定义标题对速度影响大吗?

The usual answer: what happened when you tested it?通常的答案是:测试时发生了什么?

No. It won't affect it much unless your code is really, really slow (and you've said that's not the case).不会。除非您的代码真的非常非常慢(而且您已经说过事实并非如此),否则它不会对其产生太大影响。 Even with HTTP/2 reusing a connection, the performance should be dominated by the network RTT.即使使用 HTTP/2 重用连接,性能也应该由网络 RTT 主导。 The time taken to transfer the data will be small.传输数据所花费的时间会很少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM