Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
conorbros committed Aug 17, 2022
1 parent c49a38b commit 83a7810
Show file tree
Hide file tree
Showing 23 changed files with 735 additions and 483 deletions.
62 changes: 39 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions shotover-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "Apache-2.0"
[features]
# Include WIP alpha transforms in the public API
alpha-transforms = []
cpp-driver-tests = []

[dependencies]
pretty-hex = "0.3.0"
Expand Down Expand Up @@ -63,7 +64,7 @@ halfbrown = "0.1.11"

# Transform dependencies
redis-protocol = { version = "4.0.1", features = ["decode-mut"] }
cassandra-protocol = { git = "https://github.com/krojew/cdrs-tokio" }
cassandra-protocol = { git = "https://github.com/conorbros/cdrs-tokio", branch = "v5-protocol" }
crc16 = "0.4.0"
ordered-float = { version = "3.0.0", features = ["serde"] }

Expand All @@ -90,7 +91,8 @@ hex-literal = "0.3.3"
nix = "0.24.0"
reqwest = "0.11.6"
metrics-util = "0.14.0"
cdrs-tokio = { git = "https://github.com/krojew/cdrs-tokio" }
cdrs-tokio = { git = "https://github.com/conorbros/cdrs-tokio", branch = "v5-protocol" }
rstest = "0.15.0"

[[bench]]
name = "redis_benches"
Expand All @@ -103,3 +105,4 @@ harness = false
[[bench]]
name = "cassandra_benches"
harness = false
required-features = ["cpp-driver-tests"]
86 changes: 37 additions & 49 deletions shotover-proxy/benches/cassandra_benches.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use cassandra_cpp::{stmt, Session, Statement};
use criterion::{criterion_group, criterion_main, Criterion};
use test_helpers::cert::generate_cassandra_test_certs;
use test_helpers::docker_compose::DockerCompose;
use test_helpers::lazy::new_lazy_shared;

#[path = "../tests/helpers/mod.rs"]
mod helpers;
use helpers::cassandra::CassandraConnection;
use helpers::cassandra::{CassandraConnection, CassandraDriver};
use helpers::ShotoverManager;

struct Query {
name: &'static str,
statement: Statement,
statement: &'static str,
}

const DRIVER: CassandraDriver = CassandraDriver::Datastax;

