简体   繁体   English

服务器必须为每个响应块分配多少大小?

[英]What size does the server have to give to each response chunk?

If I wanted to configure my personal server so that the response for a certain request is set according to the chunk rules : what size should each of the server response chunk have?如果我想配置我的个人服务器,以便根据块规则设置某个请求的响应:每个服务器响应块的大小应该是多少?

For example, let's say that the chunked response is a long HTML page or a file.例如,假设分块响应是一个长的 HTML 页面或文件。

How would you behave in these two cases?在这两种情况下你会如何表现?

From the RFC :来自RFC

This allows dynamically produced content to be transferred...这允许传输动态生成的内容...

In other words: Transfer-Encoding: chunked is needed when the length of content is unknown .换句话说: Transfer-Encoding: chunked内容长度未知时需要分块。

The length of your content may be as big as 10Tb... but also it can be as small as 10 bytes.您的内容的长度可能大至 10Tb……但也可能小至 10 个字节。 It doesn't matter.没关系。 The chucks' sizes depend solely on the algorithms you are using to generate them and to read then.夹头的大小仅取决于您用来生成它们并随后读取的算法。

Let's say you generate a stream of messages of different lengths, one character per second.假设您生成不同长度的消息 stream,每秒一个字符。 In this case you can decide to send one byte chucks to the client.在这种情况下,您可以决定向客户端发送一个字节的卡盘。 This way the client will be able to use the data as soon as it arrives.这样,客户端将能够在数据到达后立即使用它。 But if your client have no use for partial messages, then you probably should save the bandwidth and send a chunk at the moment you've finished generating the next message.但是,如果您的客户端不需要部分消息,那么您可能应该节省带宽并在您完成生成下一条消息的那一刻发送一个块。 And again it doesn't matter how big or small the message is.同样,消息的大小无关紧要。 It can be 2 characters or it can be 1000.它可以是 2 个字符,也可以是 1000 个字符。


On second thought, there are some use cases for Transfer-Encoding: chunked with the data of known size.再想一想, Transfer-Encoding: chunked But then your question becomes to broad to answer.但是,您的问题变得广泛而无法回答。 It depends on your client code, server code, network conditions, data properties, desired user experience, etc.这取决于您的客户端代码、服务器代码、网络条件、数据属性、所需的用户体验等。

And if by any chance you are asking about optimal size from the network perspective, then just send the whole file - that the best bet.如果您有任何机会从网络角度询问最佳大小,那么只需发送整个文件 - 这是最好的选择。 And support Content-Range on your server instead of Transfer-Encoding: chunked .并在您的服务器上支持Content-Range而不是Transfer-Encoding: chunked

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

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