benchmark
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/cfgmgr.h>
|
||||
#include <isc/time.h>
|
||||
|
||||
#include "../../lib/isc/cfgmgr.c"
|
||||
|
||||
@@ -28,6 +29,128 @@
|
||||
|
||||
#define TEST_DBPATH "/tmp/named-cfgmgr-lmdb"
|
||||
|
||||
static void *
|
||||
writer(void *arg) {
|
||||
uint64_t *duration = arg;
|
||||
size_t i = 0;
|
||||
isc_cfgmgr_val_t v = { .type = ISC_CFGMGR_UINT32 };
|
||||
|
||||
isc_time_t start = isc_time_now_hires();
|
||||
while (i < 1000) {
|
||||
if (isc_cfgmgr_openrw("foo") == ISC_R_NOTFOUND) {
|
||||
REQUIRE(isc_cfgmgr_newclause("foo") == ISC_R_SUCCESS);
|
||||
}
|
||||
v.uint32 = (uint32_t)i;
|
||||
REQUIRE(isc_cfgmgr_setval("foo", &v) == ISC_R_SUCCESS);
|
||||
(void)isc_cfgmgr_close();
|
||||
i++;
|
||||
}
|
||||
isc_time_t finish = isc_time_now_hires();
|
||||
|
||||
*duration = isc_time_microdiff(&finish, &start);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *
|
||||
reader(void *arg) {
|
||||
uint64_t *duration = arg;
|
||||
size_t i = 0;
|
||||
isc_cfgmgr_val_t v;
|
||||
|
||||
isc_time_t start = isc_time_now_hires();
|
||||
while (i < 1000) {
|
||||
(void)isc_cfgmgr_open("foo");
|
||||
REQUIRE(isc_cfgmgr_getval("foo", &v) == ISC_R_SUCCESS);
|
||||
(void)isc_cfgmgr_close();
|
||||
i++;
|
||||
}
|
||||
isc_time_t finish = isc_time_now_hires();
|
||||
|
||||
*duration = isc_time_microdiff(&finish, &start);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ISC_RUN_TEST_IMPL(cfgmgr_benchmark) {
|
||||
size_t len = 32;
|
||||
pthread_t threads[len];
|
||||
uint64_t microsecs[len];
|
||||
|
||||
isc_cfgmgr_init(mctx, TEST_DBPATH);
|
||||
|
||||
uint64_t total_read = 0;
|
||||
uint64_t total_write = 0;
|
||||
|
||||
writer(&total_write);
|
||||
reader(&total_read);
|
||||
printf("sequential writes and read\n");
|
||||
printf("avg write %f ms\n", (double)total_write / 1000000.0);
|
||||
printf("avg read %f ms\n", (double)total_read / 1000000.0);
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (i == 10 || i == 20 || i == 30) {
|
||||
REQUIRE(pthread_create(&threads[i], 0, writer,
|
||||
µsecs[i]) == 0);
|
||||
} else {
|
||||
REQUIRE(pthread_create(&threads[i], 0, reader,
|
||||
µsecs[i]) == 0);
|
||||
}
|
||||
}
|
||||
total_read = 0;
|
||||
total_write = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
REQUIRE(pthread_join(threads[i], NULL) == 0);
|
||||
if (i == 10 || i == 20 || i == 30) {
|
||||
total_write += microsecs[i];
|
||||
} else {
|
||||
total_read += microsecs[i];
|
||||
}
|
||||
}
|
||||
printf("concurrent 29 readers and 3 writers\n");
|
||||
printf("avg write %f ms\n", (double)total_write / 1000000.0);
|
||||
printf("avg read %f ms\n", (double)total_read / 1000000.0);
|
||||
|
||||
len = 8;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (i == 2 || i == 4) {
|
||||
REQUIRE(pthread_create(&threads[i], 0, writer,
|
||||
µsecs[i]) == 0);
|
||||
} else {
|
||||
REQUIRE(pthread_create(&threads[i], 0, reader,
|
||||
µsecs[i]) == 0);
|
||||
}
|
||||
}
|
||||
total_read = 0;
|
||||
total_write = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
REQUIRE(pthread_join(threads[i], NULL) == 0);
|
||||
if (i == 2 || i == 4) {
|
||||
total_write += microsecs[i];
|
||||
} else {
|
||||
total_read += microsecs[i];
|
||||
}
|
||||
}
|
||||
printf("concurrent 6 readers and 2 writers\n");
|
||||
printf("avg write %f ms\n", (double)total_write / 1000000.0);
|
||||
printf("avg read %f ms\n", (double)total_read / 1000000.0);
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
REQUIRE(pthread_create(&threads[i], 0, reader,
|
||||
µsecs[i]) == 0);
|
||||
}
|
||||
total_read = 0;
|
||||
total_write = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
REQUIRE(pthread_join(threads[i], NULL) == 0);
|
||||
total_read += microsecs[i];
|
||||
}
|
||||
printf("concurrent 8 readers and 0 writer\n");
|
||||
printf("avg write %f ms\n", (double)total_write / 1000000.0);
|
||||
printf("avg read %f ms\n", (double)total_read / 1000000.0);
|
||||
|
||||
isc_cfgmgr_deinit();
|
||||
}
|
||||
|
||||
ISC_RUN_TEST_IMPL(isc_cfgmgr_assertions) {
|
||||
isc_cfgmgr_val_t dummyval;
|
||||
|
||||
@@ -1210,15 +1333,16 @@ ISC_RUN_TEST_IMPL(isc_cfgmgr_threads) {
|
||||
}
|
||||
|
||||
ISC_TEST_LIST_START
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_assertions)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_rw)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_override)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_rw_string)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_list)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_delete)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_repeatable_clauses)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_nested_clauses)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_threads)
|
||||
ISC_TEST_ENTRY(isc_cfgmgr_parseid)
|
||||
ISC_TEST_ENTRY(cfgmgr_benchmark)
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_assertions) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_rw) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_override) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_rw_string) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_list) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_delete) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_repeatable_clauses) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_nested_clauses) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_threads) */
|
||||
/* ISC_TEST_ENTRY(isc_cfgmgr_parseid) */
|
||||
ISC_TEST_LIST_END
|
||||
ISC_TEST_MAIN
|
||||
|
||||
Reference in New Issue
Block a user