void getAllLocks(char c, int *lockArr, int lockType, int prio, int setupTime, int holdTime){ int i,j=0,retval; while(1) { sleep(setupTime); for(i=0; i<NLOCKS; i++) { // printf("%c %d %d %d %d %d\n",c,lockArr[0],lockArr[1],lockArr[2],lockArr[3],lockArr[4]); retval = lock(lockArr[i], lockType, prio); if(retval != OK) { kprintf("StressTest op-%d: %c%c%c%c%c Lock %d failed : %d\n",lockType,c,c,c,c,c, lockArr[i], retval); return; } } // kprintf("%c%c%c%c%c\n",c,c,c,c,c); for(i=0; i<holdTime*10; i++) { kprintf("StressTest op-%d: %c%c%c%c%c\n",lockType,c,c,c,c,c); sleep1000(50); } for(i=0; i<NLOCKS; i+=2 ) { retval = releaseall(2, lockArr[i], lockArr[i+1]); if(retval != OK) { kprintf("StressTest op-%d: %c%c%c%c%c Release %d failed : %d\n",lockType,c,c,c,c,c,lockArr[i],retval); return; } } j++; if(j == 10) break; } }
void randomSleep() /* Put in a random sleep time of 0-5 seconds to help * prevent overloading hub with jobDone messages all * at once, and file server with file open requests * all at once. */ { if (randomDelay > 0) { int sleepTime = randomNumber%randomDelay; sleep1000(sleepTime); } }
void reader(char c, int lck, int prio, int setupTime, int holdTime){ int i,j=0,retval; for(j=0; j<5; j++) { sleep(setupTime); if(OK != (retval = lock(lck,READ,prio) ) ) { kprintf("Reader: %c%c%c Could not lock %d. Return: %d !\n",c,c,c,lck,retval); return; } for(i=0; i<holdTime*10; i++) { kprintf("Reader: %c%c%c%c%c%d\n",c,c,c,c,c,j); sleep1000(50); } if(OK != (retval = releaseall(1,lck) ) ) { kprintf("Reader: %c%c%c Could not release lock %d. Return: %d !\n",c,c,c,lck,retval); return; } } }
void doQuery(char *database, char *table, char *chrom, int start, int end) /* doQuery */ { struct sqlConnection *conn = NULL; struct sqlResult *sr = NULL; char *empty = NULL; int rowOffset = 0; // char **row; // int count = 0; long startTime = 0; long deltaTime = 0; int i; conn = sqlConnect(database); // hSetDb(database); for (i = 0; i < iterations; i++) { startTime = clock1000(); sr = hRangeQuery(conn, table, chrom, start, end, empty, &rowOffset); deltaTime = clock1000() - startTime; printf("time for hRangeQuery = %0.3fs\n", ((double)deltaTime)/1000.0); end++; sqlFreeResult(&sr); sleep1000(500); } // startTime = clock1000(); // while ((row = sqlNextRow(sr)) != NULL) // { // count++; // } // printf("got %d rows\n", count); // sqlFreeResult(&sr); // deltaTime = clock1000() - startTime; // printf("time for sqlFreeResult = %0.3fs\n", ((double)deltaTime)/1000.0); // sqlDisconnect(&conn); }
void submitUrl(struct sqlConnection *conn) /* Submit validated manifest if it is not already in process. Show * progress once it is in progress. */ { /* Parse email and URL out of CGI vars. Do a tiny bit of error checking. */ char *url = trimSpaces(cgiString("url")); if (!stringIn("://", url)) errAbort("%s doesn't seem to be a valid URL, no '://'", url); /* Do some reality checks that email and URL actually exist. */ edwMustGetUserFromEmail(conn, userEmail); int sd = netUrlMustOpenPastHeader(url); close(sd); edwAddSubmitJob(conn, userEmail, url, cgiBoolean("update")); /* Give the system a half second to react and then put up status info about submission */ sleep1000(1000); monitorSubmission(conn); }
struct htmlPage *quickSubmit(struct htmlPage *basePage, char *org, char *db, char *group, char *track, char *table, char *testName, char *button, char *buttonVal) /* Submit page and record info. Return NULL if a problem. */ { struct tablesTest *test; struct qaStatus *qs; struct htmlPage *page; // don't get ahead of the botDelay sleep1000(5000); verbose(2, "quickSubmit(%p, %s, %s, %s, %s, %s, %s, %s, %s)\n", basePage, naForNull(org), naForNull(db), naForNull(group), naForNull(track), naForNull(table), naForNull(testName), naForNull(button), naForNull(buttonVal)); if (basePage != NULL) { if (db != NULL) htmlPageSetVar(basePage, NULL, "db", db); if (org != NULL) htmlPageSetVar(basePage, NULL, "org", org); if (group != NULL) htmlPageSetVar(basePage, NULL, hgtaGroup, group); if (track != NULL) htmlPageSetVar(basePage, NULL, hgtaTrack, track); if (table != NULL) htmlPageSetVar(basePage, NULL, hgtaTable, table); qs = qaPageFromForm(basePage, basePage->forms, button, buttonVal, &page); /* if (page->forms != NULL) htmlFormPrint(page->forms, stdout); */ test = tablesTestNew(qs, testName, org, db, group, track, table); } return page; }
void botDelayCgi(char *host, int port) /* Connect with bottleneck server and sleep the * amount it suggests for IP address calling CGI script. */ { int millis; char *ip = getenv("REMOTE_ADDR"); if (ip != NULL) { char *botCheckString = getBotCheckString(ip); millis = botDelayTime(host, port, botCheckString); freeMem(botCheckString); if (millis > 0) { if (millis > 10000) { if (millis > 20000) botTerminateMessage(ip, millis); else botDelayMessage(ip, millis); } sleep1000(millis); } } }
void cartSimulate(char *host, char *user, char *password, char *database) /* Simulate action of various UCSC Genome Browser CGIs on cart. */ { /* Figure out size of tables. */ struct sqlConnection *conn = sqlConnectRemote(host, user, password, database); int userDbSize = sqlQuickNum(conn, "NOSQLINJ select count(*) from userDb"); if (userDbSize == 0) errAbort("%s.%s table is empty", database, userTable); int maxSampleSize = 1024*1024; int sampleSize = min(userDbSize, maxSampleSize); verbose(2, "# userDb has %d rows, sampling %d\n" , userDbSize, sampleSize); /* Get sample of user id's. */ int *userIds = getSomeInts(conn, "userDb", "id", sampleSize); /* Get userCount random indexes. */ int *randomIxArray, ix; AllocArray(randomIxArray, userCount); verbose(2, "random user ix:\n"); for (ix=0; ix<userCount; ++ix) { randomIxArray[ix] = rand() % sampleSize; verbose(2, "%d ", randomIxArray[ix]); } verbose(2, "\n"); sqlDisconnect(&conn); int iteration = 0; for (;;) { for (ix = 0; ix < userCount; ++ix) { int randomIx = rand()%sampleSize; boolean doNew = randomBitFromProb(newRatio); long startTime = clock1000(); struct sqlConnection *conn = sqlConnectRemote(host, user, password, database); long connectTime = clock1000(); struct dyString *contents = fakeCart(randomFakeSize()); char *userContents = NULL; int userId = userIds[randomIx]; if (doNew) userId = userIds[randomIx] = dummyInsert(conn, userTable); int userUseCount = dummyQuery(conn, userTable, userId, &userContents); long userReadTime = clock1000(); sleep1000(cgiDelay); long cgiSleepTime = clock1000(); updateOne(conn, userTable, contents->string, userId, userUseCount); long userWriteTime = clock1000(); sqlDisconnect(&conn); long disconnectTime = clock1000(); printf("%ld total, %ld oldSize, %ld newSize, %ld connect, %ld userRead, %ld userWrite, %ld disconnect\n", disconnectTime - startTime - (cgiSleepTime - userReadTime), (long) strlen(userContents), (long)contents->stringSize, connectTime - startTime, userReadTime - connectTime, userWriteTime - cgiSleepTime, disconnectTime - userWriteTime ); dyStringFree(&contents); freez(&userContents); sleep1000(hitDelay); if (++iteration >= iterations) return; } } errAbort("cartSimulate(%s %s %s %s) not implemented", host, user, password, database); }
void cartSimNoInsert(char *host, char *user, char *password, char *database, char *milliDelayString, char *iterationString) /* cartSimNoInsert - simulates N users accessing cart at regular intervals * where cart data is read and then written back unchanged */ { int milliDelay = sqlUnsigned(milliDelayString); int iterations = sqlUnsigned(iterationString); /* Figure out size of tables. */ struct sqlConnection *conn = sqlConnectRemote(host, user, password, database); int userDbSize = sqlQuickNum(conn, "NOSQLINJ select count(*) from userDb"); int sessionDbSize = sqlQuickNum(conn, "NOSQLINJ select count(*) from sessionDb"); int sampleSize = min(userDbSize, sessionDbSize); int maxSampleSize = 8*1024; sampleSize = min(sampleSize, maxSampleSize); verbose(2, "# userDb has %d rows, sessionDb has %d rows, sampling %d\n" , userDbSize, sessionDbSize, sampleSize); /* Get sample of user id's. */ int *userIds = getSomeInts(conn, "userDb", "id", sampleSize); int *sessionIds = getSomeInts(conn, "sessionDb", "id", sampleSize); /* Get userCount random indexes. */ int *randomIxArray, ix; AllocArray(randomIxArray, userCount); verbose(2, "random user ix:\n"); for (ix=0; ix<userCount; ++ix) { randomIxArray[ix] = rand() % sampleSize; verbose(2, "%d ", randomIxArray[ix]); } verbose(2, "\n"); sqlDisconnect(&conn); int iteration = 0; int querySize = 1024*1024*16; char *query = needLargeMem(querySize); for (;;) { for (ix = 0; ix < userCount; ++ix) { int randomIx = randomIxArray[ix]; long startTime = clock1000(); struct sqlConnection *conn = sqlConnectRemote(host, user, password, database); long connectTime = clock1000(); sqlSafef(query, querySize, "select contents from userDb where id=%d", userIds[randomIx]); char *userContents = sqlQuickString(conn, query); long userReadTime = clock1000(); sqlSafef(query, querySize, "select contents from sessionDb where id=%d", sessionIds[randomIx]); char *sessionContents = sqlQuickString(conn, query); long sessionReadTime = clock1000(); sqlSafef(query, querySize, "update userDb set contents='%s' where id=%d", userContents, userIds[randomIx]); if (!readOnly) sqlUpdate(conn, query); long userWriteTime = clock1000(); sqlSafef(query, querySize, "update sessionDb set contents='%s' where id=%d", sessionContents, sessionIds[randomIx]); if (!readOnly) sqlUpdate(conn, query); long sessionWriteTime = clock1000(); sqlDisconnect(&conn); long disconnectTime = clock1000(); printf("%ld total, %ld size, %ld connect, %ld userRead, %ld sessionRead, %ld userWrite, %ld sessionWrite\n", disconnectTime - startTime, (long) strlen(userContents) + strlen(sessionContents), connectTime - startTime, userReadTime - connectTime, sessionReadTime - userReadTime, userWriteTime - sessionReadTime, sessionWriteTime - userReadTime); freez(&userContents); freez(&sessionContents); sleep1000(milliDelay); if (++iteration >= iterations) return; } } }