/* Utility to test the performance of the solution */ #include #include #include #include #include #include #include #include #include #include static long long getnow() { struct timeval tv; gettimeofday (&tv,NULL); return tv.tv_sec*1000000L+tv.tv_usec; } #define _TLMP_dofork struct _F_dofork{ #define _F_dofork_process(x) void x process(int noproc, int &ret) virtual _F_dofork_process( )=0; }; static int dofork (_F_dofork &c, int nbfork) { int ret = 0; if (nbfork == 1){ c.process (0,ret); }else{ for (int i=0; i int main (int argc, char *argv[]) { glocal int nbtest = 1000; glocal int nbfork = 1; glocal const char *host = "localhost"; glocal const char *url = "/trunk/index.php"; glocal const char *ddosport = "10000"; glocal bool keepconnect = false; glocal int ret = -1; glocal.ret = (argc,argv); setarg (' ',"host","Target host for the test",glocal.host,false); setarg (' ',"nbtest","Number of repetition",glocal.nbtest,false); setarg (' ',"nbfork","Number of sub-process to use",glocal.nbfork,false); setarg (' ',"url","URL used for the tests",glocal.url,false); setarg (' ',"ddosport","Port for ddosproof",glocal.ddosport,false); setarg (' ',"keepconnect","Keep connection open with ddosproof",glocal.keepconnect,false); int ret = -1; if (argc != 1){ usage(); }else if (strcmp(argv[0],"testget")==0){ ret = (glocal.nbfork); long long start = getnow(); int i; for (i=0; i(glocal.host,"80",1); sendf ("GET %s\n\n",glocal.url); //printf ("line %s\n",line); if (strstr(line,"var work =")!=NULL) glocal.work = true; if (!glocal.work){ tlmp_error ("No work retrieved at iteration %d, exiting\n",i); ret = -1; break; } } long long end = getnow(); printf ("testget %lf get/s\n",i/((end-start)/1000000.0)); }else if (strcmp(argv[0],"testwork")==0){ ret = (glocal.nbfork); long long start = getnow(); glocal int count = 0; int i; for (i=0; i(glocal.host,glocal.ddosport,1); send ("getwork 127.0.0.1 -\n"); //printf ("line %s\n",line); if (strncmp(line,"201 ",4)==0){ glocal.work = true; glocal.count++; if (glocal.keepconnect){ if (glocal.count < glocal.nbtest){ send ("getwork 127.0.0.1 -\n"); }else{ end = true; } }else{ end = true; } }else if (isdigit(line[0])){ // some error end = true; } if (!glocal.work){ tlmp_error ("No work retrieved at iteration %d, exiting\n",i); ret = -1; break; } if (glocal.keepconnect) break; } long long end = getnow(); printf ("testwork %lf get/s\n",glocal.count/((end-start)/1000000.0)); }else{ usage(); } return ret; return glocal.ret; }