gzip - 有关性能的问题
首先,我使用 Django。 Django 提供了 gzip 中间件,它工作得很好。 Nginx 还提供了 gzip 模块。仅仅使用 Nginx 的 gzip 模块是否更有意义,因为它是纯粹用 C 实现的,或者我是否缺少其他性能考虑因素。
其次,Django 不会压缩 200 字节以下的任何内容。这是因为 gzipping 太昂贵而在压缩输出小于该值时没有任何价值吗?
第三,我正在构建的 API 几乎是纯动态的,几乎没有缓存。 gzipping 是否足够昂贵,以至于在这种情况下使用它不切实际(相对于我可以在网络服务器上缓存 gzip 输出的情况)?
Firstly, I'm using Django. Django provides gzip middleware which works just fine. Nginx also provides a gzip module. Would it make more sense to just use Nginx's gzip module because it is implemented purely in C, or are there other performance considerations I'm missing.
Secondly, Django doesn't gzip anything under 200 bytes. Is this because gzipping is too expensive to have any value when compressing output smaller than that?
Thirdly, the API I'm building will be almost purely dynamic with very little caching. Is gzipping expensive enough to make it unpractical to use in this situation (vs a situation where I could cache the gzipped output on the webserver)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)我认为一个 gzip 压缩就足够了,并且 nginx 更快,尽管我还没有对它进行基准测试。
GzipMiddleware
使用了一些内置函数,它们也可能得到了很好的优化。2) gzip 压缩的小文件无法利用压缩(事实上,处理后小文件可能会更大),因此只需跳过此步骤即可节省时间。
3)您可以设计一个包含示例数据的测试套件。然后决定该数据,什么最适合您的应用程序。
1) I imagine that one gzip compression is enough and nginx is faster, although I haven't benchmarked it yet.
GzipMiddleware
utilizes a few built-ins, which might be well optimized, too.2) Small gzip'd files just can't take advantage from compression (in fact small files might be bigger, when processed), so one can save time by just skipping this step.
3) You could design a test suite including sample data. Then decide on that data, what works best for your application.