Skip to content

Commit f1a7efd

Browse files
committed
Add benchmark for the cpp-rust-wrapper driver
1 parent 039bffa commit f1a7efd

File tree

6 files changed

+547
-0
lines changed

6 files changed

+547
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM fedora
2+
3+
RUN dnf -y update
4+
RUN dnf -y install cmake g++ git cargo clang
5+
6+
WORKDIR /wrapper
7+
RUN git clone https://github.com/hackathon-rust-cpp/cpp-rust-driver.git
8+
WORKDIR cpp-rust-driver
9+
RUN cd scylla-rust-wrapper && cargo build --release
10+
11+
# Copy benchmark code into the container
12+
COPY source /source
13+
WORKDIR /source
14+
15+
RUN cp /wrapper/cpp-rust-driver/scylla-rust-wrapper/target/release/libscylla*.a /source
16+
RUN cp /wrapper/cpp-rust-driver/include/* /source
17+
18+
# Compile the code
19+
RUN g++ main.cpp -o basic -std=c++17 -I/boost_1_76_0 -L. -lscylla_cpp_driver -lpthread -O3 -flto -Wall -Wshadow -ldl
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker build . -t rust-driver-benchmarks-basic-cpp-multi-wrapper
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker run --rm -it --network host rust-driver-benchmarks-basic-cpp-multi-wrapper /source/basic "$@"
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#ifndef CONFIG_HPP
2+
#define CONFIG_HPP
3+
4+
#include <vector>
5+
#include <string>
6+
#include <cstring>
7+
#include <iostream>
8+
#include <stdio.h>
9+
10+
enum class Workload {
11+
Inserts,
12+
Selects,
13+
Mixed,
14+
};
15+
16+
inline void print_usage();
17+
18+
struct Config {
19+
std::vector<std::string> node_addresses;
20+
Workload workload;
21+
int64_t tasks;
22+
int64_t concurrency;
23+
int64_t batch_size;
24+
bool dont_prepare;
25+
26+
Config(int argc, const char *argv[]) {
27+
node_addresses = {"127.0.0.1"};
28+
workload = Workload::Inserts;
29+
tasks = 1000 * 1000;
30+
concurrency = 1024;
31+
dont_prepare = false;
32+
33+
for (int a = 1; a < argc;) {
34+
// --dont-prepare
35+
if (strcmp(argv[a], "-d") == 0 || strcmp(argv[a], "--dont-prepare") == 0) {
36+
dont_prepare = true;
37+
a += 1;
38+
continue;
39+
}
40+
41+
if (a + 1 >= argc) {
42+
fprintf(stderr, "ERROR: No value specified for argument %s!\n", argv[a]);
43+
std::exit(1);
44+
}
45+
46+
// --nodes
47+
if (strcmp(argv[a], "-n") == 0 || strcmp(argv[a], "--nodes") == 0) {
48+
std::vector<std::string> addresses = {""};
49+
50+
for (const char* c = argv[a + 1]; *c != 0; c++) {
51+
if (*c == ',') {
52+
addresses.push_back("");
53+
} else {
54+
addresses.back() += *c;
55+
}
56+
}
57+
58+
node_addresses = addresses;
59+
60+
a += 2;
61+
continue;
62+
}
63+
64+
// --workload
65+
if (strcmp(argv[a], "-w") == 0 || strcmp(argv[a], "--workload") == 0) {
66+
if (strcmp(argv[a + 1], "inserts") == 0) {
67+
workload = Workload::Inserts;
68+
} else if (strcmp(argv[a + 1], "selects") == 0) {
69+
workload = Workload::Selects;
70+
} else if (strcmp(argv[a + 1], "mixed") == 0) {
71+
workload = Workload::Mixed;
72+
} else {
73+
fprintf(stderr,
74+
"ERROR: Invalid workload specified: %s. (Allowed values: inserts, "
75+
"selects, mixed)\n",
76+
argv[a + 1]);
77+
78+
std::exit(1);
79+
}
80+
81+
a += 2;
82+
continue;
83+
}
84+
85+
// --tasks
86+
if (strcmp(argv[a], "-t") == 0 || strcmp(argv[a], "--tasks") == 0) {
87+
tasks = std::strtoll(argv[a + 1], nullptr, 10);
88+
89+
a += 2;
90+
continue;
91+
}
92+
93+
// --concurrency
94+
if (strcmp(argv[a], "-c") == 0 || strcmp(argv[a], "--concurrency") == 0) {
95+
concurrency = std::strtoll(argv[a + 1], nullptr, 10);
96+
97+
a += 2;
98+
continue;
99+
}
100+
101+
fprintf(stderr, "Unkown argument: %s\n", argv[a]);
102+
std::exit(1);
103+
}
104+
105+
batch_size = 256;
106+
107+
if (tasks/batch_size < concurrency) {
108+
batch_size = std::max((int64_t)1, tasks / concurrency);
109+
}
110+
}
111+
112+
void print() {
113+
std::cout << "Config:\n";
114+
std::cout << " nodes: [";
115+
for (auto&& node_address : node_addresses) {
116+
std::cout << node_address << ", ";
117+
}
118+
std::cout << "]\n";
119+
120+
std::cout << " workload: ";
121+
122+
switch (workload) {
123+
case Workload::Inserts:
124+
std::cout << "Inserts\n";
125+
break;
126+
127+
case Workload::Selects:
128+
std::cout << "Selects\n";
129+
break;
130+
131+
case Workload::Mixed:
132+
std::cout << "Mixed\n";
133+
break;
134+
}
135+
136+
std::cout << " tasks: " << tasks << "\n";
137+
std::cout << " concurrency: " << concurrency << "\n";
138+
std::cout << " dont_prepare: " << (dont_prepare ? "true" : "false") << "\n";
139+
140+
std::cout << std::endl;
141+
}
142+
};
143+
144+
#endif

0 commit comments

Comments
 (0)