26 releases (stable)

8.1.3 Apr 25, 2024
8.1.2 Oct 2, 2023
8.1.1 May 11, 2023
8.0.0-beta.1 Mar 6, 2023
1.0.0 Nov 17, 2020

#145 in Database interfaces

Download history 754/week @ 2024-04-05 1177/week @ 2024-04-12 2376/week @ 2024-04-19 1790/week @ 2024-04-26 1557/week @ 2024-05-03 3866/week @ 2024-05-10 1999/week @ 2024-05-17 1074/week @ 2024-05-24 1250/week @ 2024-05-31 1722/week @ 2024-06-07 2399/week @ 2024-06-14 3056/week @ 2024-06-21 1999/week @ 2024-06-28 2340/week @ 2024-07-05 5067/week @ 2024-07-12 2111/week @ 2024-07-19

11,980 downloads per month
Used in cqlmig-cdrs-tokio

MIT/Apache

750KB
19K SLoC

CDRS tokio

crates.io version build status

CDRS tokio - async Apache Cassandra driver using tokio

CDRS is production-ready Apache Cassandra driver written in pure Ru* *s**t. Focuses on providing high level of configurability to suit most use cases at any scale, as its Java counterpart, while also leveraging the safety and performance of Rust.

Features

  • Asynchronous API;
  • TCP/TLS connection (rustls);
  • Topology-aware dynamic and configurable load balancing;
  • Configurable connection strategies and pools;
  • Configurable speculative execution;
  • LZ4, Snappy compression;
  • Cassandra-to-Rust data serialization/deserialization with custom type support;
  • Pluggable authentication strategies;
  • ScyllaDB support;
  • Server events listening;
  • Multiple CQL version support (3, 4, 5), full spec implementation;
  • Query tracing information;
  • Prepared statements;
  • Query paging;
  • Batch statements;
  • Configurable retry and reconnection policy;
  • Support for interleaved queries;
  • Support for Yugabyte YCQL JSONB;
  • Support for beta protocol usage;

Performance

Due to high configurability of CDRS, the performance will vary depending on use case. The following benchmarks have been made against the latest (master as of 03-12-2021) versions of respective libraries (except cassandra-cpp: 2.16.0) and protocol version 4.

  • cdrs-tokio-large-pool - CDRS with node connection pool equal to double of physical CPU cores
  • cdrs-tokio-small-pool - CDRS with a single connection per node
  • scylladb-rust-large-pool - scylla crate with node connection pool equal to double of physical CPU cores
  • scylladb-rust-small-pool - scylla crate with a single connection per node
  • cassandra-cpp - Rust bindings for Datastax C++ Driver, running on multiple threads using Tokio
  • gocql - a driver written in Go
insert benchmark select benchmark mixed benchmark

Knowing given use case, CDRS can be optimized for peak performance.

Documentation and examples

Getting started

This example configures a cluster consisting of a single node without authentication, and uses round-robin load balancing. Other options are kept as default.

use cdrs_tokio::cluster::session::{TcpSessionBuilder, SessionBuilder};
use cdrs_tokio::cluster::NodeTcpConfigBuilder;
use cdrs_tokio::load_balancing::RoundRobinLoadBalancingStrategy;
use cdrs_tokio::query::*;

#[tokio::main]
async fn main() {
    let cluster_config = NodeTcpConfigBuilder::new()
        .with_contact_point("127.0.0.1:9042".into())
        .build()
        .await
        .unwrap();
    let session = TcpSessionBuilder::new(RoundRobinLoadBalancingStrategy::new(), cluster_config)
        .build()
        .await
        .unwrap();

    let create_ks = "CREATE KEYSPACE IF NOT EXISTS test_ks WITH REPLICATION = { \
                     'class' : 'SimpleStrategy', 'replication_factor' : 1 };";
    session
        .query(create_ks)
        .await
        .expect("Keyspace create error");
}

License

This project is licensed under either of

at your option.

Dependencies

~8–19MB
~261K SLoC