Skip to content

Commit 2bcbd67

Browse files
tester
Signed-off-by: Akshat Sikarwar <[email protected]>
1 parent f4c2f46 commit 2bcbd67

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

foo/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.cache
2+
build
3+

foo/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
project(foo)
3+
find_package(ConfigureBbTarget QUIET)
4+
add_executable(foo foo.c)
5+
set_target_properties(foo PROPERTIES LINKER_LANGUAGE CXX)
6+
target_link_libraries(foo PRIVATE cdb2api)
7+
configure_bb_target(foo V2)

foo/foo.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <poll.h>
2+
#include <pthread.h>
3+
#include <signal.h>
4+
#include <stdio.h>
5+
#include <string.h>
6+
#include <sys/time.h>
7+
#include <unistd.h>
8+
9+
#include <cdb2api.h>
10+
11+
static char *dbname = "akdb";
12+
static char *tier = "default";
13+
static int flags;
14+
static int conns = 10;
15+
16+
static void *work(void *data)
17+
{
18+
cdb2_hndl_tp *dbs[conns];
19+
int rc, bad_open = 0;
20+
for (int i = 0; i < conns; ++i) {
21+
while ((rc = cdb2_open(&dbs[i], dbname, tier, flags)) != 0) {
22+
++bad_open;
23+
}
24+
}
25+
if (bad_open) {
26+
printf("cdb2_open retries:%d", bad_open);
27+
}
28+
while (1) {
29+
for (int i = 0; i < conns; ++i) {
30+
cdb2_hndl_tp *db = dbs[i];
31+
rc = cdb2_run_statement(db, "select value from generate_series(1, 100)");
32+
if (rc != 0) {
33+
continue;
34+
}
35+
while ((rc = cdb2_next_record(db)) == CDB2_OK)
36+
;
37+
if (rc != CDB2_OK_DONE) {
38+
fprintf(stderr, "cdb2_next_record rc:%d err:%s\n", rc, cdb2_errstr(db));
39+
}
40+
}
41+
}
42+
return NULL;
43+
}
44+
int main(int argc, char **argv)
45+
{
46+
int sigignore(int);
47+
sigignore(SIGPIPE);
48+
int thds;
49+
switch (argc) {
50+
case 5: tier = argv[4];
51+
case 4: dbname = argv[3];
52+
case 3: conns = atoi(argv[2]);
53+
case 2: thds = atoi(argv[1]);
54+
break;
55+
default:
56+
fprintf(stderr, "usage: foo <thds> <conns-per-thd> [dbname] [tier]\n");
57+
exit(1);
58+
}
59+
printf("thds:%d conns-per-thd:%d dbname:%s tier:%s\n", thds, conns, dbname, tier);
60+
if (strcmp(tier, "default") != 0) {
61+
flags |= CDB2_DIRECT_CPU;
62+
}
63+
pthread_t t[thds - 1];
64+
for (int i = 0; i < thds - 1; ++i) {
65+
if (pthread_create(&t[i], NULL, work, NULL) != 0) {
66+
perror("pthread_create");
67+
exit(2);
68+
}
69+
}
70+
work("main");
71+
void *ret;
72+
for (int i = 0; i < thds - 1; ++i) {
73+
pthread_join(t[i], &ret);
74+
}
75+
}

foo/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#export SSL_MODE=ALLOW
2+
for ((i = 0; i < 50; ++i)); do ./build/foo 50 500 akdb c2btda-pw-167 & done
3+
wait

foo/x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kill -9 $(pidof foo)

0 commit comments

Comments
 (0)