Scylla Documentation Logo Documentation
  • Server
    • Scylla Open Source
    • Scylla Enterprise
    • Scylla Alternator
  • Cloud
    • Scylla Cloud
    • Scylla Cloud Docs
  • Tools
    • Scylla Manager
    • Scylla Monitoring Stack
    • Scylla Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
Download
Menu

Caution

You're viewing documentation for a previous version of Scylla Java Driver. Switch to the latest stable version.

Scylla Java Driver Manual Compression

Compression¶

Cassandra’s binary protocol supports optional compression of transport-level requests and responses, for example:

  • a query with its serialized parameters;

  • a page from a result set, i.e. a list of serialized rows.

It reduces network traffic at the cost of CPU overhead, therefore it will likely be beneficial when you have larger payloads.

Two algorithms are available: LZ4 and Snappy. The LZ4 implementation is a good first choice; it offers fallback implementations in case native libraries fail to load and benchmarks suggest that it offers better performance and compression ratios over Snappy. Both rely on third-party libraries, declared by the driver as optional dependencies. So if you use a build tool like Maven, you’ll need to declare an explicit dependency to pull the appropriate library in your application’s classpath. Then you configure compression at driver startup.

LZ4¶

Maven dependency:

<dependency>
    <groupId>org.lz4</groupId>
    <artifactId>lz4-java</artifactId>
    <version>1.4.1</version>
</dependency>

Always check the exact version of the library: go to the driver’s parent POM (change the URL to match your driver version) and look for the lz4.version property.

Driver configuration:

cluster = Cluster.builder()
    .addContactPoint("127.0.0.1")
    .withCompression(ProtocolOptions.Compression.LZ4)
    .build();

LZ4-java has three internal implementations (from fastest to slowest):

  • JNI;

  • pure Java using sun.misc.Unsafe;

  • pure Java using only “safe” classes.

It will pick the best implementation depending on what’s possible on your platform. To find out which one was chosen, enable INFO logs on the category com.datastax.driver.core.LZ4Compressor and look for a log similar to this:

INFO  com.datastax.driver.core.LZ4Compressor  - Using LZ4Factory:JNI

Snappy¶

Maven dependency:

<dependency>
    <groupId>org.xerial.snappy</groupId>
    <artifactId>snappy-java</artifactId>
    <version>1.1.2.6</version>
</dependency>

Always check the exact version of the library: go to the driver’s parent POM (change the URL to match your driver version) and look for the snappy.version property.

Driver configuration:

cluster = Cluster.builder()
    .addContactPoint("127.0.0.1")
    .withCompression(ProtocolOptions.Compression.SNAPPY)
    .build();
PREVIOUS
Authentication
NEXT
Control connection
  • 3.10.2.x
    • 4.13.0.x
    • 4.12.0.x
    • 4.11.1.x
    • 4.10.0.x
    • 4.7.2.x
    • 3.11.2.x
    • 3.11.0.x
    • 3.10.2.x
    • 3.7.2.x
  • Scylla Java Driver for Scylla and Apache Cassandra®
  • API Documentation
  • Manual
    • Address resolution
    • Asynchronous programming
    • Authentication
    • Compression
    • Control connection
    • Custom Codecs
    • Custom Payloads
    • Query idempotence
    • Load balancing
    • Logging
    • Metadata
    • Metrics
    • Native protocol
    • Object Mapper
      • Definition of mapped classes
      • Using custom codecs
      • Using the mapper
    • OSGi
    • Paging
    • Connection pooling
    • Query timestamps
    • Reconnection
    • Retries
    • Using the shaded JAR
    • Socket options
    • Speculative query execution
    • SSL
    • Statements
      • Simple statements
      • Prepared statements
      • Built statements
      • Batch statements
    • Using Tuples with the Java driver
    • User-defined types
  • Upgrade guide
    • Migrating from Astyanax
      • Configuration
      • Language change : from Thrift to CQL
      • Queries and Results
  • Frequently Asked Questions
  • Changelog
  • Create an issue
  • Edit this page

On this page

  • Compression
    • LZ4
    • Snappy
Logo
Docs Contact Us About Us
Mail List Icon Slack Icon
© 2022, ScyllaDB. All rights reserved.
Last updated on 25 May 2022.
Powered by Sphinx 4.3.2 & ScyllaDB Theme 1.2.2