什么是好的 Java 压缩库?
我需要压缩应用程序的部分网络流量以提高性能。 我认为这意味着我需要远离一些较新的算法,例如 bzip2,我认为我听说它速度较慢。
I need to compress portions of our application's network traffic for performance. I presume this means I need to stay away from some of the newer algorithms like bzip2, which I think I have heard is slower.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Deflater/< a href="http://docs.oracle.com/javase/7/docs/api/java/util/zip/Inflater.html" rel="nofollow noreferrer">Inflater 内置于 JDK 中。 还有 GZIPInputStream 和 GZIPOutputStream,但这实际上取决于您的具体用途。
编辑:
阅读进一步的评论,看起来网络流量是 HTTP。 根据服务器的不同,它可能支持压缩(尤其是 deflate/gzip)。 那么问题就变成了客户端。 如果客户端是浏览器,它可能已经支持它。 如果您的客户端是 Web 服务客户端或 http 客户端,请检查该包的文档看看是否支持。
看起来 jakarta-commons httpclient 可能需要您手动进行压缩。 要在客户端启用此功能,您需要执行类似的操作
You can use Deflater/Inflater which is built into the JDK. There are also GZIPInputStream and GZIPOutputStream, but it really depends on your exact use.
Edit:
Reading further comments it looks like the network taffic is HTTP. Depending on the server, it probably has support for compression (especially with deflate/gzip). The problem then becomes on the client. If the client is a browser it probably already supports it. If your client is a webservices client or an http client check the documentation for that package to see if it is supported.
It looks like jakarta-commons httpclient may require you to manually do the compression. To enable this on the client side you will need to do something like
您的压缩算法取决于您尝试优化的内容以及可用的带宽。
如果您使用的是千兆位 LAN,几乎任何压缩算法都会稍微减慢您的程序速度。 如果您通过 WAN 或互联网进行连接,则可以进行更多压缩。 如果您连接到拨号,则应该尽可能压缩。
如果这是一个 WAN,您可能会发现像 Riverbed 这样的硬件解决方案更有效,因为它们适用于一系列流量,并且不需要对软件进行任何更改。
我有一个测试用例,显示 Deflate、Filtered、BZip2 和 lzma 之间的相对压缩差异。 只需插入数据样本,然后测试两台机器之间的时序即可。
Your compression algorithm depends on what your trying to optimize, and how much bandwidth you have available.
If you're on a gigibit LAN, almost any compression algorithm is going to slow your program down just a bit. If your connecting over a WAN or internet, you can afford to do a bit more compression. If you connected to a dialup, you should compress as much as it absolutely possible.
If this is a WAN, you may find hardware solutions like Riverbed's are more effective, as they work across a range of traffic, and don't require any changes to software.
I have a test case which shows the relative compression difference between Deflate, Filtered, BZip2, and lzma. Simply plug in a sample of your data, and test the timing between two machines.
如果网络流量通过 HTTP,大多数各种 Web 服务器/servlet 容器都支持协商压缩,例如 Apache 的 mod_deflate。
If the network traffic is going over HTTP, most of the various web servers/servlet containers support for negotiated zipping, e.g., mod_deflate for Apache.