什么是好的 Java 压缩库?

发布于 2024-07-05 20:23:17 字数 72 浏览 1 评论 0原文

我需要压缩应用程序的部分网络流量以提高性能。 我认为这意味着我需要远离一些较新的算法,例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-07-12 20:23:17

您可以使用 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 可能需要您手动进行压缩。 要在客户端启用此功能,您需要执行类似的操作

.addRequestHeader("Accept-Encoding","gzip,deflate");

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

.addRequestHeader("Accept-Encoding","gzip,deflate");
云仙小弟 2024-07-12 20:23:17

您的压缩算法取决于您尝试优化的内容以及可用的带宽。

如果您使用的是千兆位 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.

残月升风 2024-07-12 20:23:17

如果网络流量通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文