/* vraci system rc error kod */ static int bench(void) { int i,j,k; pid_t pid=0; FILE *f; /* check avaibility of target server */ i=Socket(proxyhost==NULL?host:proxyhost,proxyport); if(i<0) { fprintf(stderr,"\nConnect to server failed. Aborting benchmark.\n"); return 1; } close(i); /* create pipe */ if(pipe(mypipe)) { perror("pipe failed."); return 3; } /* not needed, since we have alarm() in childrens */ /* wait 4 next system clock tick */ /* cas=time(NULL); while(time(NULL)==cas) sched_yield(); */ /* fork childs */ for(i=0;i<clients;i++) { pid=fork(); if(pid <= (pid_t) 0) { /* child process or error*/ sleep(1); /* make childs faster */ break; } } if( pid< (pid_t) 0) { fprintf(stderr,"problems forking worker no. %d\n",i); perror("fork failed."); return 3; } if(pid== (pid_t) 0) { /* I am a child */ if(proxyhost==NULL) benchcore(host,proxyport,request); else benchcore(proxyhost,proxyport,request); /* write results to pipe */ f=fdopen(mypipe[1],"w"); if(f==NULL) { perror("open pipe for writing failed."); return 3; } /* fprintf(stderr,"Child - %d %d\n",speed,failed); */ fprintf(f,"%d %d %d\n",speed,failed,bytes); fclose(f); return 0; } else { f=fdopen(mypipe[0],"r"); if(f==NULL) { perror("open pipe for reading failed."); return 3; } setvbuf(f,NULL,_IONBF,0); speed=0; failed=0; bytes=0; while(1) { pid=fscanf(f,"%d %d %d",&i,&j,&k); if(pid<2) { fprintf(stderr,"Some of our childrens died.\n"); break; } speed+=i; failed+=j; bytes+=k; /* fprintf(stderr,"*Knock* %d %d read=%d\n",speed,failed,pid); */ if(--clients==0) break; } fclose(f); printf("\nSpeed=%d pages/min, %d bytes/sec.\nRequests: %d susceed, %d failed.\n", (int)((speed+failed)/(benchtime/60.0f)), (int)(bytes/(float)benchtime), speed, failed); } return i; }
/* vraci system rc error kod */ static int bench(void) { int i, j, k; pid_t pid = 0; FILE * f; /* check avaibility of target server */ i = Socket((proxyHost == NULL) ? host : proxyHost, proxyPort); if (i < 0) { fprintf(stderr,"\nConnect to server failed. Aborting benchmark.\n"); return 1; } close(i); /** * The pipe() function shall create a pipe and place two file descriptors, one each into the arguments fildes[0] and fildes[1], that refer to the open file descriptions for the read and write ends of the pipe. Their integer values shall be the two lowest available at the time of the pipe() call. The O_NONBLOCK and FD_CLOEXEC flags shall be clear on both file descriptors. (The fcntl() function can be used to set both these flags.) * Data can be written to the file descriptor fildes[1] and read from the file descriptor fildes[0]. A read on the file descriptor fildes[0] shall access data written to the file descriptor fildes[1] on a first-in-first-out basis. It is unspecified whether fildes[0] is also open for writing and whether fildes[1] is also open for reading. * A process has the pipe open for reading (correspondingly writing) if it has a file descriptor open that refers to the read end, fildes[0] (write end, fildes[1]). * Upon successful completion, pipe() shall mark for update the st_atime, st_ctime, and st_mtime fields of the pipe. */ if (pipe(mypipe)) { // create pipe perror("pipe failed."); return 3; } /* not needed, since we have alarm() in childrens */ /* wait 4 next system clock tick */ /* cas = time(NULL); while(time(NULL) == cas) { sched_yield(); } */ /* fork childs */ for(i = 0; i < clients; i++) { pid = fork(); if (pid <= (pid_t) 0) { /* child process or error */ sleep(1); /* make childs faster */ break; } } if (pid < (pid_t) 0) { // fork failure fprintf(stderr, "problems forking worker no. %d\n", i); perror("fork failed."); return 3; } if (pid == (pid_t) 0) { // Child Process if (proxyHost == NULL) { benchcore(host, proxyPort, request); } else { benchcore(proxyHost, proxyPort, request); } /* write results to pipe */ f = fdopen(mypipe[1], "w"); if (f == NULL) { perror("open pipe for writing failed."); return 3; } /* fprintf(stderr,"Child - %d %d\n",speed,failed); */ fprintf(f, "%d %d %d\n", speed, failed, bytes); fclose(f); return 0; } else { // Father Process f = fdopen(mypipe[0], "r"); if (f == NULL) { perror("open pipe for reading failed."); return 3; } setvbuf(f, NULL, _IONBF, 0); speed = 0; // total for reply failed = 0; bytes = 0; while(1) { pid = fscanf(f, "%d %d %d", &i, &j, &k); if (pid < 2) { fprintf(stderr, "Some of our childrens died.\n"); break; } speed += i; failed += j; bytes += k; /* fprintf(stderr, "*Knock* %d %d read=%d\n", speed, failed, pid); */ if (--clients == 0) { break; } } fclose(f); printf("\nSpeed=%d pages/min, %d bytes/sec.\nRequests: %d susceed, %d failed.\n", (int)((speed + failed) / (benchtime / 60.0f)), (int)(bytes / (float)benchtime), speed, failed ); } return i; }
/* vraci system rc error kod */ static int bench(void) { int i,j,k; pid_t pid = 0; FILE *f; if (pipe(mypipe)) { perror("pipe failed."); return 3; } /* fork childs */ for (i = 0; i < clients; ++i) { pid = fork(); if (pid == 0) { /* child */ sleep(1); break; } else if (pid == -1) { /* error */ fprintf(stderr, "child #%d fork failed(err: %d)\n", i, errno); } } if (pid == 0) { /* child */ curl_global_init(CURL_GLOBAL_DEFAULT); benchcore(); curl_global_cleanup(); /* write results to pipe */ f = fdopen(mypipe[1], "w"); if (f == NULL) { perror("open pipe for writing failed."); return 3; } fprintf(stderr, "Child #%d - %d %d\n", i, success, failed); fprintf(f, "%d %d %d\n", success, failed, bytes); fclose(f); return 0; } else { f = fdopen(mypipe[0], "r"); if (f == NULL) { perror("open pipe for reading failed."); return 3; } setvbuf(f, NULL, _IONBF, 0); success = 0; failed = 0; bytes = 0; while (true) { pid = fscanf(f, "%d %d %d", &i, &j, &k); if (pid < 3) { fprintf(stderr, "Some of our childrens died.\n"); break; } success += i; failed += j; bytes += k; if (--clients == 0) { break; } } fclose(f); fprintf(stderr, "Speed: %d qps, %d bytes/sec.\n" "Requests: %d susceed, %d failed.\n", (int)((success + failed) / (float)benchtime), (int)(bytes / (float)benchtime), success, failed); } return 0; }
/* vraci system rc error kod */ static int bench(void) { int i,j,k; pid_t pid=0; FILE *f; long runs, success, recv_byte, resp_time; /* check avaibility of target server */ i=Socket(proxyhost==NULL?host:proxyhost,proxyport); if(i<0) { fprintf(stderr,"\nConnect to server failed. Aborting benchmark.\n"); return 1; } close(i); /* create pipe */ if(pipe(mypipe)) { perror("pipe failed."); return 3; } /* not needed, since we have alarm() in childrens */ /* wait 4 next system clock tick */ /* cas=time(NULL); while(time(NULL)==cas) sched_yield(); */ /* fork childs */ for(i=0; i<clients; i++) { pid=fork(); if(pid <= (pid_t) 0) { /* child process or error*/ sleep(1); /* make childs faster */ break; } } if( pid< (pid_t) 0) { fprintf(stderr,"problems forking worker no. %d\n",i); perror("fork failed."); return 3; } if(pid== (pid_t) 0) { /* I am a child */ if(proxyhost==NULL) benchcore(host,proxyport,request); else benchcore(proxyhost,proxyport,request); return 0; } else { f=fdopen(mypipe[0],"r"); if(f==NULL) { perror("open pipe for reading failed."); return 3; } setvbuf(f,NULL,_IONBF,0); runs = 0; success = 0; recv_byte = 0; resp_time = 0; while(1) { pid=fscanf(f,"%d %d %d",&i,&j,&k); if(pid<2) { fprintf(stderr,"Some of our childrens died.\n"); break; } if (i < 0) { if(--clients==0) break; } else if (i < 2) { runs++; success += i; recv_byte += j; resp_time += k; } else { runs--; /* Correcting failed caused by signal*/ } } fclose(f); printf("\nSpeed=%d pages/sec, %d bytes/sec, Mean response time: %d\nRequests: %d runs, %d succeed, %d failed.\n", (int)((success * 1.0f)/(benchtime)), (int)(recv_byte/(float)benchtime), (int)(resp_time/(float)success), (int)runs, (int)success, (int)(runs - success)); } return i; }
/* vraci system rc error kod */ static int bench(void) { int i, j, k; pid_t pid = 0; FILE *f; /* check avaibility of target server */ i = Socket(NULL == proxyhost ? host : proxyhost, proxyport); if (i < 0) { fprintf(stderr, "\nConnect to server failed. Aborting benchmark.\n"); return 1; } close(i); /* create pipe */ if (pipe(mypipe)) { perror("pipe failed."); return 3; } /* fork childs */ for (i = 0; i < clients; i++) { pid = fork(); if (pid <= (pid_t)0) { // child process or error sleep(1); // make childs faster break; } } if (pid < (pid_t)0) { fprintf(stderr, "problems forking worker no. %d\n", i); perror("fork failed."); return 3; } if ((pid_t)0 == pid) { /* I am a child */ if (NULL == proxyhost) benchcore(host, proxyport, request); else benchcore(proxyhost, proxyport, request); /* write results to pipe */ f = fdopen(mypipe[1], "w"); if (NULL == f) { perror("open pipe for writing failed."); return 3; } fprintf(f, "%d %d %d\n", speed, failed, bytes); fclose(f); return 0; } else { /* I am parent */ f = fdopen(mypipe[0], "r"); if (NULL == f) { perror("open pipe for reading failed."); return 3; } setvbuf(f, NULL, _IONBF, 0); // setup no buffer speed = 0; failed = 0; bytes = 0; while (1) { pid = fscanf(f, "%d %d %d", &i, &j, &k); if (pid < 2) { fprintf(stderr, "Some of our childrens died.\n"); break; } speed += i; failed += j; bytes += k; if (0 == --clients) break; } fclose(f); printf("\nSpeed=%d pages/min, %d bytes/sec.\nRequests: %d susceed, %d failed.\n", (int)((speed + failed) / (benchtime / 60.0f)), (int)(bytes / (float)benchtime), speed, failed); } return i; }