23

I've learned that MySQL can compress communication between servers and clients.

Compression is used if both client and server support zlib compression, and the client requests compression.

(from 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?

ento
  • 5,801
  • 6
  • 51
  • 69
  • Network speed and processing speed are always racing each other. Does your setup have greater network speed or greater processing speed? If you have greater network speed, then save on processing by not compressing. If you have greater processing speed, then save on network by compressing. – Pacerier Oct 18 '14 at 07:36

4 Answers4

21

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.

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. Of course, you don't want it at 101%, so your target range is well below 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 cycles are cheap, especially unused ones (you do pay for electricity and cooling).

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.

Don't forget that the client must also expend CPU cycles to decompress the data. Not a major issue, but still a factor. In general, today's CPUs are faster than today's networks.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
17

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. That’s almost 1.5x improvement in total run time. MySQL query time improvement is even greater. On the other hand 1 Gbit link was fast enough; and total run time was 1.2x times worse with compression.

Unless your database and client are on the same machine, on 100 Mbits network and slower, enable the compression!

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).

ktulinho
  • 3,870
  • 9
  • 28
  • 35
jeremfg
  • 323
  • 2
  • 8
  • 1
    Great info! would be important to consider this may not be applicable to all situations. If your data is easily compressed (lots of duplicate data within each query) or your CPU performance is much higher, you may want to run your own tests. – Luke Rehmann Jan 15 '15 at 16:56
4

In my experience, most mysql servers are located on the same server as the webserver, so network bandwidth is not an issue.

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.

Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99
  • 2
    Totally applicable in most web application scenarios. But the idea that the database server is nearby (network-wise) is untrue for many client-server implementations. – Elemental Mar 24 '10 at 11:29
1

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). 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.

reko_t
  • 55,302
  • 10
  • 87
  • 77