简体   繁体   English

GZIP压缩HTTP响应,然后再发送给客户端

[英]GZIP Compressing http response before sending to the client

I have gzipped the response using filter. 我已经用过滤器压缩了响应。 The data received has been compressed from 50 MB to 5 MB however, it didn't result in much saving of time. 接收到的数据已从50 MB压缩到5 MB,但是并没有节省太多时间。 The time taken has reduced from 12 seconds to 10 seconds. 所需时间从12秒减少到10秒。 Is there anything else which can be done to reduce the time period? 还有什么可以减少时间的事情吗?

Initially, the data transfer over the network took 9 seconds, now it takes 6 seconds after compression and 1 sec to decompress approximately 最初,通过网络传输数据需要9秒钟,现在压缩后需要6秒钟,解压缩大约需要1秒钟。

What else can be done? 还有什么可以做的?

For the filter the possible measures are little: 对于过滤器,可能的措施很少:

  • There exist different compression levels, the more compression the slower. 存在不同的压缩级别,压缩越多,速度越慢。 The default or GZIPOutputStream should be fast enough. 默认值或GZIPOutputStream应该足够快。
  • GZIPOutputStream has constructors with size to set. GZIPOutputStream具有要设置size构造函数。
  • Then there is buffered streaming, and not doing byte-wise int read() . 然后是缓冲流,而不是按字节进行int read()
  • Code review for plausibility: the original Content-Length header must be removed. 代码审查的合理性:必须删除原始的Content-Length标头。

For the static content: 对于静态内容:

  • .bmp are a waste of space .bmp浪费空间
  • .pdf can be optimized when images repeat, wrt fonts. 当图像重复使用wrt字体时,可以优化.pdf。
  • .docx is a zip format, so inner image files might be optimized too .docx是zip格式,因此内部图像文件也可能会进行优化

For dynamic content generation: 对于动态内容生成:

  • Fixed documents can be stored (xxxxxx.yyy.gz) with timestamp and then the generation time forfalls. 可以将带有时间戳的固定文档(xxxxxx.yyy.gz)存储起来,然后再生成时间。 Only of interest after measuring the real bottle neck; 仅在测量了实际瓶颈后才感兴趣; likely the network. 可能是网络。
  • The code for delivery should be fast. 交货代码应该很快。 In general chain streams, try not to write to a ByteArrayOutputStream, but immediately to a BufferedOutputStream(original output stream). 在一般的链流中,请尽量不要写入ByteArrayOutputStream,而应立即写入BufferedOutputStream(原始输出流)。 Check that the buffering is not done twice. 检查两次缓冲是否没有完成。 Some wrapping streams check that the wrapped stream is an instanceof a buffered. 一些包装流检查包装的流是否是缓冲的实例。

Production environment: 生产环境:

  • Maybe you even need throttling (slowing down delivery) in order to serve multiple simultaneous requests. 也许您甚至需要节流(放慢传送速度)才能处理多个同时请求。
  • You may need to do the delivery on another server. 您可能需要在另一台服务器上进行传递。
  • Buy speed from the provider. 从提供商那里购买速度。 Inquire from the provider, whether the througput was too high, and the provider slowed things down. 向提供者询问吞吐量是否太高,并且提供者放慢了速度。

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

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