From 7dd7421018f5231a3f61ce552d485cefcd6edea8 Mon Sep 17 00:00:00 2001 From: gongxini Date: Wed, 26 Jul 2023 02:13:03 -0700 Subject: [PATCH 1/3] fix a bug in microbenchmark --- tests/update_heavy.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/update_heavy.cpp b/tests/update_heavy.cpp index c1810b5..baf34ff 100644 --- a/tests/update_heavy.cpp +++ b/tests/update_heavy.cpp @@ -8,7 +8,7 @@ #include "psandbox.h" #define NUMBER 10000000 -#define THREAD 20 +#define THREAD 10 void* do_handle_one_connection(void* arg) { int i,id; @@ -20,9 +20,10 @@ void* do_handle_one_connection(void* arg) { rule.priority = 0; rule.isolation_level = 50; rule.type = RELATIVE; + id = create_psandbox(rule); activate_psandbox(id); - if (j == 19) { + if (j == THREAD -1 ) { DBUG_TRACE(&start); } @@ -30,12 +31,12 @@ void* do_handle_one_connection(void* arg) { update_psandbox(key,PREPARE); update_psandbox(key,ENTER); update_psandbox(key,HOLD); - if(j != 19) { + if(j != THREAD -1) { usleep(100); } update_psandbox(key,UNHOLD); } - if (j == 19) { + if (j == THREAD - 1) { DBUG_TRACE(&stop); long time = time2ns(timeDiff(start,stop)); total_time += time; @@ -43,8 +44,8 @@ void* do_handle_one_connection(void* arg) { freeze_psandbox(id); - if (j == 19) { - printf("average time for update psandbox %lu ns\n", total_time/(4*NUMBER)); + if (j == THREAD - 1) { + printf("average time for heavy update psandbox %lu ns\n", total_time/(4*NUMBER)); } release_psandbox(id); @@ -63,9 +64,10 @@ int main() { for (i = 0; i < THREAD; i++) { pthread_create(&threads[i], NULL, do_handle_one_connection, &arg[i]); + usleep(100); } - pthread_join (threads[19], NULL); + pthread_join (threads[THREAD - 1], NULL); for (i = 0; i < THREAD; i++) { pthread_cancel(threads[i]); } From 1c9448c0ebac443a8e820bb7ec26846290454867 Mon Sep 17 00:00:00 2001 From: gongxini Date: Wed, 26 Jul 2023 02:53:13 -0700 Subject: [PATCH 2/3] fix a small issue --- tests/release_benchmark.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/release_benchmark.cpp b/tests/release_benchmark.cpp index c77d279..e190dc6 100644 --- a/tests/release_benchmark.cpp +++ b/tests/release_benchmark.cpp @@ -32,7 +32,7 @@ int main() { release_psandbox(ids[i]); DBUG_TRACE(&stop); time = time2ns(timeDiff(start,stop)); - total_time += time; + total_time += time/2; } for (i = 0; i < NUMBER; i++) { From c1712253335059835db22acfa8e5bde60c5ad72d Mon Sep 17 00:00:00 2001 From: gongxini Date: Wed, 26 Jul 2023 02:58:07 -0700 Subject: [PATCH 3/3] fix output --- tests/activate_benchmark.cpp | 2 +- tests/bind_benchmark.cpp | 2 +- tests/freeze_benchmark.cpp | 2 +- tests/get_pid.cpp | 2 +- tests/pthread_create.cpp | 2 +- tests/release_benchmark.cpp | 2 +- tests/unbind_benchmark.cpp | 2 +- tests/update_benchmark.cpp | 2 +- tests/update_heavy.cpp | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/activate_benchmark.cpp b/tests/activate_benchmark.cpp index fbeecb2..23980ca 100644 --- a/tests/activate_benchmark.cpp +++ b/tests/activate_benchmark.cpp @@ -45,7 +45,7 @@ int main() { } - printf("average time for activate psandbox %lu ns\n", total_time/NUMBER); + printf("activate, %lu\n", total_time/NUMBER); release_psandbox(id); return 0; } diff --git a/tests/bind_benchmark.cpp b/tests/bind_benchmark.cpp index 7cbf0d4..bfb0e34 100644 --- a/tests/bind_benchmark.cpp +++ b/tests/bind_benchmark.cpp @@ -48,7 +48,7 @@ int main() { freeze_psandbox(id); - printf("average time for bind psandbox %lu ns\n", total_time/NUMBER); + printf("bind, %lu\n", total_time/NUMBER); release_psandbox(id); return 0; } diff --git a/tests/freeze_benchmark.cpp b/tests/freeze_benchmark.cpp index 3bbb0f8..b46a15b 100644 --- a/tests/freeze_benchmark.cpp +++ b/tests/freeze_benchmark.cpp @@ -42,7 +42,7 @@ int main() { total_time -= time; } - printf("average time for freeze psandbox %lu ns\n", total_time/NUMBER); + printf("freeze, %lu\n", total_time/NUMBER); release_psandbox(id); return 0; } diff --git a/tests/get_pid.cpp b/tests/get_pid.cpp index 7901a60..89c09dc 100644 --- a/tests/get_pid.cpp +++ b/tests/get_pid.cpp @@ -24,6 +24,6 @@ int main() { - printf("average time for getpid %lu ns\n", total_time/NUMBER); + printf("getpid, %lu\n", total_time/NUMBER); return 0; } \ No newline at end of file diff --git a/tests/pthread_create.cpp b/tests/pthread_create.cpp index 0218a1f..69db5d7 100644 --- a/tests/pthread_create.cpp +++ b/tests/pthread_create.cpp @@ -27,6 +27,6 @@ int main() { long time = time2ns(timeDiff(start,stop)); total_time += time; - printf("average time for pthread create %lu ns\n", total_time/NUMBER); + printf("pthread_create, %lu\n", total_time/NUMBER); return 0; } \ No newline at end of file diff --git a/tests/release_benchmark.cpp b/tests/release_benchmark.cpp index e190dc6..28eb8c3 100644 --- a/tests/release_benchmark.cpp +++ b/tests/release_benchmark.cpp @@ -42,7 +42,7 @@ int main() { total_time -= time; } - printf("average time for release call is %lu ns\n", total_time/NUMBER); + printf("release, %lu\n", total_time/NUMBER); return 0; } diff --git a/tests/unbind_benchmark.cpp b/tests/unbind_benchmark.cpp index 0788809..bc68877 100644 --- a/tests/unbind_benchmark.cpp +++ b/tests/unbind_benchmark.cpp @@ -46,7 +46,7 @@ int main() { total_time -= time; } - printf("average time for unbind psandbox %lu ns\n", total_time/NUMBER); + printf("unbind, %lu\n", total_time/NUMBER); release_psandbox(id); return 0; } diff --git a/tests/update_benchmark.cpp b/tests/update_benchmark.cpp index 316095c..c803426 100644 --- a/tests/update_benchmark.cpp +++ b/tests/update_benchmark.cpp @@ -40,7 +40,7 @@ int main() { total_time += time; freeze_psandbox(id); - printf("average time for update psandbox %lu ns\n", total_time/(4*NUMBER)); + printf("update1 (no interf.), %lu\n", total_time/(4*NUMBER)); release_psandbox(id); return 0; } diff --git a/tests/update_heavy.cpp b/tests/update_heavy.cpp index baf34ff..454bbf1 100644 --- a/tests/update_heavy.cpp +++ b/tests/update_heavy.cpp @@ -45,7 +45,7 @@ void* do_handle_one_connection(void* arg) { freeze_psandbox(id); if (j == THREAD - 1) { - printf("average time for heavy update psandbox %lu ns\n", total_time/(4*NUMBER)); + printf("update2 (w/ interf.), %lu\n", total_time/(4*NUMBER)); } release_psandbox(id);