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
Scylla Java Driver Manual Core driver Compression

Compression¶

Quick overview¶

Compress request and response bodies to save bandwidth.

  • advanced.protocol.compression in the configuration.

  • disabled by default. Also available: LZ4, Snappy.

  • your application must re-declare an explicit dependency to the compression library.


Cassandra’s binary protocol supports optional compression of requests and responses. This reduces network traffic at the cost of a slight CPU overhead, therefore it will likely be beneficial when you have larger payloads, such as:

  • requests with many values, or very large values;

  • responses with many rows, or many columns per row, or very large columns.

To enable compression, set the following option in the configuration:

datastax-java-driver {
  advanced.protocol.compression = lz4 // or snappy
}

Compression must be set before opening a session, it cannot be changed at runtime.

Two algorithms are supported out of the box: 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 implementations rely on third-party libraries, declared by the driver as optional dependencies; if you enable compression, you need to explicitly depend on the corresponding library to pull it into your project (see the Integration>Driver dependencies section for more details).

LZ4¶

Dependency:

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

Always double-check the exact LZ4 version needed; you can find it in the driver’s parent POM.

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.oss.driver.internal.core.protocol.Lz4Compressor and look for the following message:

INFO  com.datastax.oss.driver.internal.core.protocol.Lz4Compressor  - Using LZ4Factory:JNI

Snappy¶

Dependency:

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

Important: Snappy is not supported when building a GraalVM native image.

Always double-check the exact Snappy version needed; you can find it in the driver’s parent POM.

PREVIOUS
Bill of Materials (BOM)
NEXT
Configuration
  • 4.13.0.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
  • Java Driver for Scylla and Apache Cassandra®
  • API Documentation
  • Manual
    • API conventions
    • Case sensitivity
    • Core driver
      • Address resolution
      • Asynchronous programming
      • Authentication
      • Bill of Materials (BOM)
      • Compression
      • Configuration
        • Reference configuration
      • Control connection
      • Custom codecs
      • Detachable types
      • Using the driver in GraalVM native images
      • Query idempotence
      • Integration
      • Load balancing
      • Logging
      • Metadata
        • Node metadata
        • Schema metadata
        • Token metadata
      • Metrics
      • Native protocol
      • Non-blocking programming
      • Paging
      • Performance
      • Connection pooling
      • Query timestamps
      • Reactive Style Programming
      • Reconnection
      • Request tracker
      • Retries
      • Using the shaded JAR
      • Speculative query execution
      • SSL
      • Statements
        • Batch statements
        • Per-query keyspace
        • Prepared statements
        • Simple statements
      • Temporal types
      • Request throttling
      • Query tracing
      • Tuples
      • User-defined types
    • Developer docs
      • Administrative tasks
      • Common infrastructure
        • Concurrency
        • Driver context
        • Event bus
      • Native protocol layer
      • Netty pipeline
      • Request execution
    • Mapper
      • Integration
        • Kotlin
        • Lombok
        • Java 14 Records
        • Scala
      • DAOs
        • Custom result types
        • Delete methods
        • GetEntity methods
        • Increment methods
        • Insert methods
        • Null saving strategy
        • Query methods
        • Query provider methods
        • Select methods
        • SetEntity methods
        • Statement attributes
        • Update methods
      • Entities
      • Mapper interface
    • OSGi
    • Query builder
      • Conditions
      • DELETE
      • Idempotence in the query builder
      • INSERT
      • Relations
      • Schema builder
        • Aggregate
        • Function
        • Index
        • Keyspace
        • Materialized View
        • Table
        • Type
      • SELECT
      • Terms
      • TRUNCATE
      • UPDATE
  • Upgrade guide
  • Frequently asked questions
  • Changelog
  • Create an issue
  • Edit this page

On this page

  • Compression
    • Quick overview
    • 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