int do_reconnects(char *sql) { int m0, m1, m2 = 0, i; //sql="select table_name from all_tables"; m0 = m1 = os_mem_used(); //int do_smth=0; //fprintf(stderr," start reconnects with mem %d KB\n", m1/1024); for(i=1;i<100*1000;i++) { db_done(db); // clear prev if (!db_connect_string(db,cs)) { fprintf(stderr,"-reconnect failed on %d step err=%s\n",i,db->error); msleep(1000); continue; //return 0; } if (sql) { if (!db_select(db,sql)) { fprintf(stderr,"-select failed on step %d err=%s\n",i,db->error); return 0; } //while(db_fetch(db)); // Fetch all } m2 = os_mem_used(); printf(" .. reconnect: %d mem_used: %d KB delta= %d Bytes \r",i,m2/1024, (m2-m1)); if (i%100==0) { m1=m2; printf("\n"); } } fprintf(stderr,"+%d reconnects done, leak: %d\n",i, (m2-m0)); return 0; }
int do_stress_fetch(char *sql) { int m0, m1, m2 = 0, i,p1,p2; time_t t1,t2; m0 = m1 = os_mem_used(); time(&TimeNow); t1=t2 = TimeNow; p1=p2=0; //int do_smth=0; fprintf(stderr," start stress_fetch with mem %d KB, SQL:%s\n", m1/1024,sql); for(i=0;i<100*10000;i++) { int skip; time(&TimeNow); if (!db_select(db,sql)) { fprintf(stderr,"-select failed on step %d err=%s\n",i,db->error); return 0; } p2++; while(db_fetch(db)) ; //p1++; // Fetch all m2 = os_mem_used(); t2 = TimeNow; skip = t2!=t1; // New Second if (skip || (i%100 ==0)) printf(" .. stress_fetch: %d mem_used: %d KB delta= %d Bytes time=%d fetched:%d \r",i,m2/1024, (m2-m1), (int)(t2-t1),(p2-p1)); if (skip) { m1=m2; t1 = t2; p1=p2; printf("\n"); } } fprintf(stderr,"+%d stress fetch done, leak: %d\n",i, (m2-m0)); return 0; }
int onHttpStat(Socket *sock, vssHttp *req, SocketMap *map) { // Генерация статистики по серверу char buf[1024]; httpSrv *srv = sock->pool; strSetLength(&srv->buf,0); // ClearResulted sprintf(buf,"{clients:%d,connects:%d,requests:%d,mem:%d,serverTime:'%s',pps:%d}",arrLength(srv->srv.sock)-1, srv->srv.connects, srv->srv.requests, os_mem_used(), szTimeNow, (srv->readLimit.pValue+srv->readLimit.ppValue)/2); SocketPrintHttp(sock,req,"%s",buf); // Flash Results as http return 1; // OK - generated }
int onTestDone(httpCmd *cmd) { // DoneTestCommand httpClient *cli = cmd->cli; Counter *c = cli->sock.readPacket; if (ReplayCode) { // Check Replay int code=0; if (cli->res.U.len>0) code=atoi(cli->res.U.data); // GetACode if (code!=ReplayCode) { CLOG(cli,0,"WrongServerAnswer: %d, expect: %d\n",code,ReplayCode); aborted=1; } } if(0) printf("CommandDone n=%d readPacket=%d total=%d os_mem=%d!\n",cmd->n, c?c->pValue:0,c?c->Total:0,os_mem_used()); SendTestPack(cli); return 0; }
int httpTestMain(int npar,char **par) { int i,sock=1,pack=1,logLevel=1; int MaxPacket = 1000000; char *url,*Proxy=""; net_init(); signal(SIGINT,sig_done); if (npar<2) { httpTestHelp(); return 1; // Error } char *cmd=par[1]; if (strncmp(cmd,"-p",2)==0) return MicroHttpMain(npar,par); if (strncmp(cmd,"http://",7)==0) cmd+=7; // RemoveHTTP url=cmd; static Counter read={100000}; // ReadLimit for(i=2;i<npar;i++) { // Decode Optional char *cmd=par[i]; int ok=1; if (*cmd=='-') { cmd++; ok=1; if (*cmd=='s') sscanf(cmd+1,"%d",&sock); //else if (*cmd=='S') sscanf(cmd+1,"%d",&sleepTime); else if (*cmd=='p') sscanf(cmd+1,"%d",&pack); else if (*cmd=='d') sscanf(cmd+1,"%d",&logLevel); else if (*cmd=='M') sscanf(cmd+1,"%d",&MaxPacket); else if (*cmd=='P') Proxy=cmd+1; else if (*cmd=='R') sscanf(cmd+1,"%d",&ReplayCode); else if (*cmd=='r') sscanf(cmd+1,"%d",&read.Limit); else ok=0; } if (!ok) { printf("httpTest - unknownParameter: '%s'\n",cmd); httpTestHelp(); return 2; } } //thread_create(httpClientTest1); httpClient *Cli[sock]; logger *log; log = logOpen("httpTest.log"); Logf("httpStressTest: {logLevel:%d,Sockets:%d,Commands:%d,MaxPacket:%d,URL:'%s',Proxy='%s'\n", logLevel,sock,pack,MaxPacket,url,Proxy); for(i=0;i<sock;i++) { httpClient *c; Cli[i]= c = httpClientNew(); c->log = log; c->logLevel = logLevel; snprintf(c->name,sizeof(c->name),"[%d]%s",i,url); if (!httpClientInit(c,url,Proxy)) return 0; c->onDisconnect = onTestDisconnect; c->sock.readPacket = &read; //c->sock->readPacket.Limit = readPackLimit; //printf("Begin?\n"); int j; for(j=0;j<pack;j++) SendTestPack(c); // SendTestPacks //printf("Done?\n"); } TimeUpdate(); time_t Started=TimeNow; printf("StressStarted: %s, mem=%d\n",szTimeNow,os_mem_used()); while(!aborted) { int c=0; TimeUpdate(); for(i=0;i<sock;i++) if (httpClientRun(Cli[i])) c++; if (read.Total>=MaxPacket) { Logf("MaxPacket %d received\n", MaxPacket); break; } //printf("Run=%d\n",c); RunSleep(c); if (NeedReport()) Reportf("Time:'%s',Packet_Per_Second:%5d,Total:%5d,os_mem:%d",szTimeNow, (read.pValue+read.ppValue)/2,read.Total,os_mem_used()); //if (!c) msleep(1); } TimeUpdate(); int Dur=TimeNow-Started,PPS=0; if (Dur) PPS=read.Total/Dur; printf("StressStopped:'%s',Dur:%d,PPS:%d,Total:%5d,os_mem:%d",szTimeNow,Dur,PPS,read.Total,os_mem_used()); return 0; //return httpClientTest1(logLevel,sock,pack,url); // Слушай - а у меня в микрохттп нету ли такого - что я останавливаюсь??? }