24 #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
25 no_namespace rename(
"EOF",
"EndOfFile")
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);
113 DWORD WINAPI RuntimeCallContext(LPVOID lpParam)
115 long nNumCallsProcessed = 0;
118 int nStartingRecordID = pData->nStartingRecordNum;
120 HRESULT hr = CoInitialize(NULL);
123 printf(
"Error Initializing COM Library\n");
127 _ConnectionPtr cn = NULL;
128 _CommandPtr cmdUpdate = NULL, cmdInsert = NULL, cmdDelete = NULL, cmdSelect = NULL;
129 _RecordsetPtr rs = NULL;
130 _ParameterPtr paramContextID = NULL;
131 _ParameterPtr paramVersion = NULL;
132 _ParameterPtr paramLockFlag = NULL;
133 _ParameterPtr ttparamLockFlag = NULL;
134 _ParameterPtr paramLockTime = NULL;
135 _ParameterPtr paramLockTimeUSec = NULL;
136 _ParameterPtr paramContextData = NULL;
137 _variant_t vtVersion;
138 _variant_t vtLockFlag;
139 _variant_t vtLockTime;
140 _variant_t vtLockTimeUSec;
141 _variant_t vtContextData;
143 vtVersion = CALL_CONTEXT_VERSION;
144 vtLockFlag = CALL_CONTEXT_LOCK_FLAG;
145 vtLockTime = CALL_CONTEXT_LOCK_TIME;
146 vtLockTimeUSec = CALL_CONTEXT_LOCK_TIME_USEC;
147 vtContextData = STATUS_DATA;
151 DWORD dwStartTime, dwEndTime;
152 LARGE_INTEGER liStartTime, liEndTime;
157 cn->ConnectionString = _T(
"DSN=TTTelcoCS;");
158 cn->Open(_T(
""),_T(
""),_T(
""),adConnectUnspecified);
160 cmdUpdate.CreateInstance(__uuidof(Command));
161 cmdInsert.CreateInstance(__uuidof(Command));
162 cmdDelete.CreateInstance(__uuidof(Command));
163 cmdSelect.CreateInstance(__uuidof(Command));
165 TCHAR tszInsert[10000], tszUpdate[10000];
166 memset(tszInsert, 0,
sizeof(tszInsert));
167 memset(tszUpdate, 0,
sizeof(tszUpdate));
168 strcpy(tszInsert,
"INSERT INTO dbo.CallContext(ContextId,Version,LockFlag,LockTime,LockTimeUSec,ContextData) VALUES(?,?,?,?,?,'");
169 strcat(tszInsert, STATUS_DATA);
170 strcat(tszInsert,
"')");
172 cmdInsert->CommandText= tszInsert;
173 cmdInsert->ActiveConnection = cn;
174 cmdInsert->Prepared = TRUE;
177 strcpy(tszUpdate,
"UPDATE dbo.CallContext SET ContextData = '");
178 strcat(tszUpdate, STATUS_DATA);
179 strcat(tszUpdate,
"' WHERE ContextId = ?");
180 cmdUpdate->CommandText= tszUpdate;
181 cmdUpdate->ActiveConnection = cn;
182 cmdUpdate->Prepared = TRUE;
184 cmdDelete->CommandText=_T(
"DELETE FROM dbo.CallContext WHERE ContextId = ?");
185 cmdDelete->ActiveConnection = cn;
186 cmdDelete->Prepared = TRUE;
188 cmdSelect->CommandText=_T(
"SELECT ContextData FROM dbo.CallContext WHERE ContextId = ?");
189 cmdSelect->ActiveConnection = cn;
190 cmdSelect->Prepared = TRUE;
194 paramContextID = cmdInsert->CreateParameter(_T(
"ContextID"),adInteger,adParamInput,
sizeof(
int),nStartingRecordID);
195 paramVersion = cmdInsert->CreateParameter(_T(
"Version"),adInteger,adParamInput,
sizeof(
int),1);
196 paramLockFlag = cmdInsert->CreateParameter(_T(
"LockFlag"),adInteger,adParamInput,
sizeof(
int),1);
197 ttparamLockFlag = cmdUpdate->CreateParameter(_T(
"LockFlag"),adInteger,adParamInput,
sizeof(
int),1);
198 paramLockTime = cmdInsert->CreateParameter(_T(
"LockTime"),adInteger,adParamInput,
sizeof(
int),1);
199 paramLockTimeUSec = cmdInsert->CreateParameter(_T(
"LockTimeUSec"),adInteger,adParamInput,
sizeof(
int),1);
200 paramContextData = cmdInsert->CreateParameter(_T(
"ContextData"), adBSTR, adParamInput, SysStringByteLen(vtContextData.bstrVal), vtContextData);
206 cmdInsert->Parameters->Append(paramContextID);
207 cmdInsert->Parameters->Append(paramVersion);
208 cmdInsert->Parameters->Append(paramLockFlag);
209 cmdInsert->Parameters->Append(paramLockTime);
210 cmdInsert->Parameters->Append(paramLockTimeUSec);
214 cmdUpdate->Parameters->Append(paramContextID);
217 cmdSelect->Parameters->Append(paramContextID);
219 cmdDelete->Parameters->Append(paramContextID);
221 while(WaitForSingleObject(pData->hShutdownEvent,0) != WAIT_OBJECT_0)
223 paramContextID->Value = nStartingRecordID++;
225 bool bTimeLatency = (nStartingRecordID == 100) ? TRUE : FALSE;
229 BOOL bSuccess = QueryPerformanceFrequency(&freq);
231 printf(
"Error retrieving frequency: %d\n", GetLastError());
237 for (
int i=0;
i < 20;
i++)
249 QueryPerformanceCounter(&liStartTime);
251 cmdSelect->Execute(NULL, NULL, -1);
254 QueryPerformanceCounter(&liEndTime);
255 printf(
"Read = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
260 QueryPerformanceCounter(&liStartTime);
261 cmdDelete->Execute(NULL,NULL,adExecuteNoRecords);
264 QueryPerformanceCounter(&liEndTime);
265 printf(
"Delete = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
270 QueryPerformanceCounter(&liStartTime);
271 cmdInsert->Execute(NULL,NULL,adExecuteNoRecords);
274 QueryPerformanceCounter(&liEndTime);
275 printf(
"Insert = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
280 QueryPerformanceCounter(&liStartTime);
281 cmdUpdate->Execute(NULL,NULL,adExecuteNoRecords);
284 QueryPerformanceCounter(&liEndTime);
285 printf(
"Update = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
292 nNumCallsProcessed++;
294 InterlockedIncrement(pData->pnNumCallsProcessed);
301 printf(
"%d: \n\t%s\n\t%s\n",
312 int _tmain(
int argc, _TCHAR* argv[])
316 if(lstrcmp(argv[1],_T(
"/?")) == 0)
318 _tprintf(_T(
"InsertRecs [No.Of Threads] [Record Seed No.]\n"));
323 nNumThreads = _ttol(argv[1]);
327 nSeed = _ttol(argv[2]);
328 _tprintf(_T(
"Num of Threads = %d, Seed = %d"), nNumThreads, nSeed);
330 long nNumCallsProcessed = 0;
332 SetConsoleCtrlHandler(ConsoleCtrlHandler,
true);
333 hShutdownEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
335 DWORD dwStartTime = GetTickCount();
337 DWORD dwThreadID = 0;
343 for(
int ij=0;ij<nNumThreads;ij++) {
344 params[ij].hShutdownEvent = hShutdownEvent;
345 params[ij].nStartingRecordNum = (ij*5000) + nSeed;
346 params[ij].pnNumCallsProcessed = &nNumCallsProcessed;
350 for(
int ij=0;ij<nNumThreads;ij++) {
351 hThreads[ij] = CreateThread(NULL,NULL,RuntimeCallContext,¶ms[ij],0,&dwThreadID);
355 WaitForMultipleObjects(nNumThreads,hThreads,TRUE,INFINITE);
356 DWORD dwEndTime = GetTickCount();
358 CloseHandle(hShutdownEvent);
361 _tprintf(_T(
"Time Taken for %d Calls is %ld msec (= %ld calls/sec\n"),
362 nNumCallsProcessed,dwEndTime-dwStartTime, (1000*nNumCallsProcessed/(dwEndTime-dwStartTime)));