fn cassandra(c: &mut Criterion) {
let mut group = c.benchmark_group("cassandra");
group.throughput(criterion::Throughput::Elements(1));
Expand All @@ -22,13 +23,12 @@ fn cassandra(c: &mut Criterion) {
let queries = [
Query {
name: "insert",
statement: stmt!(
"INSERT INTO benchmark_keyspace.table_1 (id, x, name) VALUES (1, 11, 'foo');"
),
statement:
"INSERT INTO benchmark_keyspace.table_1 (id, x, name) VALUES (1, 11, 'foo');",
},
Query {
name: "select",
statement: stmt!("SELECT id, x, name FROM benchmark_keyspace.table_1;"),
statement: "SELECT id, x, name FROM benchmark_keyspace.table_1;",
},
];

Expand All @@ -49,7 +49,7 @@ fn cassandra(c: &mut Criterion) {
b.iter(|| {
let mut resources = resources.borrow_mut();
let connection = &mut resources.as_mut().unwrap().connection;
connection.execute(&query.statement).wait().unwrap();
connection.execute(query.statement);
})
},
);
Expand All @@ -72,7 +72,7 @@ fn cassandra(c: &mut Criterion) {
b.iter(|| {
let mut resources = resources.borrow_mut();
let connection = &mut resources.as_mut().unwrap().connection;
connection.execute(&query.statement).wait().unwrap();
connection.execute(query.statement);
})
},
);
Expand All @@ -94,7 +94,7 @@ fn cassandra(c: &mut Criterion) {
b.iter(|| {
let mut resources = resources.borrow_mut();
let connection = &mut resources.as_mut().unwrap().connection;
connection.execute(&query.statement).wait().unwrap();
connection.execute(query.statement);
})
},
);
Expand All @@ -117,7 +117,7 @@ fn cassandra(c: &mut Criterion) {
b.iter(|| {
let mut resources = resources.borrow_mut();
let connection = &mut resources.as_mut().unwrap().connection;
connection.execute(&query.statement).wait().unwrap();
connection.execute(query.statement);
})
},
);
Expand All @@ -140,7 +140,7 @@ fn cassandra(c: &mut Criterion) {
b.iter(|| {
let mut resources = resources.borrow_mut();
let connection = &mut resources.as_mut().unwrap().connection;
connection.execute(&query.statement).wait().unwrap();
connection.execute(query.statement);
})
},
);
Expand All @@ -159,7 +159,7 @@ fn cassandra(c: &mut Criterion) {
b.iter(|| {
let mut resources = resources.borrow_mut();
let connection = &mut resources.as_mut().unwrap().connection;
connection.execute(&query.statement).wait().unwrap();
connection.execute(query.statement);
})
});
}
Expand All @@ -170,11 +170,11 @@ fn cassandra(c: &mut Criterion) {
let queries = [
Query {
name: "insert",
statement: stmt!("INSERT INTO test_protect_keyspace.test_table (pk, cluster, col1, col2, col3) VALUES ('pk1', 'cluster', 'I am gonna get encrypted!!', 42, true);"),
statement: "INSERT INTO test_protect_keyspace.test_table (pk, cluster, col1, col2, col3) VALUES ('pk1', 'cluster', 'I am gonna get encrypted!!', 42, true);",
},
Query {
name: "select",
statement: stmt!("SELECT pk, cluster, col1, col2, col3 FROM test_protect_keyspace.test_table"),
statement: "SELECT pk, cluster, col1, col2, col3 FROM test_protect_keyspace.test_table",
},
];
let resources = new_lazy_shared(|| {
Expand All @@ -185,25 +185,21 @@ fn cassandra(c: &mut Criterion) {

resources
.connection
.execute(&stmt!(
.execute(
"CREATE KEYSPACE test_protect_keyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
))
.wait()
.unwrap();
);

resources
.connection
.execute(&stmt!(
.execute(
"CREATE TABLE test_protect_keyspace.test_table (pk varchar PRIMARY KEY, cluster varchar, col1 blob, col2 int, col3 boolean);"
))
.wait()
.unwrap();
);

resources
.connection
.execute(&stmt!(
.execute(
"INSERT INTO test_protect_keyspace.test_table (pk, cluster, col1, col2, col3) VALUES ('pk1', 'cluster', 'Initial value', 42, true);"
))
.wait()
.unwrap();
);

resources
});
Expand All @@ -216,7 +212,7 @@ fn cassandra(c: &mut Criterion) {
b.iter(|| {
let mut resources = resources.borrow_mut();
let connection = &mut resources.as_mut().unwrap().connection;
connection.execute(&query.statement).wait().unwrap();
connection.execute(query.statement);
})
},
);
Expand All @@ -238,7 +234,7 @@ fn cassandra(c: &mut Criterion) {
b.iter(|| {
let mut resources = resources.borrow_mut();
let connection = &mut resources.as_mut().unwrap().connection;
connection.execute(&query.statement).wait().unwrap();
connection.execute(query.statement);
})
},
);
Expand All @@ -252,16 +248,15 @@ criterion_main!(benches);
pub struct BenchResources {
_compose: DockerCompose,
_shotover_manager: ShotoverManager,
connection: Session,
connection: CassandraConnection,
}

impl BenchResources {
fn new(shotover_topology: &str, compose_file: &str) -> Self {
let compose = DockerCompose::new(compose_file);
let shotover_manager = ShotoverManager::from_topology_file(shotover_topology);

let CassandraConnection::Datastax(connection) =
shotover_manager.cassandra_connection("127.0.0.1", 9042);
let connection = shotover_manager.cassandra_connection("127.0.0.1", 9042, DRIVER);

let bench_resources = Self {
_compose: compose,
Expand All @@ -279,8 +274,8 @@ impl BenchResources {

let ca_cert = "example-configs/cassandra-tls/certs/localhost_CA.crt";

let CassandraConnection::Datastax(connection) =
shotover_manager.cassandra_connection_tls("127.0.0.1", 9042, ca_cert);
let connection =
shotover_manager.cassandra_connection_tls("127.0.0.1", 9042, ca_cert, DRIVER);

let bench_resources = Self {
_compose: compose,
Expand All @@ -293,23 +288,16 @@ impl BenchResources {

fn setup(&self) {
self.connection
.execute(&stmt!(
.execute(
"CREATE KEYSPACE benchmark_keyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
))
.wait().unwrap();
);

self.connection
.execute(&stmt!(
"CREATE TABLE benchmark_keyspace.table_1 (id int PRIMARY KEY, x int, name varchar);"
))
.wait()
.unwrap();
self.connection.execute(
"CREATE TABLE benchmark_keyspace.table_1 (id int PRIMARY KEY, x int, name varchar);",
);

self.connection
.execute(&stmt!(
"INSERT INTO benchmark_keyspace.table_1 (id, x, name) VALUES (0, 10, 'initial value');"
))
.wait()
.unwrap();
self.connection.execute(
"INSERT INTO benchmark_keyspace.table_1 (id, x, name) VALUES (0, 10, 'initial value');",
);
}
}
2 changes: 1 addition & 1 deletion shotover-proxy/benches/chain_benches.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytes::Bytes;
use cassandra_protocol::{
compression::Compression, consistency::Consistency, frame::Version, query::QueryParams,
compression::Compression, consistency::Consistency, envelope::Version, query::QueryParams,
};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use hex_literal::hex;
Expand Down
Loading

0 comments on commit 83a7810

Please sign in to comment.