From b7cbf73ce3da48f182019795aeb4e708f4678deb Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Sat, 5 Dec 2020 17:33:41 +0000 Subject: [PATCH] add benchmark mode --- README.md | 5 +++- client.c | 78 +++++++++++++++++++++++++++++++++++++++++------------- p-client.c | 1 - server.c | 1 - 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 2267855..3abe2be 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,16 @@ To build source, you should install `build-essential`. Usage: ```bash ./server [OPTION]... -./client SERVERNAME PORT FILENAME +./client SERVERNAME PORT [option] [FILENAME]... ``` Server OPTION and arguments: - `-p port` :set to port binding. couldn't set to 0 - `-h` :print help message. +Client option and arguments: +- `-b` :benchmark mode + Available macro: For server diff --git a/client.c b/client.c index 47d03f5..d19e206 100644 --- a/client.c +++ b/client.c @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include "socket_wrapper.h" #ifdef USE_SENDFILE @@ -169,24 +172,33 @@ int main(int argc, const char *argv[]){ const char * filename; const char * server_name; in_port_t server_port = 0; + int arg_filename_start = 3; int sock, err; - if (argc != 4){ - fprintf(stderr,"USAUE: %s SERVERNAME PORT FILENAME\n",argv[0]); + int retval = 0; + bool benchmode = false; + + clock_t clock_sum = 0; + clock_t begin_sclock; + clock_t begin_uclock; + + int op_count = 0; + if (argc < 4){ + fprintf(stderr,"USAUE: %s SERVERNAME PORT [Option]... [FILENAME]...\n",argv[0]); return 1; } server_name = argv[1]; server_port = atoi(argv[2]); - filename = argv[3]; - if (server_port == 0) - { + if (strcmp("-b",argv[arg_filename_start])==0 + ||strcmp("--benchmark",argv[arg_filename_start])==0){ + arg_filename_start++; + benchmode = true; + } + + if (server_port == 0){ fprintf(stderr,"port invalid"); return 1; } - sock = socket(AF_INET,SOCK_STREAM,0); - if(sock < 0){ - perror("sock create fail"); - return 1; - } + err = getsockaddrbyname(AF_INET,SOCK_STREAM,0,server_name,(struct sockaddr *)&addr); if (err != 0){ int check; @@ -196,21 +208,49 @@ int main(int argc, const char *argv[]){ assert(check != -1); if (check == 0){ fprintf(stderr,"parsing fail : invaild format\n"); - close(sock); return 1; } } addr.sin_family = AF_INET; addr.sin_port = htons(server_port); - if(connect(sock,(struct sockaddr *)&addr,sizeof(addr)) < 0){ - perror("connect failed"); - return 1; + + if (benchmode){ + struct tms t; + times(&t); + begin_sclock = t.tms_stime; + begin_uclock = t.tms_utime; } - if(sendReadOp(sock,filename) == 0){ - int ret = recvData(sock,filename); + while (arg_filename_start < argc){ + filename = argv[arg_filename_start++]; + sock = socket(AF_INET,SOCK_STREAM,0); + if(sock < 0){ + perror("sock create fail"); + return 1; + } + + if(connect(sock,(struct sockaddr *)&addr,sizeof(addr)) < 0){ + perror("connect failed"); + return 1; + } + if(sendReadOp(sock,filename) == 0){ + int ret = recvData(sock,filename); + if (ret < 0){ + fprintf(stderr,"%d",ret); + } + retval += ret; + } close(sock); - return ret; + op_count++; } - close(sock); - return 0; + if (benchmode){ + struct tms t; + times(&t); + clock_sum += t.tms_stime - begin_sclock; + clock_sum += t.tms_utime - begin_uclock; + } + if (benchmode){ + fprintf(stdout,"operation: %lf ticks/op\n",((double)clock_sum)/((double)op_count)); + } + + return retval; } \ No newline at end of file diff --git a/p-client.c b/p-client.c index d36f3e6..47d03f5 100644 --- a/p-client.c +++ b/p-client.c @@ -12,7 +12,6 @@ #include #include #include - #include "socket_wrapper.h" #ifdef USE_SENDFILE diff --git a/server.c b/server.c index 74e58d6..b162146 100644 --- a/server.c +++ b/server.c @@ -288,7 +288,6 @@ void * worker_proc(void * data){ } } - static pthread_t worker_threads[MAX_THREAD_NUMBER]; static int sock;