Skip to content

Commit 80200da

Browse files
adespawnStapox35
authored andcommitted
Compress SerDes benchmarks
1 parent b3e4443 commit 80200da

File tree

5 files changed

+34
-102
lines changed

5 files changed

+34
-102
lines changed

benchmark/logic/concurrent_deser.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,36 @@
22
const async = require("async");
33
// Possible values of argv[2] (driver) are scylladb-javascript-driver and cassandra-driver.
44
const cassandra = require(process.argv[2]);
5-
const { getClientArgs, insertConcurrentDeSer } = require("./utils");
5+
const utils = require("./utils");
66
const { exit } = require("process");
77

8-
const client = new cassandra.Client(getClientArgs());
9-
const iterCnt = parseInt(process.argv[3]);
8+
const client = new cassandra.Client(utils.getClientArgs());
9+
const iterCnt = parseInt(process.argv[3]);
1010

1111
async.series(
1212
[
13-
function connect(next) {
14-
client.connect(next);
15-
},
16-
function createKeyspace(next) {
17-
// Keep replication one to reduce time spent in the database
18-
const query =
19-
"CREATE KEYSPACE IF NOT EXISTS benchmarks WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': '1' }";
20-
client.execute(query, next);
21-
},
22-
// Drop table to ensure no overhead comes from having already some data in the database
23-
function dropTable(next) {
24-
const query =
25-
"DROP TABLE IF EXISTS benchmarks.basic";
26-
client.execute(query, next);
27-
},
28-
function createTable(next) {
29-
const query =
30-
"CREATE TABLE benchmarks.basic (id uuid, val int, tuuid timeuuid, ip inet, date date, time time, PRIMARY KEY(id))";
31-
client.execute(query, next);
13+
function initialize(next) {
14+
utils.prepareDatabase(client, utils.tableSchemaDesSer, next);
3215
},
3316
async function insert(next) {
34-
let allParameters = insertConcurrentDeSer(cassandra, iterCnt);
17+
let allParameters = utils.insertConcurrentDeSer(cassandra, iterCnt);
3518
try {
36-
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, {prepare: true});
19+
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, { prepare: true });
3720
} catch (err) {
3821
return next(err);
3922
}
4023
next();
4124
},
4225
async function select(next) {
43-
26+
4427
let allParameters = [];
4528
for (let i = 0; i < iterCnt; i++) {
4629
allParameters.push({
4730
query: 'SELECT * FROM benchmarks.basic',
4831
});
4932
}
5033
try {
51-
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, {prepare: true, collectResults: true});
34+
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, { prepare: true, collectResults: true });
5235
} catch (err) {
5336
return next(err);
5437
}

benchmark/logic/concurrent_ser.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,21 @@
22
const async = require("async");
33
// Possible values of argv[2] (driver) are scylladb-javascript-driver and cassandra-driver.
44
const cassandra = require(process.argv[2]);
5-
const { getClientArgs, insertConcurrentDeSer } = require("./utils");
5+
const utils = require("./utils");
66
const { exit } = require("process");
77

8-
const client = new cassandra.Client(getClientArgs());
9-
const iterCnt = parseInt(process.argv[3]);
8+
const client = new cassandra.Client(utils.getClientArgs());
9+
const iterCnt = parseInt(process.argv[3]);
1010

