From eb41488d018d808e8550327b28edb5a51acee8bb Mon Sep 17 00:00:00 2001 From: hellolintong Date: Mon, 25 Jan 2016 17:46:36 +0800 Subject: [PATCH 1/3] make all clients start at the same time --- webbench.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/webbench.c b/webbench.c index 8a5d305..a272a2c 100644 --- a/webbench.c +++ b/webbench.c @@ -24,6 +24,7 @@ #include #include +#define MAX_SIZE 1024*1024 /* values */ volatile int timerexpired=0; int speed=0; @@ -79,6 +80,10 @@ static void alarm_handler(int signal) timerexpired=1; } +static void sigusr1_handler(int signal) +{ +} + static void usage(void) { fprintf(stderr, @@ -296,6 +301,9 @@ static int bench(void) int i,j,k; pid_t pid=0; FILE *f; + int index=0; + struct sigaction sa; + pid_t pids[MAX_SIZE]; /* check avaibility of target server */ i=Socket(proxyhost==NULL?host:proxyhost,proxyport); @@ -325,10 +333,19 @@ static int bench(void) pid=fork(); if(pid <= (pid_t) 0) { - /* child process or error*/ - sleep(1); /* make childs faster */ break; } + /*record child pid*/ + pids[i]=pid; + sleep(1); + /*after fork last child, start all clients*/ + if(i == clients - 1) + { + for(index = 0; index <= i; ++index) + { + kill(pids[index], SIGUSR1); + } + } } if( pid< (pid_t) 0) @@ -338,9 +355,21 @@ static int bench(void) return 3; } + + /* I am a child */ if(pid== (pid_t) 0) { - /* I am a child */ + /*setup usr1 signal handler*/ + sa.sa_handler = sigusr1_handler; + sa.sa_flags = 0; + if(sigaction(SIGUSR1, &sa, NULL)) + { + exit(3); + } + + /*wait all clients ready*/ + pause(); + if(proxyhost==NULL) benchcore(host,proxyport,request); else From 98173a61e21ea96ead032c5128e10a3f44d90572 Mon Sep 17 00:00:00 2001 From: hellolintong Date: Mon, 25 Jan 2016 17:52:50 +0800 Subject: [PATCH 2/3] make all clients start at the same time --- webbench.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webbench.c b/webbench.c index a272a2c..4d50d55 100644 --- a/webbench.c +++ b/webbench.c @@ -24,7 +24,7 @@ #include #include -#define MAX_SIZE 1024*1024 +#define MAX_SIZE 3*1024*1024 /* values */ volatile int timerexpired=0; int speed=0; From 747c30089f03d97d14bb4dfb21a1e594213a9562 Mon Sep 17 00:00:00 2001 From: hellolintong Date: Mon, 25 Jan 2016 18:03:53 +0800 Subject: [PATCH 3/3] make all clients start at the same time --- webbench.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webbench.c b/webbench.c index 4d50d55..225c357 100644 --- a/webbench.c +++ b/webbench.c @@ -24,7 +24,7 @@ #include #include -#define MAX_SIZE 3*1024*1024 +#define MAX_SIZE 50*1024 /* values */ volatile int timerexpired=0; int speed=0; @@ -337,7 +337,7 @@ static int bench(void) } /*record child pid*/ pids[i]=pid; - sleep(1); + usleep(500); /*after fork last child, start all clients*/ if(i == clients - 1) {