29 static TCHAR STATUS_DATA[]=_T(
"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F")
30 _T("101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F")
31 _T("202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F")
32 _T("303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F")
33 _T("404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F")
34 _T("505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F")
35 _T("606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F")
36 _T("707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F")
37 _T("808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F")
38 _T("909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F")
39 _T("10010110210310410510610710810910A000102030405060708090A0B0C0D0EF")
40 _T("10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF")
41 _T("11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF")
42 _T("12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF")
43 _T("12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF")
44 _T("13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF")
45 _T("14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF")
46 _T("14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF")
47 _T("15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF")
48 _T("16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF")
49 _T("16F170171172173174175176177178179000102030405060708090A0B0C0D0EF")
50 _T("17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF")
51 _T("18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF")
52 _T("19019119219319419519619719819919A000102030405060708090A0B0C0D0EF")
53 _T("19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF")
54 _T("20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF")
55 _T("21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF")
56 _T("21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF")
57 _T("22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF")
58 _T("23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF")
59 _T("23E23F240241242243244245246247248000102030405060708090A0B0C0D0EF")
60 _T("24924A24B24C24D24E24F250251252253000102030405060708090A0B0C0D0EF")
61 _T("101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F")
62 _T("202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F")
63 _T("303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F")
64 _T("404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F")
65 _T("505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F")
66 _T("606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F")
67 _T("707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F")
68 _T("808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F")
69 _T("909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F")
70 _T("10010110210310410510610710810910A000102030405060708090A0B0C0D0EF")
71 _T("10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF")
72 _T("11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF")
73 _T("12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF")
74 _T("12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF")
75 _T("13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF")
76 _T("14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF")
77 _T("14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF")
78 _T("15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF")
79 _T("16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF")
80 _T("16F170171172173174175176177178179000102030405060708090A0B0C0D0EF")
81 _T("17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF")
82 _T("18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF")
83 _T("19019119219319419519619719819919A000102030405060708090A0B0C0D0EF")
84 _T("19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF")
85 _T("20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF")
86 _T("21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF")
87 _T("21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF")
88 _T("22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF")
89 _T("23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF")
90 _T("2366890FE1438751097E7F6325DC0E6326F")
91 _T("25425525625725825925A25B25C25D25E25F000102030405060708090A0B0C0F");
96 HANDLE hShutdownEvent;
97 int nStartingRecordNum;
98 long* pnNumCallsProcessed;
101 HANDLE hShutdownEvent = 0;
103 BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType)
105 if(CTRL_C_EVENT == dwCtrlType)
107 SetEvent(hShutdownEvent);
116 DWORD WINAPI RuntimeCallContext(LPVOID lpParam)
118 long nNumCallsProcessed = 0;
121 int nStartingRecordID = pData->nStartingRecordNum;
128 char pchContextData[4008];
131 LARGE_INTEGER liStartTime, liEndTime;
133 pNdb =
new Ndb(
"TEST_DB");
136 printf(
"new Ndb failed\n");
148 while(WaitForSingleObject(pData->hShutdownEvent,0) != WAIT_OBJECT_0)
152 bool bTimeLatency = (nStartingRecordID == 100) ? TRUE : FALSE;
156 BOOL bSuccess = QueryPerformanceFrequency(&freq);
158 printf(
"Error retrieving frequency: %d\n", GetLastError());
162 for (
int i=0;
i < 20;
i++)
174 QueryPerformanceCounter(&liStartTime);
176 pNdbConnection = pNdb->
startTransaction((Uint32)0, (
const char*)&nStartingRecordID, (Uint32)4);
184 throw pNdbConnection;
187 || pNdbOperation->
equal(_T(
"ContextId"), nStartingRecordID))
191 pNdbRecAttrContextData = pNdbOperation->
getValue(_T(
"ContextData"), pchContextData);
192 if(!pNdbRecAttrContextData)
196 if(pNdbConnection->
execute(Commit))
198 throw pNdbConnection;
204 QueryPerformanceCounter(&liEndTime);
205 printf(
"Read = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
211 QueryPerformanceCounter(&liStartTime);
213 pNdbConnection = pNdb->
startTransaction((Uint32)0, (
const char*)&nStartingRecordID, (Uint32)4);
221 throw pNdbConnection;
224 || pNdbOperation->
equal(_T(
"ContextId"), nStartingRecordID))
228 if(pNdbConnection->
execute(Commit))
230 throw pNdbConnection;
236 QueryPerformanceCounter(&liEndTime);
237 printf(
"Delete = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
243 QueryPerformanceCounter(&liStartTime);
245 pNdbConnection = pNdb->
startTransaction((Uint32)0, (
const char*)&nStartingRecordID, (Uint32)4);
253 throw pNdbConnection;
256 || pNdbOperation->
equal(_T(
"ContextId"), nStartingRecordID)
257 || pNdbOperation->
setValue(_T(
"Version"), Int32(1))
258 || pNdbOperation->
setValue(_T(
"LockFlag"), Int32(1))
259 || pNdbOperation->
setValue(_T(
"LockTime"), Int32(1))
260 || pNdbOperation->
setValue(_T(
"LockTimeUSec"), Int32(1))
261 || pNdbOperation->
setValue(_T(
"ContextData"), STATUS_DATA,
sizeof(STATUS_DATA)))
265 if(pNdbConnection->
execute(Commit))
267 throw pNdbConnection;
273 QueryPerformanceCounter(&liEndTime);
274 printf(
"Insert = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
280 QueryPerformanceCounter(&liStartTime);
282 pNdbConnection = pNdb->
startTransaction((Uint32)0, (
const char*)&nStartingRecordID, (Uint32)4);
290 throw pNdbConnection;
296 if(pNdbOperation->
equal(_T(
"ContextId"), nStartingRecordID)
297 || pNdbOperation->
setValue(_T(
"ContextData"), STATUS_DATA,
sizeof(STATUS_DATA)))
301 if(pNdbConnection->
execute(Commit))
303 throw pNdbConnection;
309 QueryPerformanceCounter(&liEndTime);
310 printf(
"Update = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
317 nNumCallsProcessed++;
319 InterlockedIncrement(pData->pnNumCallsProcessed);
326 printf(
"%d: \n\t%s\n\t%s\n",
328 pNdb->getNdbErrorString(),
334 printf(
"%d: \n\t%s\n\t%s\n",
336 pNdbConnection->getNdbErrorString(),
343 printf(
"%d: \n\t%s\n\t%s\n",
345 pNdbOperation->getNdbErrorString(),
355 void Initialize(
Ndb* pNdb,
long nInsert,
bool bStoredTable)
364 _tprintf(_T(
"Create CallContext table\n"));
366 pNdbSchemaCon = pNdb->startSchemaTransaction();
376 if(pNdbSchemaOp->
createTable(_T(
"CallContext"), 8, TupleKey, 2, All, 6, 78, 80, 1, bStoredTable)
377 || pNdbSchemaOp->
createAttribute(_T(
"ContextId"), TupleKey, 32, 1, Signed)
381 || pNdbSchemaOp->
createAttribute(_T(
"LockTimeUSec"), NoKey, 32, 1, Signed)
390 pNdb->closeSchemaTransaction(pNdbSchemaCon);
392 _tprintf(_T(
"Insert %d tuples in the CallContext table\n"), nInsert);
393 for(
long i=0;
i<nInsert; ++
i)
395 long iContextId = -
i;
396 pNdbConnection = pNdb->
startTransaction((Uint32)0, (
const char*)&iContextId, (Uint32)4);
404 throw pNdbConnection;
407 || pNdbOperation->
equal(_T(
"ContextId"), iContextId)
408 || pNdbOperation->
setValue(_T(
"Version"), Int32(1))
409 || pNdbOperation->
setValue(_T(
"LockFlag"), Int32(1))
410 || pNdbOperation->
setValue(_T(
"LockTime"), Int32(1))
411 || pNdbOperation->
setValue(_T(
"LockTimeUSec"), Int32(1))
412 || pNdbOperation->
setValue(_T(
"ContextData"), STATUS_DATA,
sizeof(STATUS_DATA)))
416 if(pNdbConnection->
execute(Commit))
418 throw pNdbConnection;
422 _tprintf(_T(
"initialisation done\n"));
426 printf(
"%d: \n\t%s\n\t%s\n",
428 pNdb->getNdbErrorString(),
434 printf(
"%d: \n\t%s\n\t%s\n",
436 pNdbConnection->getNdbErrorString(),
443 printf(
"%d: \n\t%s\n\t%s\n",
445 pNdbOperation->getNdbErrorString(),
452 printf(
"%d: \n\t%s\n\t%s\n",
454 pNdbSchemaCon->getNdbErrorString(),
456 pNdb->closeSchemaTransaction(pNdbSchemaCon);
461 printf(
"%d: \n\t%s\n\t%s\n",
462 pNdbSchemaOp->getNdbError(),
463 pNdbSchemaOp->getNdbErrorString(),
471 int _tmain(
int argc, _TCHAR* argv[])
476 bool bStoredTable =
true;
477 if(lstrcmp(argv[1],_T(
"/?")) == 0)
479 _tprintf(_T(
"InsertRecs [No.Of Threads] [Record Seed No.] [Init no. of rec.] [Stored?]\n"));
484 nNumThreads = _ttol(argv[1]);
488 nSeed = _ttol(argv[2]);
489 _tprintf(_T(
"Num of Threads = %d, Seed = %d"), nNumThreads, nSeed);
492 nInsert = _ttol(argv[3]);
494 bStoredTable = (_ttol(argv[4])!=0);
496 long nNumCallsProcessed = 0;
498 SetConsoleCtrlHandler(ConsoleCtrlHandler,
true);
499 hShutdownEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
502 WORD wVersionRequested;
505 wVersionRequested = MAKEWORD( 2, 2 );
506 err = WSAStartup( wVersionRequested, &wsaData );
508 _tprintf(_T(
"could not find a usable WinSock DLL\n"));
511 if ( LOBYTE( wsaData.wVersion ) != 2
512 || HIBYTE( wsaData.wVersion ) != 2 )
514 _tprintf(_T(
"could not find a usable WinSock DLL\n"));
519 Ndb* pNdb =
new Ndb(
"TEST_DB");
522 _tprintf(_T(
"could not construct ndb\n"));
528 _tprintf(_T(
"could not initialize ndb\n"));
534 Initialize(pNdb, nInsert, bStoredTable);
539 _tprintf(_T(
"creating %d threads\n"), nNumThreads);
540 DWORD dwStartTime = GetTickCount();
542 DWORD dwThreadID = 0;
547 for(
int ij=0;ij<nNumThreads;ij++) {
548 params[ij].hShutdownEvent = hShutdownEvent;
549 params[ij].nStartingRecordNum = (ij*5000) + nSeed;
550 params[ij].pnNumCallsProcessed = &nNumCallsProcessed;
553 for(ij=0;ij<nNumThreads;ij++) {
554 hThreads[ij] = CreateThread(NULL,NULL,RuntimeCallContext,¶ms[ij],0,&dwThreadID);
558 WaitForMultipleObjects(nNumThreads,hThreads,TRUE,INFINITE);
559 DWORD dwEndTime = GetTickCount();
562 _tprintf(_T(
"Time Taken for %d Calls is %ld msec (= %ld calls/sec\n"),
563 nNumCallsProcessed,dwEndTime-dwStartTime, (1000*nNumCallsProcessed/(dwEndTime-dwStartTime)));
568 CloseHandle(hShutdownEvent);