1111
async.series(
1212
[
13-
function connect(next) {
14-
client.connect(next);
15-
},
16-
function createKeyspace(next) {
17-
// Keep replication one to reduce time spent in the database
18-
const query =
19-
"CREATE KEYSPACE IF NOT EXISTS benchmarks WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': '1' }";
20-
client.execute(query, next);
21-
},
22-
// Drop table to ensure no overhead comes from having already some data in the database
23-
function dropTable(next) {
24-
const query =
25-
"DROP TABLE IF EXISTS benchmarks.basic";
26-
client.execute(query, next);
27-
},
28-
function createTable(next) {
29-
const query =
30-
"CREATE TABLE benchmarks.basic (id uuid, val int, tuuid timeuuid, ip inet, date date, time time, PRIMARY KEY(id))";
31-
client.execute(query, next);
13+
function initialize(next) {
14+
utils.prepareDatabase(client, utils.tableSchemaDesSer, next);
3215
},
3316
async function insert(next) {
34-
let allParameters = insertConcurrentDeSer(cassandra, iterCnt * iterCnt);
17+
let allParameters = utils.insertConcurrentDeSer(cassandra, iterCnt * iterCnt);
3518
try {
36-
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, {prepare: true});
19+
const _result = await cassandra.concurrent.executeConcurrent(client, allParameters, { prepare: true });
3720
} catch (err) {
3821
return next(err);
3922
}

benchmark/logic/deser.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,21 @@
22
const async = require("async");
33
// Possible values of argv[2] (driver) are scylladb-javascript-driver and cassandra-driver.
44
const cassandra = require(process.argv[2]);
5-
const { getClientArgs, insertDeSer } = require("./utils");
5+
const utils = require("./utils");
66
const { exit } = require("process");
77

8-
const client = new cassandra.Client(getClientArgs());
8+
const client = new cassandra.Client(utils.getClientArgs());
99
const iterCount = parseInt(process.argv[3]);
1010

1111
async.series(
1212
[
13-
function connect(next) {
14-
client.connect(next);
15-
},
16-
function createKeyspace(next) {
17-
// Keep replication one to reduce time spent in the database
18-
const query =
19-
"CREATE KEYSPACE IF NOT EXISTS benchmarks WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': '1' }";
20-
client.execute(query, next);
21-
},
22-
// Drop table to ensure no overhead comes from having already some data in the database
23-
function dropTable(next) {
24-
const query =
25-
"DROP TABLE IF EXISTS benchmarks.basic";
26-
client.execute(query, next);
27-
},
28-
function createTable(next) {
29-
const query =
30-
"CREATE TABLE benchmarks.basic (id uuid, val int, tuuid timeuuid, ip inet, date date, time time, PRIMARY KEY(id))";
31-
client.execute(query, next);
13+
function initialize(next) {
14+
utils.prepareDatabase(client, utils.tableSchemaDesSer, next);
3215
},
3316
async function insert(next) {
34-
const query =
35-
"INSERT INTO benchmarks.basic (id, val, tuuid, ip, date, time) VALUES (?, ?, ?, ?, ?, ?)";
3617
for (let i = 0; i < iterCount; i++) {
3718
try {
38-
await client.execute(query, insertDeSer(cassandra), {prepare: true});
19+
await client.execute(utils.DesSerInsertStatement, utils.insertDeSer(cassandra), { prepare: true });
3920
} catch (err) {
4021
return next(err);
4122
}
@@ -53,7 +34,7 @@ async.series(
5334
}
5435
next();
5536
},
56-
function r(){
37+
function r() {
5738
exit(0);
5839
}
5940
],
@@ -62,7 +43,7 @@ async.series(
6243
console.error("There was an error", err.message, err.stack);
6344
exit(1);
6445
}
65-
46+
6647
},
6748
);
6849

benchmark/logic/ser.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,28 @@
22
const async = require("async");
33
// Possible values of argv[2] (driver) are scylladb-javascript-driver and cassandra-driver.
44
const cassandra = require(process.argv[2]);
5-
const { getClientArgs, insertDeSer } = require("./utils");
5+
const utils = require("./utils");
66
const { exit } = require("process");
77

8-
const client = new cassandra.Client(getClientArgs());
8+
const client = new cassandra.Client(utils.getClientArgs());
99
const iterCount = parseInt(process.argv[3]);
1010

1111
async.series(
1212
[
13-
function connect(next) {
14-
client.connect(next);
15-
},
16-
function createKeyspace(next) {
17-
// Keep replication one to reduce time spent in the database
18-
const query =
19-
"CREATE KEYSPACE IF NOT EXISTS benchmarks WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': '1' }";
20-
client.execute(query, next);
21-
},
22-
// Drop table to ensure no overhead comes from having already some data in the database
23-
function dropTable(next) {
24-
const query =
25-
"DROP TABLE IF EXISTS benchmarks.basic";
26-
client.execute(query, next);
27-
},
28-
function createTable(next) {
29-
const query =
30-
"CREATE TABLE benchmarks.basic (id uuid, val int, tuuid timeuuid, ip inet, date date, time time, PRIMARY KEY(id))";
31-
client.execute(query, next);
13+
function initialize(next) {
14+
utils.prepareDatabase(client, utils.tableSchemaDesSer, next);
3215
},
3316
async function insert(next) {
34-
const query =
35-
"INSERT INTO benchmarks.basic (id, val, tuuid, ip, date, time) VALUES (?, ?, ?, ?, ?, ?)";
3617
for (let i = 0; i < iterCount * iterCount; i++) {
3718
try {
38-
await client.execute(query, insertDeSer(cassandra), {prepare: true});
19+
await client.execute(utils.DesSerInsertStatement, utils.insertDeSer(cassandra), { prepare: true });
3920
} catch (err) {
4021
return next(err);
4122
}
4223
}
4324
next();
4425
},
45-
function r(){
26+
function r() {
4627
exit(0);
4728
}
4829
],
@@ -51,7 +32,7 @@ async.series(
5132
console.error("There was an error", err.message, err.stack);
5233
exit(1);
5334
}
54-
35+
5536
},
5637
);
5738

benchmark/logic/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const utils = require("../../lib/utils");
55
const { _Client } = require("../../main");
66

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

1012
function getClientArgs() {
@@ -81,6 +83,8 @@ function insertConcurrentDeSer(cassandra, n) {
8183
exports.getClientArgs = getClientArgs;
8284
exports.insertDeSer = insertDeSer;
8385
exports.tableSchemaBasic = tableSchemaBasic;
86+
exports.tableSchemaDesSer = tableSchemaDesSer;
87+
exports.DesSerInsertStatement = DesSerInsertStatement;
8488
exports.getClientArgs = getClientArgs;
8589
exports.prepareDatabase = prepareDatabase;
8690
exports.insertConcurrentDeSer = insertConcurrentDeSer;

0 commit comments

Comments
 (0)