zstd Compression Support in ProxySQL 3.0.7
Network compression is critical for database proxy deployments where clients and servers are separated by high-latency WAN links. ProxySQL has supported zlib-based MySQL compression since its early versions. Starting with 3.0.7, we are adding native support for zstd (Zstandard) compression, developed by Meta and widely adopted across the database and storage ecosystem.
Why zstd?
The MySQL protocol supports two compression algorithms:
- zlib (
CLIENT_COMPRESS): Available since the early days of MySQL. Well-understood but shows its age in terms of compression ratio and CPU efficiency. - zstd (
CLIENT_ZSTD_COMPRESSION_ALGORITHM): Introduced in MySQL 8.0.18. Offers significantly better compression ratios with substantially lower CPU overhead.
For ProxySQL users operating at scale, the difference matters:
| Metric | zlib | zstd |
|---|---|---|
| Compression ratio | Moderate | High |
| Compression speed | Moderate | Fast |
| Decompression speed | Moderate | Very fast |
| CPU overhead | Higher | Lower |
| Max compression level | 9 | 22 |
In practice, zstd at level 3 (the default) typically achieves compression ratios comparable to zlib at level 6-9, but with much less CPU usage. For high-throughput OLTP workloads over WAN connections, this translates to lower latency and higher throughput.
How It Works
When mysql-have_compress is set to true (the default), ProxySQL advertises both CLIENT_COMPRESS and CLIENT_ZSTD_COMPRESSION_ALGORITHM in its server capabilities during the MySQL handshake. The client then negotiates its preferred algorithm.
The compression level is controlled by the existing mysql-protocol_compression_level variable. For zstd, the level is automatically clamped to the valid zstd range (1 to 22). If the client specifies a preferred level in the handshake, that level takes precedence over the server-side default.
No new configuration variables are needed. The feature is enabled transparently for any client that supports zstd.
Static Linking
The zstd library (v1.5.7) is statically linked into the ProxySQL binary. This ensures consistent compression behavior across all supported platforms without requiring an external library installation. The static linking also eliminates potential version mismatch issues between the proxy and system libraries.
Configuration
There is nothing new to configure. The existing variables work as before with extended semantics:
-- Enable compression (advertising both zlib and zstd)
SET mysql-have_compress = 'true';
-- Set compression level
-- For zlib: -1 (library default) to 9
-- For zstd: 1 to 22 (clamped automatically)
SET mysql-protocol_compression_level = 3;
LOAD MYSQL VARIABLES TO RUNTIME;
Client Compatibility
Clients that support zstd compression will automatically negotiate it.
Clients that only support zlib will continue to use zlib compression as before. Clients without compression support will use uncompressed connections. There is full backward compatibility.
Performance Considerations
For most deployments, zstd level 3 (the default) provides the best balance between compression ratio and CPU usage. If you are CPU-constrained, levels 1-2 offer good compression with minimal overhead. If you need maximum compression and can afford the CPU, levels 10-22 provide the highest ratios.
For LAN deployments where bandwidth is plentiful, compression may not be beneficial. For WAN or cross-region deployments, zstd compression can significantly reduce bandwidth costs and improve query latency.
Looking Ahead
This is the first step in our compression roadmap. Future releases will explore:
- Compression statistics in admin tables
- Per-hostgroup compression settings
- Compression policy rules based on query size thresholds
Ready to try zstd compression? Upgrade to ProxySQL 3.0.7 and let your clients negotiate the best algorithm automatically.