简体   繁体   English

我什么时候应该使用 MySQL 压缩协议?

[英]When should I use MySQL compressed protocol?

I've learned that MySQL can compress communication between servers and clients.我了解到 MySQL 可以压缩服务器和客户端之间的通信。

Compression is used if both client and server support zlib compression, and the client requests compression.如果客户端和服务器都支持 zlib 压缩,并且客户端请求压缩,则使用压缩。

(from MySQL Forge Wiki ) (来自MySQL Forge Wiki

The most obvious pros and cons are最明显的优点和缺点是

  • pros: Reduced payload size优点:减少有效载荷大小
  • cons: Increased computation time缺点:计算时间增加

So, is compressed protocol something I should enable whenever I can afford servers with adequate specs?那么,只要我负担得起具有足够规格的服务器,我就应该启用压缩协议吗? Are there other factors I should consider?还有其他我应该考虑的因素吗?

Performance benefits are going to be largely dependent on the size of the result sets that you are sending, in addition to the network bandwidth and latency between the database server and its clients.除了数据库服务器与其客户端之间的网络带宽和延迟之外,性能优势将在很大程度上取决于您发送的结果集的大小。

The larger the result sets, the larger the latency, or the less bandwidth, the more likely you will see the benefit of compression.结果集越大,延迟越大,或带宽越少,您就越有可能看到压缩的好处。

Your maximum level of service is limited to the smallest bottleneck.您的最高服务水平仅限于最小的瓶颈。 So, you need to analyze where you're currently at regarding network and CPU resources.因此,您需要分析您目前在网络和 CPU 资源方面所处的位置。

The most optimized database server utilizes 100% of its CPU 100% of the time, otherwise you're wasting computing resources by having a processor that's sitting there not doing anything.最优化的数据库服务器在 100% 的时间内使用其 CPU 的 100%,否则您会因为处理器坐在那里什么都不做而浪费计算资源。 Of course, you don't want it at 101%, so your target range is well below 100%.当然,您不希望达到 101%,因此您的目标范围远低于 100%。 Yet, my point is that if you have a lot of headroom before you reach a CPU bottleneck, and the result sets are a significant size, and the network is a factor, then turn compression on.然而,我的观点是,如果在达到 CPU 瓶颈之前您有很多空间,并且结果集很大,并且网络是一个因素,那么请打开压缩。 CPU cycles are cheap, especially unused ones (you do pay for electricity and cooling). CPU 周期很便宜,尤其是未使用的周期(您需要支付电费和冷却费用)。

If you pay for bandwidth, trading CPU usage for bandwidth is easily justified, and even if you're not anywhere near reaching the bandwidth bottleneck, that faster speed, and higher level of service, is worth something.如果您为带宽付费,那么用 CPU 使用量换取带宽是很容易的,即使您还没有接近带宽瓶颈,更快的速度和更高的服务水平也是值得的。

Don't forget that the client must also expend CPU cycles to decompress the data.不要忘记客户端还必须花费 CPU 周期来解压缩数据。 Not a major issue, but still a factor.不是主要问题,但仍然是一个因素。 In general, today's CPUs are faster than today's networks.一般来说,今天的 CPU 比今天的网络要快。

I know it's late, but I though I might share this:我知道已经晚了,但我想我可能会分享这个:

It turns out that 100 Mbit link (with 1.4 ms round-trip time) is not fast enough... With compression, total indexing time reduced to 87 sec from 127 sec.事实证明,100 Mbit 链路(往返时间为 1.4 毫秒)还不够快……通过压缩,总索引时间从 127 秒减少到 87 秒。 That's almost 1.5x improvement in total run time.总运行时间几乎提高了 1.5 倍。 MySQL query time improvement is even greater. MySQL 查询时间的改进甚至更大。 On the other hand 1 Gbit link was fast enough;另一方面,1 Gbit 链路足够快; and total run time was 1.2x times worse with compression.总运行时间是压缩的 1.2 倍。

Unless your database and client are on the same machine, on 100 Mbits network and slower, enable the compression!除非您的数据库和客户端在同一台机器上,在 100 Mbits 网络和更慢的网络上,启用压缩!

However, your final decision might also to depend on the balance between the cost of CPU cycles (compress/decompress) and Bandwith usage (more data on the wire).但是,您的最终决定也可能取决于 CPU 周期成本(压缩/解压缩)和带宽使用(更多数据在线上)之间的平衡。

In my experience, most mysql servers are located on the same server as the webserver, so network bandwidth is not an issue.根据我的经验,大多数 mysql 服务器与 web 服务器位于同一台服务器上,因此网络带宽不是问题。

I'd say that unless your db and app/web servers are geographically apart (ie not on the same server or network), there's going to be very little benefit in enabling compression.我会说,除非您的数据库和应用程序/网络服务器在地理上分开(即不在同一服务器或网络上),否则启用压缩几乎没有什么好处。

From my experience it's especially useful if you're connecting to an external MySQL server that resides in completely another network (or even country).根据我的经验,如果您要连接到完全位于另一个网络(甚至国家/地区)的外部 MySQL 服务器,则它特别有用。 The benefit you get from enabling compression in such cases depends on the size of the data you're transferring, and the distance between the client and the server.在这种情况下启用压缩的好处取决于您传输的数据的大小以及客户端和服务器之间的距离。 As always, you should test your application with and without compression, and then make a decision which is most beneficial for your situation.与往常一样,您应该在压缩和不压缩的情况下测试您的应用程序,然后做出对您的情况最有利的决定。 There's no absolute answer for this question.这个问题没有绝对的答案。

I don't see much point enabling compression if you query a MySQL server on same machine, or even on same network.如果您在同一台机器上甚至在同一网络上查询 MySQL 服务器,我认为启用压缩没有多大意义。

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

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