MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
benchronja.cpp
1 /*
2  Copyright (C) 2003-2007 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 
20 /* ***************************************************
21  NODEREC
22  Perform benchmark of insert, update and delete transactions
23 
24  Arguments:
25  -t Number of threads to start, default 1
26  -o Number of loops per thread, default 100000
27 
28 
29  * *************************************************** */
30 
31 #include <ndb_global.h>
32 
33 #include <NdbApi.hpp>
34 #include <NdbTest.hpp>
35 #include <NdbOut.hpp>
36 #include <NdbThread.h>
37 #include <NdbSleep.h>
38 #include <NdbMain.h>
39 #include <NdbTimer.hpp>
40 #include <NdbTick.h>
41 #include <random.h>
42 
43 #define MAX_TIMERS 4
44 #define MAXSTRLEN 16
45 #define MAXATTR 64
46 #define MAXTABLES 64
47 #define NDB_MAXTHREADS 256
48 /*
49  NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
50  #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
51  #undef it here lest someone use it by habit and get really funny
52  results. K&R says we may #undef non-existent symbols, so let's go.
53 */
54 #undef MAXTHREADS
55 #define MAXATTRSIZE 8000
56 #define START_TIMER NdbTimer timer; timer.doStart();
57 #define STOP_TIMER timer.doStop();
58 #define START_TIMER_TOP NdbTimer timer_top; timer_top.doStart();
59 #define STOP_TIMER_TOP timer_top.doStop();
60 
61 void* ThreadExec(void*);
62 struct ThreadNdb
63 {
64  int NoOfOps;
65  int ThreadNo;
66  Ndb* NdbRef;
67 };
68 
69 static NdbThread* threadLife[NDB_MAXTHREADS];
70 static unsigned int tNoOfThreads;
71 static unsigned int tNoOfOpsPerExecute;
72 static unsigned int tNoOfRecords;
73 static unsigned int tNoOfOperations;
74 static int ThreadReady[NDB_MAXTHREADS];
75 static int ThreadStart[NDB_MAXTHREADS];
76 
77 NDB_COMMAND(benchronja, "benchronja", "benchronja", "benchronja", 65535){
78  ndb_init();
79 
80  ThreadNdb tabThread[NDB_MAXTHREADS];
81  int i = 0 ;
82  int cont = 0 ;
83  Ndb* pMyNdb = NULL ; //( "TEST_DB" );
84  int tmp = 0 ;
85  int nTest = 0 ;
86  char inp[100] ;
87 
88  tNoOfThreads = 1; // Default Value
89  tNoOfOpsPerExecute = 1; // Default Value
90  tNoOfOperations = 100000; // Default Value
91  tNoOfRecords = 500 ; // Default Value <epaulsa: changed from original 500,000 to match 'initronja's' default
92  i = 1;
93  while (argc > 1)
94  {
95  if (strcmp(argv[i], "-t") == 0){
96  tNoOfThreads = atoi(argv[i+1]);
97  if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS)) goto error_input;
98  }else if (strcmp(argv[i], "-o") == 0){
99  tNoOfOperations = atoi(argv[i+1]);
100  if (tNoOfOperations < 1) goto error_input;
101  }else if (strcmp(argv[i], "-r") == 0){
102  tNoOfRecords = atoi(argv[i+1]);
103  if ((tNoOfRecords < 1) || (tNoOfRecords > 1000000000)) goto error_input;
104  }else if (strcmp(argv[i], "-p") == 0){
105  nTest = atoi(argv[i+1]) ;
106  if (0 > nTest || 18 < nTest) goto error_input ;
107  }else if (strcmp(argv[i], "-c") == 0){
108  tNoOfOpsPerExecute = atoi(argv[i+1]);
109  if ((tNoOfOpsPerExecute < 1) || (tNoOfOpsPerExecute > 1024)) goto error_input;
110  }else{
111  goto error_input;
112  }
113  argc -= 2;
114  i = i + 2;
115  }
116 
117  ndbout << "Initialisation started. " << endl;
118  pMyNdb = new Ndb("TEST_DB") ;
119  pMyNdb->init();
120  ndbout << "Initialisation completed. " << endl;
121 
122  ndbout << endl << "Execute Ronja Benchmark" << endl;
123  ndbout << " NdbAPI node with id = " << pMyNdb->getNodeId() << endl;
124  ndbout << " " << tNoOfThreads << " thread(s) " << endl;
125  ndbout << " " << tNoOfOperations << " transaction(s) per thread and round " << endl;
126 
127  if (pMyNdb->waitUntilReady(120) != 0) {
128  ndbout << "Benchmark failed - NDB is not ready" << endl;
129  delete pMyNdb ;
130  return NDBT_ProgramExit(NDBT_FAILED);
131  }//if
132 
133  NdbThread_SetConcurrencyLevel(2 + tNoOfThreads);
134 
135  for (i = 0; i < tNoOfThreads ; i++) {
136  ThreadReady[i] = 0;
137  ThreadStart[i] = 0;
138  }//for
139 
140  for (i = 0; i < tNoOfThreads ; i++) {
141  tabThread[i].ThreadNo = i;
142  tabThread[i].NdbRef = NULL;
143  tabThread[i].NoOfOps = tNoOfOperations;
144  threadLife[i] = NdbThread_Create(ThreadExec,
145  (void**)&tabThread[i],
146  32768,
147  "RonjaThread",
148  NDB_THREAD_PRIO_LOW);
149  }//for
150 
151  cont = 1;
152  while (cont) {
153  NdbSleep_MilliSleep(10);
154  cont = 0;
155  for (i = 0; i < tNoOfThreads ; i++)
156  if (!ThreadReady[i]) cont = 1;
157  }//while
158 
159  ndbout << "All threads started" << endl;
160 
161  if(!nTest){
162 
163  for (;;){
164 
165  inp[0] = 0;
166  ndbout << endl << "What to do next:" << endl;
167  ndbout << "1 \t=> Perform lookups in short table" << endl;
168  ndbout << "2 \t=> Perform lookups in long table" << endl;
169  ndbout << "3 \t=> Perform updates in short table" << endl;
170  ndbout << "4 \t=> Perform updates in long table" << endl;
171  ndbout << "5 \t=> Perform 50% lookups/50% updates in short table" << endl;
172  ndbout << "6 \t=> Perform 50% lookups/50% updates in long table" << endl;
173  ndbout << "7 \t=> Perform 80% lookups/20% updates in short table" << endl;
174  ndbout << "8 \t=> Perform 80% lookups/20% updates in long table" << endl;
175  ndbout << "9 \t=> Perform 25% lookups short/25% lookups long/25% updates short/25% updates long" << endl;
176  ndbout << "10\t=> Test bug with replicated interpreted updates, short table" << endl;
177  ndbout << "11\t=> Test interpreter functions, short table" << endl;
178  ndbout << "12\t=> Test bug with replicated interpreted updates, long table" << endl;
179  ndbout << "13\t=> Test interpreter functions, long table" << endl;
180  ndbout << "14\t=> Perform lookups in short table, no guess of TC" << endl;
181  ndbout << "15\t=> Perform lookups in long table, no guess of TC" << endl;
182  ndbout << "16\t=> Perform updates in short table, no guess of TC" << endl;
183  ndbout << "17\t=> Perform updates in long table, no guess of TC" << endl;
184  ndbout << "18\t=> Multi record updates of transactions" << endl;
185  ndbout << "All other responses will exit" << endl;
186  ndbout << "_____________________________" << endl << endl ;
187 
188  int inp_i = 0;
189  do {
190  inp[inp_i] = (char) fgetc(stdin);
191  if (inp[inp_i] == '\n' || inp[inp_i] == EOF) {
192  inp[inp_i] ='\0';
193  break;
194  }
195  inp_i++;
196 
197  } while (inp[inp_i - 1] != '\n' && inp[inp_i - 1] != EOF);
198 
199  tmp = atoi(inp);
200 
201  if ((tmp > 18) || (tmp <= 0)) break;
202 
203  ndbout << "Starting test " << tmp << "..." << endl;
204 
205  for (i = 0; i < tNoOfThreads ; i++){ ThreadStart[i] = tmp; }
206 
207  cont = 1;
208  while (cont) {
209  NdbSleep_MilliSleep(10);
210  cont = 0;
211  for (i = 0; i < tNoOfThreads ; i++){
212  if (!ThreadReady[i]) cont = 1;
213  }
214  }//while
215  }//for(;;)
216 
217  }else{
218 
219  if(19 == nTest){
220  ndbout << "Executing all 18 available tests..." << endl << endl;
221  for (int count = 1; count < nTest; count++){
222  ndbout << "Test " << count << endl ;
223  ndbout << "------" << endl << endl ;
224  for (i = 0; i < tNoOfThreads ; i++) { ThreadStart[i] = count ; }
225  cont = 1;
226  while (cont) {
227  NdbSleep_MilliSleep(10);
228  cont = 0;
229  for (i = 0; i < tNoOfThreads ; i++){
230  if (!ThreadReady[i]) cont = 1;
231  }
232  }
233  }//for
234  }else{
235  ndbout << endl << "Executing test " << nTest << endl << endl;
236  for (i = 0; i < tNoOfThreads ; i++) { ThreadStart[i] = nTest ; }
237  cont = 1;
238  while (cont) {
239  NdbSleep_MilliSleep(10);
240  cont = 0;
241  for (i = 0; i < tNoOfThreads ; i++){
242  if (!ThreadReady[i]) cont = 1;
243  }
244  }
245  }//if(18 == nTest)
246  } //if(!nTest)
247 
248  ndbout << "--------------------------------------------------" << endl;
249 
250  for (i = 0; i < tNoOfThreads ; i++) ThreadReady[i] = 0;
251  // Signaling threads to stop
252  for (i = 0; i < tNoOfThreads ; i++) ThreadStart[i] = 999;
253 
254  // Wait for threads to stop
255  cont = 1;
256  do {
257  NdbSleep_MilliSleep(1);
258  cont = 0;
259  for (i = 0; i < tNoOfThreads ; i++){
260  if (ThreadReady[i] == 0) cont = 1;
261  }
262  } while (cont == 1);
263 
264  delete pMyNdb ;
265  ndbout << endl << "Ronja Benchmark completed" << endl;
266  return NDBT_ProgramExit(NDBT_OK) ;
267 
268 error_input:
269  ndbout << endl << " Ivalid parameter(s)" << endl;
270  ndbout << " Usage: benchronja [-t threads][-r rec] [-o ops] [-c ops_per_exec] [-p test], where:" << endl;
271  ndbout << " threads - the number of threads to start; default: 1" << endl;
272  ndbout << " rec - the number of records in the tables; default: 500" << endl;
273  ndbout << " ops - the number of operations per transaction; default: 100000" << endl;
274  ndbout << " ops_per_exec - the number of operations per execution; default: 1" << endl ;
275  ndbout << " test - the number of test to execute; 19 executes all available tests; default: 0"<< endl ;
276  ndbout << " which enters a loop expecting manual input of test number to execute." << endl << endl ;
277  delete pMyNdb ;
278  return NDBT_ProgramExit(NDBT_WRONGARGS) ;
279 
280  }
282 
283 void commitTrans(Ndb* aNdb, NdbConnection* aCon)
284 {
285  int ret = aCon->execute(Commit);
286  assert (ret != -1);
287  aNdb->closeTransaction(aCon);
288 }
289 
290 void rollbackTrans(Ndb* aNdb, NdbConnection* aCon)
291 {
292  int ret = aCon->execute(Rollback);
293  assert (ret != -1);
294  aNdb->closeTransaction(aCon);
295 }
296 
297 void updateNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
298 {
299  NdbOperation* theOperation;
300 
301  *flip = *flip + 1;
302  theOperation = aCon->getNdbOperation("SHORT_REC");
303  theOperation->updateTuple();
304  theOperation->equal((Uint32)0, key);
305  theOperation->setValue((Uint32)1, (char*)flip);
306  int ret = aCon->execute(NoCommit);
307  assert (ret != -1);
308 }
309 
310 void updateNoCommitFail(NdbConnection* aCon, unsigned int key)
311 {
312  NdbOperation* theOperation;
313 
314  Uint32 flip = 0;
315  theOperation = aCon->getNdbOperation("SHORT_REC");
316  theOperation->updateTuple();
317  theOperation->equal((Uint32)0, key);
318  theOperation->setValue((Uint32)1, (char*)flip);
319  int ret = aCon->execute(NoCommit);
320  assert (ret == -1);
321 }
322 
323 void deleteNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
324 {
325  NdbOperation* theOperation;
326 
327  *flip = 0;
328  theOperation = aCon->getNdbOperation("SHORT_REC");
329  theOperation->deleteTuple();
330  theOperation->equal((Uint32)0, key);
331  int ret = aCon->execute(NoCommit);
332  assert (ret != -1);
333 }
334 
335 void insertNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
336 {
337  NdbOperation* theOperation;
338  Uint32 placeholder[100];
339 
340  *flip = *flip + 1;
341  theOperation = aCon->getNdbOperation("SHORT_REC");
342  theOperation->insertTuple();
343  theOperation->equal((Uint32)0, key);
344  theOperation->setValue((Uint32)1, (char*)flip);
345  theOperation->setValue((Uint32)2, (char*)&placeholder[0]);
346  theOperation->setValue((Uint32)3, (char*)&placeholder[0]);
347  int ret = aCon->execute(NoCommit);
348  assert (ret != -1);
349 }
350 
351 void writeNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
352 {
353  NdbOperation* theOperation;
354  Uint32 placeholder[100];
355 
356  *flip = *flip + 1;
357  theOperation = aCon->getNdbOperation("SHORT_REC");
358  theOperation->writeTuple();
359  theOperation->equal((Uint32)0, key);
360  theOperation->setValue((Uint32)1, (char*)flip);
361  theOperation->setValue((Uint32)2, (char*)&placeholder[0]);
362  theOperation->setValue((Uint32)3, (char*)&placeholder[0]);
363  int ret = aCon->execute(NoCommit);
364  assert (ret != -1);
365 }
366 
367 void readNoCommit(NdbConnection* aCon, Uint32* flip, Uint32 key, int expected_ret)
368 {
369  NdbOperation* theOperation;
370  Uint32 readFlip;
371 
372  theOperation = aCon->getNdbOperation("SHORT_REC");
373  theOperation->readTuple();
374  theOperation->equal((Uint32)0, key);
375  theOperation->getValue((Uint32)1, (char*)&readFlip);
376  int ret = aCon->execute(NoCommit);
377  assert (ret == expected_ret);
378  if (ret == 0)
379  assert (*flip == readFlip);
380 }
381 
382 void readDirtyNoCommit(NdbConnection* aCon, Uint32* flip, Uint32 key, int expected_ret)
383 {
384  NdbOperation* theOperation;
385  Uint32 readFlip;
386 
387  theOperation = aCon->getNdbOperation("SHORT_REC");
388  theOperation->committedRead();
389  theOperation->equal((Uint32)0, key);
390  theOperation->getValue((Uint32)1, (char*)&readFlip);
391  int ret = aCon->execute(NoCommit);
392  assert (ret == expected_ret);
393  if (ret == 0)
394  assert (*flip == readFlip);
395 }
396 
397 void readVerify(Ndb* aNdb, Uint32* flip, Uint32 key, int expected_ret)
398 {
399  NdbConnection* theTransaction;
400  theTransaction = aNdb->startTransaction();
401  readNoCommit(theTransaction, flip, key, expected_ret);
402  commitTrans(aNdb, theTransaction);
403 }
404 
405 void readDirty(Ndb* aNdb, Uint32* flip, Uint32 key, int expected_ret)
406 {
407  NdbOperation* theOperation;
408  NdbConnection* theTransaction;
409  Uint32 readFlip;
410 
411  theTransaction = aNdb->startTransaction();
412  theOperation = theTransaction->getNdbOperation("SHORT_REC");
413  theOperation->committedRead();
414  theOperation->equal((Uint32)0, key);
415  theOperation->getValue((Uint32)1, (char*)&readFlip);
416  int ret = theTransaction->execute(Commit);
417  assert (ret == expected_ret);
418  if (ret == 0)
419  assert (*flip == readFlip);
420  aNdb->closeTransaction(theTransaction);
421 }
422 
423 int multiRecordTest(Ndb* aNdb, unsigned int key)
424 {
425  NdbConnection* theTransaction;
426  Uint32 flip = 0;
427  Uint32 save_flip;
428  ndbout << "0" << endl;
429 
430  theTransaction = aNdb->startTransaction();
431 
432  updateNoCommit(theTransaction, &flip, key);
433 
434  readNoCommit(theTransaction, &flip, key, 0);
435 
436  updateNoCommit(theTransaction, &flip, key);
437 
438  readNoCommit(theTransaction, &flip, key, 0);
439 
440  commitTrans(aNdb, theTransaction);
441 
442  ndbout << "1 " << endl;
443 
444  readVerify(aNdb, &flip, key, 0);
445  readDirty(aNdb, &flip, key, 0);
446  save_flip = flip;
447  ndbout << "1.1 " << endl;
448 
449  theTransaction = aNdb->startTransaction();
450 
451  deleteNoCommit(theTransaction, &flip, key);
452 
453  readNoCommit(theTransaction, &flip, key, -1);
454  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
455  readDirtyNoCommit(theTransaction, &flip, key, -1);
456  ndbout << "1.2 " << endl;
457 
458  insertNoCommit(theTransaction, &flip, key);
459 
460  readNoCommit(theTransaction, &flip, key, 0);
461  readDirtyNoCommit(theTransaction, &flip, key, 0);
462  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
463  ndbout << "1.3 " << endl;
464 
465  updateNoCommit(theTransaction, &flip, key);
466 
467  readNoCommit(theTransaction, &flip, key, 0);
468  readDirtyNoCommit(theTransaction, &flip, key, 0);
469  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
470  ndbout << "1.4 " << endl;
471 
472  commitTrans(aNdb, theTransaction);
473 
474  ndbout << "2 " << endl;
475 
476  readDirty(aNdb, &flip, key, 0); // COMMITTED READ!!!
477  readVerify(aNdb, &flip, key, 0);
478 
479  save_flip = flip;
480  theTransaction = aNdb->startTransaction();
481 
482  deleteNoCommit(theTransaction, &flip, key);
483 
484  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
485  readDirtyNoCommit(theTransaction, &flip, key, -1); // COMMITTED READ!!!
486  readNoCommit(theTransaction, &flip, key, -1);
487 
488  insertNoCommit(theTransaction, &flip, key);
489 
490  readNoCommit(theTransaction, &flip, key, 0);
491 
492  updateNoCommit(theTransaction, &flip, key);
493 
494  readNoCommit(theTransaction, &flip, key, 0);
495  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
496  readDirtyNoCommit(theTransaction, &flip, key, 0); // COMMITTED READ!!!
497 
498  deleteNoCommit(theTransaction, &flip, key);
499 
500  readNoCommit(theTransaction, &flip, key, -1);
501  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
502  readDirtyNoCommit(theTransaction, &flip, key, -1);
503 
504  rollbackTrans(aNdb, theTransaction);
505 
506  ndbout << "3 " << endl;
507 
508  flip = save_flip;
509  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
510  readVerify(aNdb, &flip, key, 0);
511 
512  theTransaction = aNdb->startTransaction();
513 
514  updateNoCommit(theTransaction, &flip, key);
515 
516  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
517  readDirtyNoCommit(theTransaction, &flip, key, 0);
518  readNoCommit(theTransaction, &flip, key, 0);
519 
520  deleteNoCommit(theTransaction, &flip, key);
521 
522  readNoCommit(theTransaction, &flip, key, -1);
523  readDirtyNoCommit(theTransaction, &flip, key, -1);
524  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
525 
526  insertNoCommit(theTransaction, &flip, key);
527 
528  readNoCommit(theTransaction, &flip, key, 0);
529  readDirtyNoCommit(theTransaction, &flip, key, 0);
530  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
531 
532  updateNoCommit(theTransaction, &flip, key);
533 
534  readNoCommit(theTransaction, &flip, key, 0);
535  readDirtyNoCommit(theTransaction, &flip, key, 0);
536  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
537 
538  deleteNoCommit(theTransaction, &flip, key);
539 
540  readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
541  readNoCommit(theTransaction, &flip, key, -1);
542  readDirtyNoCommit(theTransaction, &flip, key, -1);
543 
544  commitTrans(aNdb, theTransaction);
545 
546  ndbout << "4 " << endl;
547 
548  readVerify(aNdb, &flip, key, -1);
549 
550  theTransaction = aNdb->startTransaction();
551 
552  insertNoCommit(theTransaction, &flip, key);
553 
554  readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
555  readNoCommit(theTransaction, &flip, key, 0);
556  readDirtyNoCommit(theTransaction, &flip, key, 0);
557 
558  deleteNoCommit(theTransaction, &flip, key);
559 
560  readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
561  readNoCommit(theTransaction, &flip, key, -1);
562  readDirtyNoCommit(theTransaction, &flip, key, -1);
563 
564  insertNoCommit(theTransaction, &flip, key);
565 
566  readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
567  readNoCommit(theTransaction, &flip, key, 0);
568  readDirtyNoCommit(theTransaction, &flip, key, 0);
569 
570  updateNoCommit(theTransaction, &flip, key);
571 
572  readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
573  readNoCommit(theTransaction, &flip, key, 0);
574  readDirtyNoCommit(theTransaction, &flip, key, 0);
575 
576  deleteNoCommit(theTransaction, &flip, key);
577 
578  readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
579  readNoCommit(theTransaction, &flip, key, -1);
580  readDirtyNoCommit(theTransaction, &flip, key, -1);
581 
582  commitTrans(aNdb, theTransaction);
583 
584  ndbout << "5 " << endl;
585 
586  readDirty(aNdb, &flip, key, -1); // COMMITTED READ!!!
587  readVerify(aNdb, &flip, key, -1);
588 
589  theTransaction = aNdb->startTransaction();
590 
591  insertNoCommit(theTransaction, &flip, key);
592 
593  readDirty(aNdb, &flip, key, -1); // COMMITTED READ!!!
594  readDirtyNoCommit(theTransaction, &flip, key, 0); // COMMITTED READ!!!
595 
596  commitTrans(aNdb, theTransaction);
597  readDirty(aNdb, &flip, key, 0); // COMMITTED READ!!!
598 
599  ndbout << "6 " << endl;
600 
601  theTransaction = aNdb->startTransaction();
602 
603  deleteNoCommit(theTransaction, &flip, key);
604  updateNoCommitFail(theTransaction, key);
605  rollbackTrans(aNdb, theTransaction);
606  return 0;
607 }
608 
609 int lookup(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess){
610 
611  int placeholder[500];
612  unsigned int flip, count;
613  int ret_value, i;
614  NdbConnection* theTransaction;
615  NdbOperation* theOperation;
616  if ( !aNdb ) return -1 ;
617 
618  if (guess != 0)
619  theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);
620  else
621  theTransaction = aNdb->startTransaction();
622 
623  for (i = 0; i < tNoOfOpsPerExecute; i++) {
624  if (long_short == 0)
625  theOperation = theTransaction->getNdbOperation("SHORT_REC");
626  else
627  theOperation = theTransaction->getNdbOperation("LONG_REC");
628  if (theOperation == NULL) {
629  ndbout << "Table missing" << endl;
630  aNdb->closeTransaction(theTransaction) ;
631  return -1;
632  }//if
633  theOperation->simpleRead();
634  theOperation->equal((Uint32)0, key);
635  theOperation->getValue((Uint32)1, (char*)&flip);
636  theOperation->getValue((Uint32)2, (char*)&count);
637  if (theOperation->getValue((Uint32)3, (char*)&placeholder[0]) == NULL) {
638  ndbout << "Error in definition phase = " << theTransaction->getNdbError() << endl;
639  aNdb->closeTransaction(theTransaction);
640  return -1;
641  }//if
642  }//for
643  ret_value = theTransaction->execute(Commit);
644  if (ret_value == -1)
645  ndbout << "Error in lookup:" << theTransaction->getNdbError() << endl;
646  aNdb->closeTransaction(theTransaction);
647  return ret_value;
648 }//lookup()
649 
650 int update(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess)
651 {
652  int placeholder[500];
653  int ret_value, i;
654  unsigned int flip, count;
655  NdbConnection* theTransaction;
656  NdbOperation* theOperation;
657 
658  if ( !aNdb ) return -1 ;
659 
660  if (guess != 0)
661  theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);
662  else
663  theTransaction = aNdb->startTransaction();
664 
665  for (i = 0; i < tNoOfOpsPerExecute; i++) {
666  if (long_short == 0)
667  theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
668  else
669  theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
670  if (theOperation == NULL) {
671  ndbout << "Table missing" << endl;
672  aNdb->closeTransaction(theTransaction) ;
673  delete aNdb ;
674  return -1;
675  }//if
676  theOperation->interpretedUpdateTuple(); // Send interpreted program to NDB kernel
677  theOperation->equal((Uint32)0, key); // Search key
678  theOperation->getValue((Uint32)1, (char*)&flip); // Read value of flip
679  theOperation->getValue((Uint32)2, (char*)&count); // Read value of count
680  theOperation->getValue((Uint32)3, (char*)&placeholder[0]); // Read value of placeholder
681  theOperation->load_const_u32((Uint32)1, (Uint32)0); // Load register 1 with 0
682  theOperation->read_attr((Uint32)1, (Uint32)2); // Read Flip value into register 2
683  theOperation->branch_eq((Uint32)1, (Uint32)2, (Uint32)0); // If Flip (register 2) == 0 (register 1) goto label 0
684  theOperation->branch_label((Uint32)1); // Goto label 1
685  theOperation->def_label((Uint32)0); // Define label 0
686  theOperation->load_const_u32((Uint32)1, (Uint32)1); // Load register 1 with 1
687  theOperation->def_label((Uint32)1); // Define label 0
688  theOperation->write_attr((Uint32)1, (Uint32)1); // Write 1 (register 1) into Flip
689  ret_value = theOperation->incValue((Uint32)2, (Uint32)1); // Increment Count by 1
690  if (ret_value == -1) {
691  ndbout << "Error in definition phase " << endl;
692  aNdb->closeTransaction(theTransaction);
693  return ret_value;
694  }//if
695  }//for
696  ret_value = theTransaction->execute(Commit); // Perform the actual read and update
697  if (ret_value == -1) {
698  ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
699  aNdb->closeTransaction(theTransaction); // < epaulsa
700  return ret_value ;
701  }//if
702  aNdb->closeTransaction(theTransaction);
703  return ret_value;
704 }//update()
705 
706 int update_bug(Ndb* aNdb, unsigned int key, unsigned int long_short)
707 {
708  int placeholder[500];
709  int ret_value, i;
710  unsigned int flip, count;
711  NdbConnection* theTransaction;
712  NdbOperation* theOperation;
713 
714  if ( !aNdb ) return -1 ;
715 
716  theTransaction = aNdb->startTransaction();
717  for (i = 0; i < tNoOfOpsPerExecute; i++) {
718  if (long_short == 0)
719  theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
720  else
721  theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
722  if (theOperation == NULL) {
723  ndbout << "Table missing" << endl;
724  aNdb->closeTransaction(theTransaction) ;
725  return -1;
726  }//if
727  theOperation->interpretedUpdateTuple(); // Send interpreted program to NDB kernel
728  theOperation->equal((Uint32)0, key); // Search key
729  theOperation->getValue((Uint32)1, (char*)&flip); // Read value of flip
730  theOperation->getValue((Uint32)2, (char*)&count); // Read value of count
731  theOperation->getValue((Uint32)3, (char*)&placeholder[0]); // Read value of placeholder
732  theOperation->load_const_u32((Uint32)1, (Uint32)0); // Load register 1 with 0
733  theOperation->read_attr((Uint32)1, (Uint32)2); // Read Flip value into register 2
734  theOperation->branch_eq((Uint32)1, (Uint32)2, (Uint32)0); // If Flip (register 2) == 0 (register 1) goto label 0
735  theOperation->branch_label((Uint32)1); // Goto label 1
736  theOperation->def_label((Uint32)0); // Define label 0
737  theOperation->load_const_u32((Uint32)1, (Uint32)1); // Load register 1 with 1
738  theOperation->def_label((Uint32)1); // Define label 0
739  theOperation->write_attr((Uint32)1, (Uint32)1); // Write 1 (register 1) into Flip
740  ret_value = theOperation->incValue((Uint32)2, (Uint32)1); // Increment Count by 1
741  if (ret_value == -1) {
742  ndbout << "Error in definition phase " << endl;
743  aNdb->closeTransaction(theTransaction);
744  return ret_value;
745  }//if
746  }//for
747  ret_value = theTransaction->execute(NoCommit); // Perform the actual read and update
748  if (ret_value == -1) {
749  ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
750  aNdb->closeTransaction(theTransaction);
751  return ret_value ;
752  }//if
753  aNdb->closeTransaction(theTransaction);
754  return ret_value;
755 }//update_bug()
756 
757 int update_interpreter_test(Ndb* aNdb, unsigned int key, unsigned int long_short)
758 {
759  int placeholder[500];
760  int ret_value, i;
761  unsigned int flip, count;
762  NdbConnection* theTransaction;
763  NdbOperation* theOperation;
764  Uint32 Tlabel = 0;
765 
766  if ( !aNdb ) return -1 ;
767 
768 //------------------------------------------------------------------------------
769 // Start the transaction and get a unique transaction id
770 //------------------------------------------------------------------------------
771  theTransaction = aNdb->startTransaction();
772  for (i = 0; i < tNoOfOpsPerExecute; i++) {
773 //------------------------------------------------------------------------------
774 // Get the proper table object and load schema information if not already
775 // present.
776 //------------------------------------------------------------------------------
777  if (long_short == 0)
778  theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
779  else
780  theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
781  if (theOperation == NULL) {
782  ndbout << "Table missing" << endl;
783  aNdb->closeTransaction(theTransaction) ;
784  return -1;
785  }//if
786 //------------------------------------------------------------------------------
787 // Define the operation type and the tuple key (primary key in this case).
788 //------------------------------------------------------------------------------
789  theOperation->interpretedUpdateTuple(); // Send interpreted program to NDB kernel
790  theOperation->equal((Uint32)0, key); // Search key
791 
792 //------------------------------------------------------------------------------
793 // Perform initial read of attributes before updating them
794 //------------------------------------------------------------------------------
795  theOperation->getValue((Uint32)1, (char*)&flip); // Read value of flip
796  theOperation->getValue((Uint32)2, (char*)&count); // Read value of count
797  theOperation->getValue((Uint32)3, (char*)&placeholder[0]); // Read value of placeholder
798 
799 //------------------------------------------------------------------------------
800 // Test that the various branch operations can handle things correctly.
801 // Test first 2 + 3 = 5 with 32 bit registers
802 // Next test the same with 32 bit + 64 bit = 64
803 //------------------------------------------------------------------------------
804  theOperation->load_const_u32((Uint32)4, (Uint32)0); // Load register 4 with 0
805 
806  theOperation->load_const_u32((Uint32)0, (Uint32)0);
807  theOperation->load_const_u32((Uint32)1, (Uint32)3);
808  theOperation->load_const_u32((Uint32)2, (Uint32)5);
809  theOperation->load_const_u32((Uint32)3, (Uint32)1);
810  theOperation->def_label(Tlabel++);
811  theOperation->def_label(Tlabel++);
812  theOperation->sub_reg((Uint32)2, (Uint32)3, (Uint32)2);
813  theOperation->branch_ne((Uint32)2, (Uint32)0, (Uint32)0);
814  theOperation->load_const_u32((Uint32)2, (Uint32)5);
815  theOperation->sub_reg((Uint32)1, (Uint32)3, (Uint32)1);
816  theOperation->branch_ne((Uint32)1, (Uint32)0, (Uint32)1);
817 
818  theOperation->load_const_u32((Uint32)1, (Uint32)2); // Load register 1 with 2
819  theOperation->load_const_u32((Uint32)2, (Uint32)3); // Load register 2 with 3
820  theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1); // 2+3 = 5 into reg 1
821  theOperation->load_const_u32((Uint32)2, (Uint32)5); // Load register 2 with 5
822 
823  theOperation->def_label(Tlabel++);
824 
825  theOperation->branch_eq((Uint32)1, (Uint32)2, Tlabel);
826  theOperation->interpret_exit_nok((Uint32)6001);
827 
828  theOperation->def_label(Tlabel++);
829  theOperation->branch_ne((Uint32)1, (Uint32)2, Tlabel);
830  theOperation->branch_label(Tlabel + 1);
831  theOperation->def_label(Tlabel++);
832  theOperation->interpret_exit_nok((Uint32)6002);
833 
834  theOperation->def_label(Tlabel++);
835  theOperation->branch_lt((Uint32)1, (Uint32)2, Tlabel);
836  theOperation->branch_label(Tlabel + 1);
837  theOperation->def_label(Tlabel++);
838  theOperation->interpret_exit_nok((Uint32)6003);
839 
840  theOperation->def_label(Tlabel++);
841  theOperation->branch_gt((Uint32)1, (Uint32)2, Tlabel);
842  theOperation->branch_label(Tlabel + 1);
843  theOperation->def_label(Tlabel++);
844  theOperation->interpret_exit_nok((Uint32)6005);
845 
846  theOperation->def_label(Tlabel++);
847  theOperation->branch_eq_null((Uint32)1, Tlabel);
848  theOperation->branch_label(Tlabel + 1);
849  theOperation->def_label(Tlabel++);
850  theOperation->interpret_exit_nok((Uint32)6006);
851 
852  theOperation->def_label(Tlabel++);
853  theOperation->branch_ne_null((Uint32)1,Tlabel);
854  theOperation->interpret_exit_nok((Uint32)6007);
855 
856  theOperation->def_label(Tlabel++);
857  theOperation->branch_ge((Uint32)1, (Uint32)2, Tlabel);
858  theOperation->interpret_exit_nok((Uint32)6008);
859 
860  theOperation->def_label(Tlabel++);
861  theOperation->branch_eq_null((Uint32)6,Tlabel);
862  theOperation->interpret_exit_nok((Uint32)6009);
863 
864  theOperation->def_label(Tlabel++);
865  theOperation->branch_ne_null((Uint32)6, Tlabel);
866  theOperation->branch_label(Tlabel + 1);
867  theOperation->def_label(Tlabel++);
868  theOperation->interpret_exit_nok((Uint32)6010);
869 
870  theOperation->def_label(Tlabel++);
871 
872  theOperation->load_const_u32((Uint32)5, (Uint32)1);
873  theOperation->add_reg((Uint32)4, (Uint32)5, (Uint32)4);
874 
875  theOperation->load_const_u32((Uint32)5, (Uint32)1);
876  theOperation->branch_eq((Uint32)4, (Uint32)5, Tlabel);
877 
878 
879  theOperation->load_const_u32((Uint32)5, (Uint32)2);
880  theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 1));
881 
882  theOperation->load_const_u32((Uint32)5, (Uint32)3);
883  theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 2));
884 
885  theOperation->load_const_u32((Uint32)5, (Uint32)4);
886  theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 3));
887 
888  theOperation->branch_label(Tlabel + 4);
889 
890  theOperation->def_label(Tlabel++);
891  theOperation->load_const_u32((Uint32)1, (Uint32)200000);
892  theOperation->load_const_u32((Uint32)2, (Uint32)300000);
893  theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
894  theOperation->load_const_u32((Uint32)2, (Uint32)500000);
895  theOperation->branch_label((Uint32)2);
896 
897  theOperation->def_label(Tlabel++);
898  theOperation->load_const_u32((Uint32)1, (Uint32)200000);
899  theOperation->load_const_u32((Uint32)2, (Uint32)300000);
900  theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
901  theOperation->load_const_u32((Uint32)2, (Uint32)500000);
902  theOperation->branch_label((Uint32)2);
903 
904  theOperation->def_label(Tlabel++);
905  theOperation->load_const_u32((Uint32)1, (Uint32)2);
906  Uint64 x = 0;
907  theOperation->load_const_u64((Uint32)2, (Uint64)(x - 1));
908  theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
909  theOperation->load_const_u32((Uint32)2, (Uint32)1);
910  theOperation->branch_label((Uint32)2);
911 
912  theOperation->def_label(Tlabel++);
913  theOperation->load_const_u32((Uint32)1, (Uint32)2);
914  theOperation->load_const_u64((Uint32)2, (Uint64)(x - 1));
915  theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
916  theOperation->load_const_u64((Uint32)2, (Uint64)1);
917  theOperation->branch_label((Uint32)2);
918 
919  theOperation->def_label(Tlabel++);
920  theOperation->read_attr((Uint32)1, (Uint32)2);
921  theOperation->branch_eq((Uint32)1, (Uint32)2, Tlabel);
922  theOperation->load_const_u32((Uint32)1, (Uint32)0);
923  theOperation->branch_label(Tlabel + 1);
924  theOperation->def_label(Tlabel++);
925  theOperation->load_const_u32((Uint32)1, (Uint32)1);
926  theOperation->def_label(Tlabel++);
927  theOperation->write_attr((Uint32)1, (Uint32)1);
928  ret_value = theOperation->incValue((Uint32)2, (Uint32)1);
929  if (ret_value == -1) {
930  ndbout << "Error in definition phase " << endl;
931  ndbout << "Error = " << theOperation->getNdbError() << " on line = " << theOperation->getNdbErrorLine() << endl;
932  aNdb->closeTransaction(theTransaction);
933  return ret_value;
934  }//if
935  }//for
936 //------------------------------------------------------------------------------
937 //------------------------------------------------------------------------------
938  ret_value = theTransaction->execute(Commit); // Perform the actual read and update
939  if (ret_value == -1) {
940  ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
941  aNdb->closeTransaction(theTransaction); // < epaulsa
942  return ret_value ;
943  }//if
944 //------------------------------------------------------------------------------
945 //------------------------------------------------------------------------------
946  aNdb->closeTransaction(theTransaction);
947  return ret_value;
948 }//update_interpreter_test()
949 
950 void* ThreadExec(void* ThreadData){
951 
952  ThreadNdb* tabThread = (ThreadNdb*)ThreadData;
953  Ndb* pMyNdb = NULL ;
954  myRandom48Init(NdbTick_CurrentMillisecond());
955 
956  int Tsuccess = 0 ;
957  int check = 0 ;
958  int loop_count_ops = 0;
959  int count, i, Ti;
960  int tType = 0 ;
961  int remType = 0 ;
962  unsigned int thread_no = 0 ;
963  unsigned long total_milliseconds;
964  unsigned int key = 0 ;
965  unsigned int prob = 0 ;
966  unsigned long transaction_time = 0 ;
967  unsigned long transaction_max_time = 0 ;
968  unsigned long min_time, max_time[MAX_TIMERS];
969  double mean_time, mean_square_time, std_time;
970 
971  thread_no = tabThread->ThreadNo;
972  pMyNdb = tabThread->NdbRef;
973  if (!pMyNdb) {
974  pMyNdb = new Ndb( "TEST_DB" );
975  pMyNdb->init();
976  }//if
977 
978  for (;;){
979 
980  min_time = 0xFFFFFFFF;
981  //for (Ti = 0; Ti < MAX_TIMERS ; Ti++) max_time[Ti] = 0;
982  memset(&max_time, 0, sizeof max_time) ;
983  mean_time = 0;
984  mean_square_time = 0;
985  ThreadReady[thread_no] = 1;
986 
987  while (!ThreadStart[thread_no]){
988  NdbSleep_MilliSleep(1);
989  }
990 
991  // Check if signal to exit is received
992  if (ThreadStart[thread_no] == 999){
993  delete pMyNdb;
994  pMyNdb = NULL ;
995  ThreadReady[thread_no] = 1;
996  return 0 ;
997  }//if
998 
999  tType = ThreadStart[thread_no];
1000  remType = tType;
1001  ThreadStart[thread_no] = 0;
1002  ThreadReady[thread_no] = 0 ;
1003 
1004  // Start transaction, type of transaction
1005  // is received in the array ThreadStart
1006  loop_count_ops = tNoOfOperations;
1007 
1008  START_TIMER_TOP
1009  for (count=0 ; count < loop_count_ops ; count++) {
1010 
1011  Tsuccess = 0;
1012 //----------------------------------------------------
1013 // Generate a random key between 0 and tNoOfRecords - 1
1014 //----------------------------------------------------
1015  key = myRandom48(tNoOfRecords);
1016 //----------------------------------------------------
1017 // Start time measurement of transaction.
1018 //----------------------------------------------------
1019  START_TIMER
1020  //do {
1021  switch (remType){
1022  case 1:
1023 //----------------------------------------------------
1024 // Only lookups in short record table
1025 //----------------------------------------------------
1026  Tsuccess = lookup(pMyNdb, key, 0, 1);
1027  break;
1028 
1029  case 2:
1030 //----------------------------------------------------
1031 // Only lookups in long record table
1032 //----------------------------------------------------
1033  Tsuccess = lookup(pMyNdb, key, 1, 1);
1034  break;
1035  case 3:
1036 //----------------------------------------------------
1037 // Only updates in short record table
1038 //----------------------------------------------------
1039  Tsuccess = update(pMyNdb, key, 0, 1);
1040  break;
1041  case 4:
1042 //----------------------------------------------------
1043 // Only updates in long record table
1044 //----------------------------------------------------
1045  Tsuccess = update(pMyNdb, key, 1, 1);
1046  break;
1047  case 5:
1048 //----------------------------------------------------
1049 // 50% read/50 % update in short record table
1050 //----------------------------------------------------
1051  prob = myRandom48(100);
1052  if (prob < 50)
1053  Tsuccess = update(pMyNdb, key, 0, 1);
1054  else
1055  Tsuccess = lookup(pMyNdb, key, 0, 1);
1056  break;
1057  case 6:
1058 //----------------------------------------------------
1059 // 50% read/50 % update in long record table
1060 //----------------------------------------------------
1061  prob = myRandom48(100);
1062  if (prob < 50)
1063  Tsuccess = update(pMyNdb, key, 1, 1);
1064  else
1065  Tsuccess = lookup(pMyNdb, key, 1, 1);
1066  break;
1067  case 7:
1068 //----------------------------------------------------
1069 // 80 read/20 % update in short record table
1070 //----------------------------------------------------
1071  prob = myRandom48(100);
1072  if (prob < 20)
1073  Tsuccess = update(pMyNdb, key, 0, 1);
1074  else
1075  Tsuccess = lookup(pMyNdb, key, 0, 1);
1076  break;
1077  case 8:
1078 //----------------------------------------------------
1079 // 80 read/20 % update in long record table
1080 //----------------------------------------------------
1081  prob = myRandom48(100);
1082  if (prob < 20)
1083  Tsuccess = update(pMyNdb, key, 1, 1);
1084  else
1085  Tsuccess = lookup(pMyNdb, key, 1, 1);
1086  break;
1087  case 9:
1088 //----------------------------------------------------
1089 // 25 read short/25 % read long/25 % update short/25 % update long
1090 //----------------------------------------------------
1091  prob = myRandom48(100);
1092  if (prob < 25)
1093  Tsuccess = update(pMyNdb, key, 0, 1);
1094  else if (prob < 50)
1095  Tsuccess = update(pMyNdb, key, 1, 1);
1096  else if (prob < 75)
1097  Tsuccess = lookup(pMyNdb, key, 0, 1);
1098  else
1099  Tsuccess = lookup(pMyNdb, key, 1, 1);
1100  break;
1101  case 10:
1102 //----------------------------------------------------
1103 // Test bug with replicated interpreted update, short table
1104 //----------------------------------------------------
1105  Tsuccess = update_bug(pMyNdb, key, 0);
1106  break;
1107  case 11:
1108 //----------------------------------------------------
1109 // Test interpreter functions, short table
1110 //----------------------------------------------------
1111  Tsuccess = update_interpreter_test(pMyNdb, key, 0);
1112  break;
1113  case 12:
1114 //----------------------------------------------------
1115 // Test bug with replicated interpreted update, long table
1116 //----------------------------------------------------
1117  Tsuccess = update_bug(pMyNdb, key, 1);
1118  break;
1119  case 13:
1120 //----------------------------------------------------
1121 // Test interpreter functions, long table
1122 //----------------------------------------------------
1123  Tsuccess = update_interpreter_test(pMyNdb, key, 1);
1124  break;
1125  case 14:
1126 //----------------------------------------------------
1127 // Only lookups in short record table
1128 //----------------------------------------------------
1129  Tsuccess = lookup(pMyNdb, key, 0, 0);
1130  break;
1131  case 15:
1132 //----------------------------------------------------
1133 // Only lookups in long record table
1134 //----------------------------------------------------
1135  Tsuccess = lookup(pMyNdb, key, 1, 0);
1136  break;
1137  case 16:
1138 //----------------------------------------------------
1139 // Only updates in short record table
1140 //----------------------------------------------------
1141  Tsuccess = update(pMyNdb, key, 0, 0);
1142  break;
1143  case 17:
1144 //----------------------------------------------------
1145 // Only updates in long record table
1146 //----------------------------------------------------
1147  Tsuccess = update(pMyNdb, key, 1, 0);
1148  break;
1149  case 18:
1150  Tsuccess = multiRecordTest(pMyNdb, key);
1151  break;
1152  default:
1153  break;
1154  }//switch
1155  //} while (0);//
1156  if(-1 == Tsuccess) {
1157  NDBT_ProgramExit(NDBT_FAILED);
1158  exit(-1);
1159  } // for
1160 //----------------------------------------------------
1161 // Stop time measurement of transaction.
1162 //----------------------------------------------------
1163  STOP_TIMER
1164  transaction_time = (unsigned long)timer.elapsedTime() ;//stopTimer(&theStartTime);
1165 //----------------------------------------------------
1166 // Perform calculations of time measurements.
1167 //----------------------------------------------------
1168  transaction_max_time = transaction_time;
1169  for (Ti = 0; Ti < MAX_TIMERS; Ti++) {
1170  if (transaction_max_time > max_time[Ti]) {
1171  Uint32 tmp = max_time[Ti];
1172  max_time[Ti] = transaction_max_time;
1173  transaction_max_time = tmp;
1174  }//if
1175  }//if
1176  if (transaction_time < min_time) min_time = transaction_time;
1177  mean_time = (double)transaction_time + mean_time;
1178  mean_square_time = (double)(transaction_time * transaction_time) + mean_square_time;
1179  }//for
1180 //----------------------------------------------------
1181 // Calculate mean and standard deviation
1182 //----------------------------------------------------
1183  STOP_TIMER_TOP
1184  total_milliseconds = (unsigned long)timer_top.elapsedTime() ;//stopTimer(&total_time);
1185  mean_time = mean_time / loop_count_ops;
1186  mean_square_time = mean_square_time / loop_count_ops;
1187  std_time = sqrt(mean_square_time - (mean_time * mean_time));
1188 //----------------------------------------------------
1189 // Report statistics
1190 //----------------------------------------------------
1191  ndbout << "Thread = " << thread_no << " reporting:" << endl ;
1192  ndbout << "------------------------------" << endl ;
1193  ndbout << "Total time is " << (unsigned int)(total_milliseconds /1000);
1194  ndbout << " seconds and " << (unsigned int)(total_milliseconds % 1000);
1195  ndbout << " milliseconds" << endl;
1196  ndbout << "Minimum time = " << (unsigned int)min_time << " milliseconds" << endl;
1197  for (Ti = 0; Ti < MAX_TIMERS; Ti++) {
1198  ndbout << "Maximum timer " << Ti << " = " << (unsigned int)max_time[Ti] << " milliseconds" << endl;
1199  ndbout << "Mean time = " << (unsigned int)mean_time << " milliseconds" << endl;
1200  ndbout << "Standard deviation on time = " << (unsigned int)std_time;
1201  ndbout << " milliseconds" << endl << endl ;
1202  }//for
1203  ndbout << endl ;
1204 
1205  } // for(;;)
1206 
1207  delete pMyNdb ;
1208  return 0 ;
1209 }
1210