home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
TP1.ZIP
/
BENCHW.C
< prev
next >
Wrap
Text File
|
1989-06-29
|
16KB
|
600 lines
/***************************************************************************/
/* Copyright (C) 1989 Microsoft Corporation */
/* Copyright (C) 1989 Sybase, Inc. */
/* Program: BENCHW.C */
/* Description: The program acts as client for the TP/1 benchmark. */
/* BENCHW reads mail sent by the controlling program, */
/* SQLQUEEN. SQLQUEEN tells BENCHW to connect to the */
/* server under test and to a tracking server to log the */
/* test results. BENCHW then waits for a mail message */
/* to start testing. After the tests are completed, */
/* BENCHW logs the test results to the tracking server. */
/* */
/* Inputs: Workstation Number, Computer Description */
/* */
/* Created: Trish Millines 1/24/89 */
/* Modified: Bob Muglia 4/6/89 */
/* */
/***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <types.h>
#include <fcntl.h>
#include <stat.h>
#include <share.h>
#include <io.h>
#include <timeb.h>
#include <sqlfront.h>
#include <sqldb.h>
#include <netcons.h>
#include <neterr.h>
#include <mailslot.h>
#include <os2def.h>
#include <bse.h>
#include "bench.h"
#define MAILPATH "\\mailslot\\sqlbench\\"
/* */
/* Forward declaration of SQL Server error handlers */
/* */
int bench_err_handler();
int bench_msg_handler();
/* */
/* SETUP and CONFIGURATION structures */
/* */
struct bench_data bd; /* Program setup structure */
DBPROCESS far *dbproc, *track_proc;
DBINT CURR_ERROR;
int PRINT_ERRORS;
/* */
/* EXECUTION STATISTICS structures */
/* */
struct statistics stats;
FILE *outptr;
main(argc,argv)
int argc;
char **argv;
{
char message[100];
char mailbox[50];
char buffout[80];
char code;
int mailtemp, i;
unsigned mailhandle;
unsigned short messagebytes, nextbytes, priority;
DBINT dummy_seed; /* truly randomizes the function */
/* */
/* Initialize */
/* */
dummy_seed = get_random(500l); /* just seed the generator */
mailtemp = 1;
code = READY;
/* */
/* Call routine to parse the arguments */
/* */
if (Check_arguments(argc,argv) == FAIL)
exit(-1);
/* */
/* Open the status log */
/* */
if((outptr = fopen("sqlstat.log","w")) == NULL)
{
printf("\nBENCH ERROR: Can't open sqlstat.log");
exit(FAIL);
}
/* */
/* Install the SQL Server error handlers */
/* */
dberrhandle(bench_err_handler); /* install DBLIB error handler */
dbmsghandle(bench_msg_handler); /* install DBLIB message handler */
/* */
/* Create a mailbox to receive information from SQLQUEEN */
/* */
do
{
sprintf(mailbox,"%s%d",MAILPATH,mailtemp);
mailtemp++;
}
while (DosMakeMailslot(mailbox, 100, 600, &mailhandle) != NERR_Success);
/* */
/* Loop to allow multiple tests in sequence */
/* */
while (code != QUIT)
{
printf("\nWaiting for server information");
PRINT_ERRORS = TRUE;
/* */
/* Wait for a mail message indicating it's time to start testing */
/* */
DosReadMailslot(mailhandle, message, &messagebytes,
&nextbytes, &priority, (long) -1);
code = message[0];
if (code != GET_SERVERS)
{
printf("\nBENCH ERROR: Incorrect code, expected GET_SERVERS, received: %c",
code);
exit(FAIL);
}
/* */
/* Parse the mail message, connect to servers */
/* */
i = 2;
i = parsebuff(message,i,',',bd.test_server);
i = parsebuff(message,i,',',bd.track_server);
i = parsebuff(message,i,',',bd.database);
Connect_to_servers();
/* */
/* Get ready to test - Wait for mail to start */
/* */
DosReadMailslot(mailhandle, message, &messagebytes,
&nextbytes, &priority, (long) -1);
code = message[0];
if (code != ALL_START)
{
printf("\nBENCH ERROR: Incorrect code, expected ALL_START, received: %c",
code);
exit(FAIL);
}
i = 2;
i = parsebuff(message,i,',',buffout);
bd.seconds = atol(buffout);
i = parsebuff(message,i,',',buffout);
bd.max_accts = atol(buffout);
i = parsebuff(message,i,',',buffout);
bd.max_teller = atol(buffout);
i = parsebuff(message,i,',',buffout);
bd.max_branch = atol(buffout);
/* */
/* Go! */
/* */
printf("\nTesting for %ld seconds",bd.seconds);
Run_tp1();
/* */
/* Finish up the test */
/* */
PRINT_ERRORS = FALSE;
Update_bench_stats();
dbexit();
}
exit(0);
}
/***************************************************************************/
/* FUNCTION TO PARSE THE ARGUMENTS */
/***************************************************************************/
int Check_arguments(argc,argv)
int argc;
char **argv;
{
/* */
/* See if all the necessary arguments are there */
/* */
if(argc != 2)
{
system("cls");
printf("\nUSAGE: benchw Computer_identifier");
printf("\n\nEXAMPLE: benchw Compaq-386/20");
return(FAIL);
}
/* */
/* Initialize variables */
/* */
strcpy(bd.computer,argv[1]);
return(SUCCEED);
}
/***************************************************************************/
/* FUNCTION TO MAKE SERVER CONNECTIONS */
/***************************************************************************/
int Connect_to_servers()
{
int done;
LOGINREC far *login;
/* */
/* Get the login record */
/* */
if((login = dblogin()) == NULL)
{
printf("\nBENCH ERROR: Out of memeory logging on to test server");
fprintf(outptr,"\nBENCH ERROR: Out of memory logging on to test server");
return(FAIL);
}
DBSETLUSER(login,"sa");
DBSETLPWD(login,"");
DBSETLAPP(login,"benchmarks");
/* */
/* Connect to the server under test. */
/* */
if((dbproc = dbopen(login,bd.test_server)) == NULL)
{
printf("\nBENCH ERROR: Unable to connect to the test server");
fprintf(outptr,"\nBENCH ERROR: Unable to connect to the test server");
return(FAIL);
}
dbfreelogin(login);
if(dbuse(dbproc,bd.database) == FAIL)
{
printf("\nBENCH ERROR: Database %s not found",bd.database);
fprintf(outptr,"\nBENCH ERROR: Database %s not found",bd.database);
return(FAIL);
}
printf("\nMade connection to test server %s",bd.test_server);
fprintf(outptr,"\n\nMade connection to test server %s",bd.test_server);
fflush(outptr);
/* */
/* Make a connection to the performance tracking database */
/* */
if((login = dblogin()) == NULL)
{
printf("\nBENCH ERROR: Out of memory logging on to tracking server");
fprintf(outptr,"\nBENCH ERROR: Out of memory logging on to tracking server");
return(FAIL);
}
DBSETLUSER(login,"sa");
DBSETLPWD(login,"");
DBSETLAPP(login,"bench_stats");
if((track_proc = dbopen(login,bd.track_server)) == NULL)
{
printf("\nBENCH ERROR: Unable to connect to the tracking server");
fprintf(outptr,"\nBENCH ERROR: Unable to connect to the tracking server");
return(FAIL);
}
dbfreelogin(login);
if(dbuse(track_proc,"bench_stat") == FAIL)
{
printf("\nBENCH ERROR: Cannot find bench_stat database");
fprintf(outptr,"\nBENCH ERROR: Cannot find bench_stat database");
return(FAIL);
}
printf("\nMade connection to tracking server %s",bd.track_server);
fprintf(outptr,"\n\n*** Made connection to tracking server %s ***",\
bd.track_server);
fflush(outptr);
return(SUCCEED);
}
/***************************************************************************/
/* FUNCTION TO START THE TIMER */
/***************************************************************************/
void Startimer(Start)
struct timeb *Start;
{
ftime(Start);
}
/***************************************************************************/
/* FUNCTION TO STOP THE TIMER */
/***************************************************************************/
void Get_elapsed_time(Start)
struct timeb Start; /* Start time */
{
unsigned long result;
struct timeb Stoptime;
ftime(&Stoptime);
/* */
/* If ending milliseconds greater than starting milliseconds, */
/* borrow from seconds. */
/* */
if (Stoptime.millitm < Start.millitm)
{
Stoptime.time--;
Stoptime.millitm += 1000;
}
/* */
/* Since time is represented in seconds since 1970, and */
/* would overflow when converted to milliseconds, simply */
/* take the difference modulo 1 day. */
/* */
result = (((Stoptime.time - Start.time) % (60*60*24L)) * 1000L) +
(Stoptime.millitm - Start.millitm);
/* */
/* Get the max, min and total (all loops) execution time of the transaction */
/* */
if (stats.Timecnt == 0)
{
stats.Timemin = result;
stats.Timemax = result;
}
else
{
if (result < stats.Timemin)
stats.Timemin = result;
else if (result > stats.Timemax)
stats.Timemax = result;
}
stats.Timetot += result;
/* */
/* If under 1 second, add 1 to Timeunder1 */
/* */
if (result < 1000)
++stats.Timeunder1;
/* */
/* If under 2 seconds, add 1 to Timeunder2 */
/* */
if (result < 2000)
++stats.Timeunder2;
}
/***************************************************************************/
/* FUNCTION TO EXECUTE TP/1 PROCEDURES */
/***************************************************************************/
void Run_tp1()
{
DBINT acct, teller, branch, delta, transid, pid;
char cmd[240],code;
struct timeb timein;
long elapsed,now,Target_time;
int done,i;
char tp1message[101];
CURR_ERROR = 0;
transid = pid = 0;
stats.Timemin = 0;
stats.Timemax = 0;
stats.Timetot = 0;
stats.Timecnt = 0;
stats.Errcnt = 0;
stats.Timeunder1 = 0;
stats.Timeunder2 = 0;
/* */
/* Initialize a 100 byte string to pass to the server for the TP1 benchmark */
/* */
strcpy(tp1message,"12345678901234567890123456789012345678901234567890");
strcat(tp1message,"12345678901234567890123456789012345678901234567890");
/* */
/* Execute for the specified number of seconds */
/* */
time(&stats.Real_start);
Target_time = stats.Real_start + bd.seconds;
do
{
/* */
/* Generate random numbers */
/* */
acct = get_random(bd.max_accts);
teller = get_random(bd.max_teller);
branch = get_random(bd.max_branch);
delta = get_random(500l);
++transid;
++pid;
sprintf(cmd,"exec tp1 %ld,%ld,%ld,%ld,%ld,%ld,'%s'",acct,teller,branch,
delta,transid,pid,tp1message);
dbcmd(dbproc,(char DBDIST *)cmd);
/* */
/* Send the script */
/* */
Startimer(&timein); /* Start exec timing here */
if(dbsqlexec(dbproc) != FAIL) /* execute it */
{
if(CURR_ERROR != 0)
CURR_ERROR = 0;
else
{
Get_results(dbproc); /* Get the results */
Get_elapsed_time(timein); /* Stop the res timing here */
++stats.Timecnt;
}
}
/* */
/* Check the elapsed time every 10 iterations*/
/* */
done = Check_time(Target_time);
}
while(done == FALSE);
time(&stats.Real_end);
}
/***************************************************************************/
/* FUNCTION TO CHECK TARGET TIME */
/***************************************************************************/
int Check_time(Target_time)
long Target_time;
{
long now;
if(stats.Timecnt%10 == 0)
{
time(&now);
if(now >= Target_time)
return(TRUE);
}
return(FALSE);
}
/***************************************************************************/
/* FUNCTION TO UPDATE THE PERFORMANCE TRACKING DATABASE */
/***************************************************************************/
void Update_bench_stats()
{
DBINT run_num;
char cmd[240],start_time[50],end_time[50];
struct tm *t;
fprintf(outptr,"\n\nStarted at: %s",ctime(&stats.Real_start));
fprintf(outptr,"Ended at : %s",ctime(&stats.Real_end));
fprintf(outptr,"\nIterations: %ld",stats.Timecnt);
fprintf(outptr,"\nErrors : %ld ",stats.Errcnt);
fflush(outptr);
printf("\nUpdating the performance tracking database");
t = localtime(&stats.Real_start);
sprintf(start_time,"%d/%d/%d %d:%d:%d",t->tm_mon + 1,t->tm_mday,t->tm_year,\
t->tm_hour,t->tm_min,t->tm_sec);
t = localtime(&stats.Real_end);
sprintf(end_time,"%d/%d/%d %d:%d:%d",t->tm_mon + 1,t->tm_mday,t->tm_year,\
t->tm_hour,t->tm_min,t->tm_sec);
/* */
/* Update the RUNS tables */
/* */
CURR_ERROR = SQLDUPROW;
while(CURR_ERROR != SUCCEED)
{
run_num = Get_max_value(track_proc,"runs","number"); /* get max run# + 1 */
++run_num;
sprintf(cmd,"insert into runs values "
"(%ld,'%s','%s','%s',%ld,%ld,%ld,%ld,%ld,%f,%ld,%ld)",
run_num,bd.computer,start_time,end_time,stats.Timecnt,
stats.Errcnt,stats.Timetot,stats.Timemin,stats.Timemax,
(float)stats.Timetot/stats.Timecnt,stats.Timeunder1,stats.Timeunder2);
dbcmd(track_proc,(char DBDIST *)cmd);
if(dbsqlexec(track_proc) != FAIL)
CURR_ERROR = SUCCEED;
Get_results(track_proc);
}
printf("\nSuccessful - Run number: %d\n\n",run_num);
fprintf(outptr,"\nRun number: %d",run_num);
fflush(outptr);
}
/***************************************************************************/
/* FUNCTION TO HANDLE DBLIB ERRORS */
/***************************************************************************/
int bench_err_handler(dbproc,severity,dberr,oserr,dberrstr,oserrstr)
DBPROCESS *dbproc;
int severity;
int dberr;
int oserr;
char *dberrstr;
char *oserrstr;
{
long ltoday;
if (PRINT_ERRORS)
{
time(<oday);
printf("\nDB-LIB error: %d=%s\n Time: %s",dberr,dberrstr,
ctime(<oday));
fprintf(outptr,"\nDB-LIB error: %d=%s\n Time: %s",dberr,dberrstr,
ctime(<oday));
fflush(outptr);
++stats.Errcnt;
}
return(INT_CANCEL);
}
/***************************************************************************/
/* FUNCTION TO HANDLE SQL SERVER MESSAGES */
/***************************************************************************/
int bench_msg_handler(dbproc,msgno,msgstate,severity,msgtext)
DBPROCESS *dbproc;
DBINT msgno;
int msgstate;
int severity;
char *msgtext;
{
long ltoday;
if (PRINT_ERRORS)
{
if (msgno != 5701)
{
CURR_ERROR = msgno;
time(<oday);
printf("\nMessage number: %ld=%s\n Time: %s",msgno,msgtext,
ctime(<oday));
fprintf(outptr,"\nMessage number: %ld=%s\n Time: %s",msgno,msgtext,
ctime(<oday));
fflush(outptr);
++stats.Errcnt;
}
}
return(0);
}