Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ crate-type = ["cdylib"]

napi = { version = "2.16.16", default-features = false, features = ["napi4", "napi6", "async"] }
napi-derive = "2.16.6"
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "v1.2.0" }
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "v1.2.0" , features = ["chrono-04"]}
tokio = { version = "1.34", features = ["full"] }
futures = "0.3"
uuid = "1"
regex = "1.11.1"
thiserror = "2.0.12"
chrono = "0.4"


[build-dependencies]
Expand Down Expand Up @@ -47,3 +48,19 @@ path = "benchmark/logic_rust/concurrent_select.rs"
[[bin]]
name = "batch_benchmark"
path = "benchmark/logic_rust/batch.rs"

[[bin]]
name = "deser_benchmark"
path = "benchmark/logic_rust/deser.rs"

[[bin]]
name = "concurrent_deser_benchmark"
path = "benchmark/logic_rust/concurrent_deser.rs"

[[bin]]
name = "ser_benchmark"
path = "benchmark/logic_rust/ser.rs"

[[bin]]
name = "concurrent_ser_benchmark"
path = "benchmark/logic_rust/concurrent_ser.rs"
54 changes: 54 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,60 @@ Rust:
CNT=<Number of queries> cargo run --bin select_benchmark -r
```

- **concurrent deserialization**

This benchmark uses `executeConcurrent` endpoint to insert `n` rows containing `uuid`, `int`, `timeuuid`, `inet`, `date`, `time` into the database. Afterwards it uses `executeConcurrent` endpoint to select all (`n`) of the inserted rows from the database `n` times.

JS:
```
node concurrent_deser.js <driver> <Number of queries>
```
Rust:
```
CNT=<Number of queries> cargo run --bin concurrent_deser_benchmark -r
```

- **deserialization**

This benchmark executes `n` `client.execute` queries, that insert a single row containing `uuid`, `int`, `timeuuid`, `inet`, `date`, `time` waiting for the result of the previous query before executing the next one. Afterwards it executes `n` `client.execute` queries, that select all (`n`) of the inserted rows, waiting for the result of the previous query before executing the next one.

JS:
```
node deser.js <driver> <Number of queries>
```
Rust:
```
CNT=<Number of queries> cargo run --bin deser_benchmark -r
```



- **concurrent serialization**

This benchmark uses `executeConcurrent` endpoint to insert `n*n` rows containing `uuid`, `int`, `timeuuid`, `inet`, `date`, `time` into the database.

JS:
```
node concurrent_ser.js <driver> <Number of queries>
```
Rust:
```
CNT=<Number of queries> cargo run --bin concurrent_ser_benchmark -r
```

- **serialization**

This benchmark executes `n*n` `client.execute` queries, that insert a single row containing `uuid`, `int`, `timeuuid`, `inet`, `date`, `time` waiting for the result of the previous query before executing the next one.

JS:
```
node ser.js <driver> <Number of queries>
```
Rust:
```
CNT=<Number of queries> cargo run --bin ser_benchmark -r
```

- **batch**

This benchmark uses `client.batch` endpoint to insert `n` rows containing `uuid` and `int` into the database. Afterwards, it checks that the number of rows inserted is correct.
Expand Down
49 changes: 49 additions & 0 deletions benchmark/logic/concurrent_deser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use strict";
const async = require("async");
// Possible values of argv[2] (driver) are scylladb-javascript-driver and cassandra-driver.
const cassandra = require(process.argv[2]);
const utils = require("./utils");
const { exit } = require("process");

const client = new cassandra.Client(utils.getClientArgs());
const iterCnt = parseInt(process.argv[3]);

async.series(
[
function initialize(next) {
utils.prepareDatabase(client, utils.tableSchemaDesSer, next);
},
async function insert(next) {
let allParameters = utils.insertConcurrentDeSer(cassandra, iterCnt);
try {
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, { prepare: true });
} catch (err) {
return next(err);
}
next();
},
async function select(next) {

let allParameters = [];
for (let i = 0; i < iterCnt; i++) {
allParameters.push({
query: 'SELECT * FROM benchmarks.basic',
});
}
try {
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, { prepare: true, collectResults: true });
} catch (err) {
return next(err);
}
next();
},
function r() {
exit(0);
}
], function (err) {
if (err) {
console.error("Error: ", err.message, err.stack);
exit(1);
}
},);

34 changes: 34 additions & 0 deletions benchmark/logic/concurrent_ser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict";
const async = require("async");
// Possible values of argv[2] (driver) are scylladb-javascript-driver and cassandra-driver.
const cassandra = require(process.argv[2]);
const utils = require("./utils");
const { exit } = require("process");

const client = new cassandra.Client(utils.getClientArgs());
const iterCnt = parseInt(process.argv[3]);

async.series(
[
function initialize(next) {
utils.prepareDatabase(client, utils.tableSchemaDesSer, next);
},
async function insert(next) {
let allParameters = utils.insertConcurrentDeSer(cassandra, iterCnt * iterCnt);
try {
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, { prepare: true });
} catch (err) {
return next(err);
}
next();
},
function r() {
exit(0);
}
], function (err) {
if (err) {
console.error("Error: ", err.message, err.stack);
exit(1);
}
},);

49 changes: 49 additions & 0 deletions benchmark/logic/deser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use strict";
const async = require("async");
// Possible values of argv[2] (driver) are scylladb-javascript-driver and cassandra-driver.
const cassandra = require(process.argv[2]);
const utils = require("./utils");
const { exit } = require("process");

const client = new cassandra.Client(utils.getClientArgs());
const iterCount = parseInt(process.argv[3]);

async.series(
[
function initialize(next) {
utils.prepareDatabase(client, utils.tableSchemaDesSer, next);
},
async function insert(next) {
for (let i = 0; i < iterCount; i++) {
try {
await client.execute(utils.DesSerInsertStatement, utils.insertDeSer(cassandra), { prepare: true });
} catch (err) {
return next(err);
}
}
next();
},
async function select(next) {
const query = "SELECT * FROM benchmarks.basic";
for (let i = 0; i < iterCount; i++) {
try {
await client.execute(query);
} catch (err) {
return next(err);
}
}
next();
},
function r() {
exit(0);
}
],
function (err) {
if (err) {
console.error("There was an error", err.message, err.stack);
exit(1);
}

},
);

38 changes: 38 additions & 0 deletions benchmark/logic/ser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";
const async = require("async");
// Possible values of argv[2] (driver) are scylladb-javascript-driver and cassandra-driver.
const cassandra = require(process.argv[2]);
const utils = require("./utils");
const { exit } = require("process");

const client = new cassandra.Client(utils.getClientArgs());
const iterCount = parseInt(process.argv[3]);

async.series(
[
function initialize(next) {
utils.prepareDatabase(client, utils.tableSchemaDesSer, next);
},
async function insert(next) {
for (let i = 0; i < iterCount * iterCount; i++) {
try {
await client.execute(utils.DesSerInsertStatement, utils.insertDeSer(cassandra), { prepare: true });
} catch (err) {
return next(err);
}
}
next();
},
function r() {
exit(0);
}
],
function (err) {
if (err) {
console.error("There was an error", err.message, err.stack);
exit(1);
}

},
);

33 changes: 33 additions & 0 deletions benchmark/logic/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"use strict";
const { randomBytes } = require("crypto");
const utils = require("../../lib/utils");

const { _Client } = require("../../main");

const tableSchemaBasic = "CREATE TABLE benchmarks.basic (id uuid, val int, PRIMARY KEY(id))";
const tableSchemaDesSer = "CREATE TABLE benchmarks.basic (id uuid, val int, tuuid timeuuid, ip inet, date date, time time, PRIMARY KEY(id))";
const DesSerInsertStatement = "INSERT INTO benchmarks.basic (id, val, tuuid, ip, date, time) VALUES (?, ?, ?, ?, ?, ?)";
const singleStepCount = 1000000;

function getClientArgs() {
Expand Down Expand Up @@ -52,7 +56,36 @@ async function repeatCapped(callback, n) {

}




function insertDeSer(cassandra) {
const id = cassandra.types.Uuid.random();
const tuid = cassandra.types.TimeUuid.fromString("8e14e760-7fa8-11eb-bc66-000000000001");
const ip = new cassandra.types.InetAddress(utils.allocBufferFromArray(randomBytes(4)));
const date = cassandra.types.LocalDate.now();
const time = cassandra.types.LocalTime.now();

return [id, 100, tuid, ip, date, time];
}

function insertConcurrentDeSer(cassandra, n) {
let allParameters = [];
for (let i = 0; i < n; i++) {
allParameters.push({
query: "INSERT INTO benchmarks.basic (id, val, tuuid, ip, date, time) VALUES (?, ?, ?, ?, ?, ?)",
params: insertDeSer(cassandra)
});
}
return allParameters;
}

exports.getClientArgs = getClientArgs;
exports.insertDeSer = insertDeSer;
exports.tableSchemaBasic = tableSchemaBasic;
exports.tableSchemaDesSer = tableSchemaDesSer;
exports.DesSerInsertStatement = DesSerInsertStatement;
exports.getClientArgs = getClientArgs;
exports.prepareDatabase = prepareDatabase;
exports.insertConcurrentDeSer = insertConcurrentDeSer;
exports.repeatCapped = repeatCapped;
Loading
Loading