18 #include <ndb_global.h>
21 #include <NdbSchemaCon.hpp>
22 #include <NdbCondition.h>
25 #include <NdbThread.h>
29 const char*
const c_szDatabaseName =
"TEST_DB";
31 const char*
const c_szTableNameStored =
"CCStored";
32 const char*
const c_szTableNameTemp =
"CCTemp";
34 const char*
const c_szContextId =
"ContextId";
35 const char*
const c_szVersion =
"Version";
36 const char*
const c_szLockFlag =
"LockFlag";
37 const char*
const c_szLockTime =
"LockTime";
38 const char*
const c_szLockTimeUSec =
"LockTimeUSec";
39 const char*
const c_szContextData =
"ContextData";
41 const char* g_szTableName = c_szTableNameStored;
45 HANDLE hShutdownEvent = 0;
47 bool bShutdownEvent =
false;
49 long g_nMaxContextIdPerThread = 5000;
50 long g_nNumThreads = 0;
51 long g_nMaxCallsPerSecond = 0;
52 long g_nMaxRetry = 50;
53 bool g_bWriteTuple =
false;
54 bool g_bInsertInitial =
false;
55 bool g_bVerifyInitial =
false;
58 NdbMutex* g_pNdbMutexPrintf = 0;
59 NdbMutex* g_pNdbMutexIncrement = 0;
60 long g_nNumCallsProcessed = 0;
61 NDB_TICKS g_tStartTime = 0;
62 NDB_TICKS g_tEndTime = 0;
64 long g_nNumberOfInitialInsert = 0;
65 long g_nNumberOfInitialVerify = 0;
67 const long c_nMaxMillisecForAllCall = 5000;
68 long* g_plCountMillisecForCall = 0;
69 const long c_nMaxMillisecForAllTrans = 5000;
70 long* g_plCountMillisecForTrans = 0;
71 bool g_bReport =
false;
72 bool g_bReportPlus =
false;
76 static char STATUS_DATA[]=
77 "000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F"
78 "101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F"
79 "202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F"
80 "303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F"
81 "404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F"
82 "505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F"
83 "606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F"
84 "707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F"
85 "808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F"
86 "909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F"
87 "10010110210310410510610710810910A000102030405060708090A0B0C0D0EF"
88 "10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF"
89 "11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF"
90 "12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF"
91 "12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF"
92 "13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF"
93 "14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF"
94 "14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF"
95 "15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF"
96 "16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF"
97 "16F170171172173174175176177178179000102030405060708090A0B0C0D0EF"
98 "17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF"
99 "18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF"
100 "19019119219319419519619719819919A000102030405060708090A0B0C0D0EF"
101 "19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF"
102 "20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF"
103 "21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF"
104 "21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF"
105 "22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF"
106 "23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF"
107 "23E23F240241242243244245246247248000102030405060708090A0B0C0D0EF"
108 "24924A24B24C24D24E24F250251252253000102030405060708090A0B0C0D0EF"
109 "101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F"
110 "202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F"
111 "303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F"
112 "404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F"
113 "505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F"
114 "606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F"
115 "707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F"
116 "808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F"
117 "909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F"
118 "10010110210310410510610710810910A000102030405060708090A0B0C0D0EF"
119 "10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF"
120 "11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF"
121 "12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF"
122 "12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF"
123 "13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF"
124 "14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF"
125 "14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF"
126 "15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF"
127 "16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF"
128 "16F170171172173174175176177178179000102030405060708090A0B0C0D0EF"
129 "17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF"
130 "18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF"
131 "19019119219319419519619719819919A000102030405060708090A0B0C0D0EF"
132 "19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF"
133 "20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF"
134 "21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF"
135 "21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF"
136 "22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF"
137 "23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF"
138 "2366890FE1438751097E7F6325DC0E6326F"
139 "25425525625725825925A25B25C25D25E25F000102030405060708090A0B0C0F";
141 long g_nStatusDataSize =
sizeof(STATUS_DATA);
149 BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType)
151 if(CTRL_C_EVENT == dwCtrlType)
153 SetEvent(hShutdownEvent);
161 void CtrlCHandler(
int)
163 bShutdownEvent =
true;
170 void ReportNdbError(
const char* szMsg,
const NdbError& err)
172 NdbMutex_Lock(g_pNdbMutexPrintf);
174 NdbMutex_Unlock(g_pNdbMutexPrintf);
179 ReportCallsPerSecond(
long nNumCallsProcessed,
180 NDB_TICKS tStartTime,
183 NDB_TICKS tElapsed = tEndTime - tStartTime;
186 lCallsPerSec = (long)((1000*nNumCallsProcessed)/tElapsed);
190 NdbMutex_Lock(g_pNdbMutexPrintf);
191 printf(
"Time Taken for %ld Calls is %ld msec (= %ld calls/sec)\n",
192 nNumCallsProcessed, (
long)tElapsed, lCallsPerSec);
193 NdbMutex_Unlock(g_pNdbMutexPrintf);
198 void InterlockedIncrement(
long* lp)
200 NdbMutex_Lock(g_pNdbMutexIncrement);
202 NdbMutex_Unlock(g_pNdbMutexIncrement);
207 void InterlockedIncrementAndReport(
void)
209 NdbMutex_Lock(g_pNdbMutexIncrement);
210 ++g_nNumCallsProcessed;
211 if((g_nNumCallsProcessed%1000)==0)
213 g_tEndTime = NdbTick_CurrentMillisecond();
215 ReportCallsPerSecond(1000, g_tStartTime, g_tEndTime);
217 g_tStartTime = g_tEndTime;
219 NdbMutex_Unlock(g_pNdbMutexIncrement);
223 void SleepOneCall(
void)
225 int iMillisecToSleep;
226 if(g_nMaxCallsPerSecond>0)
227 iMillisecToSleep = (1000*g_nNumThreads)/g_nMaxCallsPerSecond;
229 iMillisecToSleep = 50;
231 if(iMillisecToSleep>0)
232 NdbSleep_MilliSleep(iMillisecToSleep);
238 int QueryTransaction(
Ndb* pNdb,
243 long* piLockTimeUSec,
244 char* pchContextData,
261 && !pNdbOperation->
equal(c_szContextId, (Int32)iContextId)
262 && (pNdbRecAttrVersion=pNdbOperation->
getValue(c_szVersion, (
char*)piVersion))
263 && (pNdbRecAttrLockFlag=pNdbOperation->
getValue(c_szLockFlag, (
char*)piLockFlag))
264 && (pNdbRecAttrLockTime=pNdbOperation->
getValue(c_szLockTime, (
char*)piLockTime))
265 && (pNdbRecAttrLockTimeUSec=pNdbOperation->
getValue(c_szLockTimeUSec, (
char*)piLockTimeUSec))
266 && (pNdbRecAttrContextData=pNdbOperation->
getValue(c_szContextData, pchContextData)))
268 if(!pNdbConnection->
execute(Commit))
288 int RetryQueryTransaction(
Ndb* pNdb,
293 long* piLockTimeUSec,
294 char* pchContextData,
301 while(bRetry && nRetry<g_nMaxRetry)
303 if(!QueryTransaction(pNdb, iContextId, piVersion, piLockFlag,
304 piLockTime, piLockTimeUSec, pchContextData, err))
330 int DeleteTransaction(
Ndb* pNdb,
long iContextId,
NdbError& err)
341 && !pNdbOperation->
equal(c_szContextId, (Int32)iContextId))
343 if(pNdbConnection->
execute(Commit) == 0)
364 int RetryDeleteTransaction(
Ndb* pNdb,
long iContextId,
NdbError& err,
int& nRetry)
369 bool bUnknown =
false;
370 while(bRetry && nRetry<g_nMaxRetry)
372 if(!DeleteTransaction(pNdb, iContextId, err))
393 if(err.
code==626 && bUnknown)
409 int InsertTransaction(
Ndb* pNdb,
415 const char* pchContextData,
427 && !pNdbOperation->
equal(c_szContextId, (Int32)iContextID)
428 && !pNdbOperation->
setValue(c_szVersion, (Int32)iVersion)
429 && !pNdbOperation->
setValue(c_szLockFlag, (Int32)iLockFlag)
430 && !pNdbOperation->
setValue(c_szLockTime, (Int32)iLockTime)
431 && !pNdbOperation->
setValue(c_szLockTimeUSec, (Int32)iLockTimeUSec)
432 && !pNdbOperation->
setValue(c_szContextData, pchContextData, g_nStatusDataSize))
434 if(!pNdbConnection->
execute(Commit))
455 int RetryInsertTransaction(
Ndb* pNdb,
461 const char* pchContextData,
467 bool bUnknown =
false;
468 while(bRetry && nRetry<g_nMaxRetry)
470 if(!InsertTransaction(pNdb, iContextId, iVersion, iLockFlag,
471 iLockTime, iLockTimeUSec, pchContextData, err))
492 if(err.
code==630 && bUnknown)
507 int UpdateTransaction(
Ndb* pNdb,
long iContextId,
NdbError& err)
518 && !pNdbOperation->
equal(c_szContextId, (Int32)iContextId)
519 && !pNdbOperation->
setValue(c_szContextData, STATUS_DATA, g_nStatusDataSize))
521 if(!pNdbConnection->
execute(Commit))
541 int RetryUpdateTransaction(
Ndb* pNdb,
long iContextId,
NdbError& err,
int& nRetry)
546 while(bRetry && nRetry<g_nMaxRetry)
548 if(!UpdateTransaction(pNdb, iContextId, err))
575 int InsertInitialRecords(
Ndb* pNdb,
long nInsert,
long nSeed)
579 for(
long i=0;
i<nInsert; ++
i)
581 int iContextID =
i+nSeed;
584 memset(&err, 0,
sizeof(err));
585 NDB_TICKS tStartTrans = NdbTick_CurrentMillisecond();
586 iRes = RetryInsertTransaction(pNdb, iContextID, nSeed, iContextID,
587 (
long)(tStartTrans/1000), (
long)((tStartTrans%1000)*1000),
588 STATUS_DATA, err, nRetry);
589 NDB_TICKS tEndTrans = NdbTick_CurrentMillisecond();
590 long lMillisecForThisTrans = (long)(tEndTrans-tStartTrans);
593 sprintf(szMsg,
"insert retried %d times, time %ld msec.",
594 nRetry, lMillisecForThisTrans);
595 ReportNdbError(szMsg, err);
599 ReportNdbError(
"Insert initial record failed", err);
602 InterlockedIncrement(&g_nNumberOfInitialInsert);
609 int VerifyInitialRecords(
Ndb* pNdb,
long nVerify,
long nSeed)
612 char* pchContextData =
new char[g_nStatusDataSize];
614 long iPrevLockTime = -1;
615 long iPrevLockTimeUSec = -1;
616 for(
long i=0;
i<nVerify; ++
i)
618 int iContextID =
i+nSeed;
622 long iLockTimeUSec = 0;
625 memset(&err, 0,
sizeof(err));
626 NDB_TICKS tStartTrans = NdbTick_CurrentMillisecond();
627 iRes = RetryQueryTransaction(pNdb, iContextID, &iVersion, &iLockFlag,
628 &iLockTime, &iLockTimeUSec, pchContextData, err, nRetry);
629 NDB_TICKS tEndTrans = NdbTick_CurrentMillisecond();
630 long lMillisecForThisTrans = (long)(tEndTrans-tStartTrans);
633 sprintf(szMsg,
"verify retried %d times, time %ld msec.",
634 nRetry, lMillisecForThisTrans);
635 ReportNdbError(szMsg, err);
639 ReportNdbError(
"Read initial record failed", err);
640 delete[] pchContextData;
643 if(memcmp(pchContextData, STATUS_DATA, g_nStatusDataSize))
645 sprintf(szMsg,
"wrong context data in tuple %d", iContextID);
646 ReportNdbError(szMsg, err);
647 delete[] pchContextData;
651 || iLockFlag!=iContextID
652 || iLockTime<iPrevLockTime
653 || (iLockTime==iPrevLockTime && iLockTimeUSec<iPrevLockTimeUSec))
655 sprintf(szMsg,
"wrong call data in tuple %d", iContextID);
656 ReportNdbError(szMsg, err);
657 delete[] pchContextData;
660 iPrevLockTime = iLockTime;
661 iPrevLockTimeUSec = iLockTimeUSec;
662 InterlockedIncrement(&g_nNumberOfInitialVerify);
664 delete[] pchContextData;
672 void* RuntimeCallContext(
void* lpParam)
674 long nNumCallsProcessed = 0;
675 int nStartingRecordID = *(
int*)lpParam;
678 char* pchContextData =
new char[g_nStatusDataSize];
688 pNdb =
new Ndb(theConnection,
"TEST_DB");
691 NdbMutex_Lock(g_pNdbMutexPrintf);
692 printf(
"new Ndb failed\n");
693 NdbMutex_Unlock(g_pNdbMutexPrintf);
694 delete[] pchContextData;
700 ReportNdbError(
"init of Ndb failed", pNdb->
getNdbError());
702 delete[] pchContextData;
708 if(InsertInitialRecords(pNdb, g_nMaxContextIdPerThread, -nStartingRecordID-g_nMaxContextIdPerThread))
711 delete[] pchContextData;
719 memset(&err, 0,
sizeof(err));
720 if(VerifyInitialRecords(pNdb, g_nMaxContextIdPerThread, -nStartingRecordID-g_nMaxContextIdPerThread))
723 delete[] pchContextData;
727 if(g_bInsertInitial || g_bVerifyInitial)
729 delete[] pchContextData;
733 long nContextID = nStartingRecordID;
735 while(WaitForSingleObject(hShutdownEvent,0) != WAIT_OBJECT_0)
737 while(!bShutdownEvent)
741 nContextID %= g_nMaxContextIdPerThread;
742 nContextID += nStartingRecordID;
744 bool bTimeLatency = (nContextID==100);
746 NDB_TICKS tStartCall = NdbTick_CurrentMillisecond();
747 for (
int i=0;
i < 20;
i++)
751 memset(&err, 0,
sizeof(err));
752 NDB_TICKS tStartTrans = NdbTick_CurrentMillisecond();
763 iRes = RetryQueryTransaction(pNdb, nContextID, &iVersion, &iLockFlag,
764 &iLockTime, &iLockTimeUSec, pchContextData, err, nRetry);
769 iRes = RetryDeleteTransaction(pNdb, nContextID, err, nRetry);
774 iRes = RetryInsertTransaction(pNdb, nContextID, 1, 1, 1, 1, STATUS_DATA, err, nRetry);
779 iRes = RetryUpdateTransaction(pNdb, nContextID, err, nRetry);
782 NDB_TICKS tEndTrans = NdbTick_CurrentMillisecond();
783 long lMillisecForThisTrans = (long)(tEndTrans-tStartTrans);
787 assert(lMillisecForThisTrans>=0 && lMillisecForThisTrans<c_nMaxMillisecForAllTrans);
788 InterlockedIncrement(g_plCountMillisecForTrans+lMillisecForThisTrans);
793 sprintf(szMsg,
"%s retried %d times, time %ld msec.",
794 szOp, nRetry, lMillisecForThisTrans);
795 ReportNdbError(szMsg, err);
797 else if(bTimeLatency)
799 NdbMutex_Lock(g_pNdbMutexPrintf);
800 printf(
"%s = %ld msec.\n", szOp, lMillisecForThisTrans);
801 NdbMutex_Unlock(g_pNdbMutexPrintf);
806 sprintf(szMsg,
"%s failed after %ld calls, terminating thread",
807 szOp, nNumCallsProcessed);
808 ReportNdbError(szMsg, err);
810 delete[] pchContextData;
814 NDB_TICKS tEndCall = NdbTick_CurrentMillisecond();
815 long lMillisecForThisCall = (long)(tEndCall-tStartCall);
819 assert(lMillisecForThisCall>=0 && lMillisecForThisCall<c_nMaxMillisecForAllCall);
820 InterlockedIncrement(g_plCountMillisecForCall+lMillisecForThisCall);
825 NdbMutex_Lock(g_pNdbMutexPrintf);
826 printf(
"Total time for call is %ld msec.\n", (
long)lMillisecForThisCall);
827 NdbMutex_Unlock(g_pNdbMutexPrintf);
830 nNumCallsProcessed++;
831 InterlockedIncrementAndReport();
832 if(g_nMaxCallsPerSecond>0)
834 int iMillisecToSleep = (1000*g_nNumThreads)/g_nMaxCallsPerSecond;
835 iMillisecToSleep -= lMillisecForThisCall;
836 if(iMillisecToSleep>0)
838 NdbSleep_MilliSleep(iMillisecToSleep);
843 NdbMutex_Lock(g_pNdbMutexPrintf);
844 printf(
"Terminating thread after %ld calls\n", nNumCallsProcessed);
845 NdbMutex_Unlock(g_pNdbMutexPrintf);
848 delete[] pchContextData;
853 int CreateCallContextTable(
Ndb* pNdb,
const char* szTableName,
bool bStored)
857 memset(&err, 0,
sizeof(err));
859 NdbSchemaCon* pNdbSchemaCon = NdbSchemaCon::startSchemaTrans(pNdb);
865 if(!pNdbSchemaOp->
createTable(szTableName, 8, TupleKey, 2,
866 All, 6, 78, 80, 1, bStored)
867 && !pNdbSchemaOp->
createAttribute(c_szContextId, TupleKey, 32, 1, Signed)
871 && !pNdbSchemaOp->
createAttribute(c_szLockTimeUSec, NoKey, 32, 1, Signed)
880 err = pNdbSchemaOp->getNdbError();
885 NdbSchemaCon::closeSchemaTrans(pNdbSchemaCon);
892 ReportNdbError(
"create call context table failed", err);
899 void ReportResponseTimeStatistics(
const char* szStat,
long* plCount,
const long lSize)
907 for(
long l=0; l<lSize; ++l)
911 lCount += plCount[l];
912 llSum += (Int64)l*(Int64)plCount[l];
913 llSum2 += (Int64)l*(Int64)l*(Int64)plCount[l];
914 if(lMin==-1 || l<lMin)
918 if(lMax==-1 || l>lMax)
925 long lAvg = long(llSum/lCount);
926 double dblVar = ((double)lCount*(
double)llSum2 - (double)llSum*(
double)llSum)/((
double)lCount*(
double)(lCount-1));
927 long lStd =
long(sqrt(dblVar));
932 for(
long l=lMin; l<=lMax; ++l)
937 if(lMed==-1 && lSel>=(lCount/2))
941 if(l95==-1 && lSel>=((lCount*95)/100))
947 printf(
"%ld\t%ld\n", l, plCount[l]);
952 printf(
"%s: Count=%ld, Min=%ld, Max=%ld, Avg=%ld, Std=%ld, Med=%ld, 95%%=%ld\n",
953 szStat, lCount, lMin, lMax, lAvg, lStd, lMed, l95);
958 void ShowHelp(
const char* szCmd)
960 printf(
"%s -t<threads> [-s<seed>] [-b<batch>] [-c<maxcps>] [-m<size>] [-d] [-i] [-v] [-f] [-w] [-r[+]]\n", szCmd);
961 printf(
"%s -?\n", szCmd);
962 puts(
"-d\t\tcreate the table");
963 puts(
"-i\t\tinsert initial records");
964 puts(
"-v\t\tverify initial records");
965 puts(
"-t<threads>\tnumber of threads making calls");
966 puts(
"-s<seed>\toffset for primary key");
967 puts(
"-b<batch>\tbatch size per thread");
968 puts(
"-c<maxcps>\tmax number of calls per second for this process");
969 puts(
"-m<size>\tsize of context data");
970 puts(
"-f\t\tno checkpointing and no logging");
971 puts(
"-w\t\tuse writeTuple instead of insertTuple");
972 puts(
"-r\t\treport response time statistics");
973 puts(
"-r+\t\treport response time distribution");
978 int main(
int argc,
char* argv[])
982 g_nMaxCallsPerSecond = 0;
984 bool bStoredTable =
true;
985 bool bCreateTable =
false;
986 g_bWriteTuple =
false;
988 g_bReportPlus =
false;
990 for(
int i=1;
i<argc; ++
i)
992 if(argv[
i][0]==
'-' || argv[
i][0]==
'/')
997 g_nNumThreads = atol(argv[i]+2);
1000 nSeed = atol(argv[i]+2);
1003 g_nMaxContextIdPerThread = atol(argv[i]+2);
1006 g_nStatusDataSize = atol(argv[i]+2);
1007 if(g_nStatusDataSize> (
int)
sizeof(STATUS_DATA))
1009 g_nStatusDataSize =
sizeof(STATUS_DATA);
1013 g_bInsertInitial =
true;
1016 g_bVerifyInitial =
true;
1019 bCreateTable =
true;
1022 bStoredTable =
false;
1025 g_bWriteTuple =
true;
1031 g_bReportPlus =
true;
1035 g_nMaxCallsPerSecond = atol(argv[i]+2);
1050 puts(
"-d\tcreate the table");
1051 if(g_bInsertInitial)
1052 printf(
"-i\tinsert initial records\n");
1053 if(g_bVerifyInitial)
1054 printf(
"-v\tverify initial records\n");
1056 printf(
"-t%ld\tnumber of threads making calls\n", g_nNumThreads);
1059 printf(
"-s%ld\toffset for primary key\n", nSeed);
1060 printf(
"-b%ld\tbatch size per thread\n", g_nMaxContextIdPerThread);
1062 if(g_nMaxCallsPerSecond>0)
1063 printf(
"-c%ld\tmax number of calls per second for this process\n", g_nMaxCallsPerSecond);
1065 puts(
"-f\tno checkpointing and no logging to disk");
1067 puts(
"-w\tuse writeTuple instead of insertTuple");
1069 puts(
"-r\treport response time statistics");
1071 puts(
"-r+\treport response time distribution");
1073 if(!bCreateTable && g_nNumThreads<=0)
1078 printf(
"-m%ld\tsize of context data\n", g_nStatusDataSize);
1080 g_szTableName = (bStoredTable ? c_szTableNameStored : c_szTableNameTemp);
1083 SetConsoleCtrlHandler(ConsoleCtrlHandler,
true);
1085 signal(SIGINT, CtrlCHandler);
1090 g_plCountMillisecForCall =
new long[c_nMaxMillisecForAllCall];
1091 memset(g_plCountMillisecForCall, 0, c_nMaxMillisecForAllCall*
sizeof(
long));
1092 g_plCountMillisecForTrans =
new long[c_nMaxMillisecForAllTrans];
1093 memset(g_plCountMillisecForTrans, 0, c_nMaxMillisecForAllTrans*
sizeof(
long));
1096 g_pNdbMutexIncrement = NdbMutex_Create();
1097 g_pNdbMutexPrintf = NdbMutex_Create();
1099 hShutdownEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
1103 if (theConnection->
connect(12, 5, 1) != 0)
1105 ndbout <<
"Unable to connect to managment server." << endl;
1110 ndbout <<
"Cluster nodes not ready in 30 seconds." << endl;
1114 Ndb* pNdb =
new Ndb(theConnection, c_szDatabaseName);
1117 printf(
"could not construct ndb\n");
1123 ReportNdbError(
"could not initialize ndb\n", pNdb->
getNdbError());
1130 printf(
"Create CallContext table\n");
1133 if (CreateCallContextTable(pNdb, c_szTableNameStored,
true))
1135 printf(
"Create table failed\n");
1142 if (CreateCallContextTable(pNdb, c_szTableNameTemp,
false))
1144 printf(
"Create table failed\n");
1153 printf(
"creating %d threads\n", (
int)g_nNumThreads);
1154 if(g_bInsertInitial)
1156 printf(
"each thread will insert %ld initial records, total %ld inserts\n",
1157 g_nMaxContextIdPerThread, g_nNumThreads*g_nMaxContextIdPerThread);
1159 if(g_bVerifyInitial)
1161 printf(
"each thread will verify %ld initial records, total %ld reads\n",
1162 g_nMaxContextIdPerThread, g_nNumThreads*g_nMaxContextIdPerThread);
1165 g_nNumberOfInitialInsert = 0;
1166 g_nNumberOfInitialVerify = 0;
1168 NDB_TICKS tStartTime = NdbTick_CurrentMillisecond();
1170 int pnStartingRecordNum[256];
1172 for(ij=0;ij<g_nNumThreads;ij++)
1174 pnStartingRecordNum[ij] = (ij*g_nMaxContextIdPerThread) + nSeed;
1177 for(ij=0;ij<g_nNumThreads;ij++)
1179 pThreads[ij] = NdbThread_Create(RuntimeCallContext,
1180 (
void**)(pnStartingRecordNum+ij),
1181 0,
"RuntimeCallContext", NDB_THREAD_PRIO_LOW);
1185 for(ij=0;ij<g_nNumThreads;ij++)
1188 NdbThread_WaitFor(pThreads[ij], &status);
1190 NDB_TICKS tEndTime = NdbTick_CurrentMillisecond();
1193 printf(
"Time Taken for %ld Calls is %ld msec (= %ld calls/sec)\n",
1194 g_nNumCallsProcessed,
1195 (
long)(tEndTime-tStartTime),
1196 (
long)((1000*g_nNumCallsProcessed)/(tEndTime-tStartTime)));
1198 if(g_bInsertInitial)
1199 printf(
"successfully inserted %ld tuples\n", g_nNumberOfInitialInsert);
1200 if(g_bVerifyInitial)
1201 printf(
"successfully verified %ld tuples\n", g_nNumberOfInitialVerify);
1207 CloseHandle(hShutdownEvent);
1209 NdbMutex_Destroy(g_pNdbMutexIncrement);
1210 NdbMutex_Destroy(g_pNdbMutexPrintf);
1214 ReportResponseTimeStatistics(
"Calls", g_plCountMillisecForCall, c_nMaxMillisecForAllCall);
1215 ReportResponseTimeStatistics(
"Transactions", g_plCountMillisecForTrans, c_nMaxMillisecForAllTrans);
1217 delete[] g_plCountMillisecForCall;
1218 delete[] g_plCountMillisecForTrans;