Overview
The ScyllaDB Rust Driver supports frame compression to reduce the amount of data transmitted over the network. Compression can significantly reduce bandwidth usage, especially for queries that return large result sets. The driver supports two compression algorithms:- LZ4: Fast compression with moderate compression ratios
- Snappy: Very fast compression/decompression with lower compression ratios
Compression Enum
TheCompression enum represents the available compression algorithms:
Configuring Compression
Compression is configured on theSessionBuilder using the compression() method. By default, compression is disabled (None).
Enabling LZ4 Compression
Enabling Snappy Compression
Disabling Compression
To explicitly disable compression (or revert after setting it):How Compression Works
Compression Negotiation
When you specify a preferred compression algorithm, the driver will:- Request the specified compression during the connection handshake
- If the server supports the requested algorithm, it will be used for all frames
- If the server doesn’t support it, the driver will fall back to no compression
The driver negotiates compression separately for each connection. If the database server doesn’t support your preferred compression algorithm, the session will still be established successfully without compression.
What Gets Compressed
Compression applies to the frame body only, not the frame header:- Request frames: Query strings, bound values, batch statements, etc.
- Response frames: Result sets, schema information, error messages, etc.
Choosing a Compression Algorithm
LZ4
Best for: General-purpose use with large result sets Advantages:- Good compression ratios
- Fast compression and decompression
- Widely supported
Snappy
Best for: Ultra-low latency requirements Advantages:- Very fast compression/decompression
- Low CPU overhead
- Predictable performance
Performance Considerations
When to Use Compression
Compression is beneficial when:- Your network bandwidth is limited
- You’re transferring large result sets
- Network latency is higher than compression overhead
- You’re on a metered network connection
When to Avoid Compression
You may want to disable compression when:- You’re on a fast local network (e.g., same datacenter)
- Your queries return small result sets
- CPU resources are constrained
- You need the absolute lowest latency
Benchmarking
Complete Example
Here’s a complete example demonstrating compression configuration:Compression String Representation
TheCompression enum provides methods for string conversion:
See Also
Connection Overview
Learn about basic connection configuration
TLS/SSL
Configure secure TLS connections
