23 #include <ndb_global.h>
25 #include "dbGenerator.h"
42 static void getRandomSubscriberNumber(SubscriberNumber number);
43 static void getRandomServerId(ServerId *serverId);
44 static void getRandomChangedBy(ChangedBy changedBy);
55 static void doTransaction_T1(
Ndb * pNDB,
ThreadData * td,
int async);
56 static void doTransaction_T2(
Ndb * pNDB,
ThreadData * td,
int async);
57 static void doTransaction_T3(
Ndb * pNDB,
ThreadData * td,
int async);
58 static void doTransaction_T4(
Ndb * pNDB,
ThreadData * td,
int async);
59 static void doTransaction_T5(
Ndb * pNDB,
ThreadData * td,
int async);
80 static unsigned maxsize = 0;
92 static void getRandomSubscriberNumber(SubscriberNumber number)
95 char sbuf[SUBSCRIBER_NUMBER_LENGTH + 1];
96 tmp = myRandom48(NO_OF_SUBSCRIBERS);
97 sprintf(sbuf,
"%.*d", SUBSCRIBER_NUMBER_LENGTH, tmp);
98 memcpy(number, sbuf, SUBSCRIBER_NUMBER_LENGTH);
101 static void getRandomServerId(ServerId *serverId)
103 *serverId = myRandom48(NO_OF_SERVERS);
106 static void getRandomChangedBy(ChangedBy changedBy)
108 memset(changedBy, myRandom48(26)+
'A', CHANGED_BY_LENGTH);
109 changedBy[CHANGED_BY_LENGTH] = 0;
113 static void getRandomChangedTime(ChangedTime changedTime)
115 memset(changedTime, myRandom48(26)+
'A', CHANGED_TIME_LENGTH);
116 changedTime[CHANGED_TIME_LENGTH] = 0;
123 trans->branchExecuted = 0;
124 trans->rollbackExecuted = 0;
125 trans->latencyCounter = myRandom48(127);
126 trans->latency.reset();
131 return(list->numberInList == SESSION_LIST_LENGTH);
136 return(list->numberInList == 0);
140 SubscriberNumber number,
144 if( listFull(list) )
return;
146 e = &list->list[list->writeIndex];
148 strcpy(e->subscriberNumber, number);
149 e->serverId = serverId;
151 list->writeIndex = (list->writeIndex + 1) % SESSION_LIST_LENGTH;
152 list->numberInList++;
154 if( list->numberInList > maxsize )
155 maxsize = list->numberInList;
160 if( listEmpty(list) )
return(0);
162 return(&list->list[list->readIndex]);
167 if( listEmpty(list) )
return;
169 list->readIndex = (list->readIndex + 1) % SESSION_LIST_LENGTH;
170 list->numberInList--;
177 if( initSequence(&gen->transactionSequence,
178 transactionDefinition) != 0 ) {
179 ndbout_c(
"could not set the transaction types");
183 if( initSequence(&gen->rollbackSequenceT4,
184 rollbackDefinition) != 0 ) {
185 ndbout_c(
"could not set the rollback sequence");
189 if( initSequence(&gen->rollbackSequenceT5,
190 rollbackDefinition) != 0 ) {
191 ndbout_c(
"could not set the rollback sequence");
195 for(i = 0; i < NUM_TRANSACTION_TYPES; i++ )
196 clearTransaction(&gen->transactions[i]);
198 gen->totalTransactions = 0;
200 gen->activeSessions.numberInList = 0;
201 gen->activeSessions.readIndex = 0;
202 gen->activeSessions.writeIndex = 0;
208 doOneTransaction(
ThreadData * td,
int p,
int millis,
int minEvents,
int force)
211 unsigned int transactionType;
216 for(i = 0; i<p; i++){
217 if(td[i].runState == Runnable){
218 transactionType = getNextRandom(&td[i].generator.transactionSequence);
220 switch(transactionType) {
222 doTransaction_T1(td[i].pNDB, &td[i], async);
225 doTransaction_T2(td[i].pNDB, &td[i], async);
228 doTransaction_T3(td[i].pNDB, &td[i], async);
231 doTransaction_T4(td[i].pNDB, &td[i], async);
234 doTransaction_T5(td[i].pNDB, &td[i], async);
237 ndbout_c(
"Unknown transaction type: %d", transactionType);
253 getRandomSubscriberNumber(td->transactionData.number);
254 getRandomChangedBy(td->transactionData.changed_by);
256 sizeof(td->transactionData.changed_time),
257 "%ld - %u", td->changedTime++, (
unsigned)myRandom48(65536*1024));
259 td->transactionData.location = td->transactionData.changed_by[0];
265 td->generator.transactions[0].startLatency();
267 start_T1(pNDB, td, async);
277 getRandomSubscriberNumber(td->transactionData.number);
283 td->generator.transactions[1].startLatency();
285 start_T2(pNDB, td, async);
297 se = getNextSession(&td->generator.activeSessions);
299 strcpy(td->transactionData.number, se->subscriberNumber);
300 td->transactionData.server_id = se->serverId;
301 td->transactionData.sessionElement = 1;
303 getRandomSubscriberNumber(td->transactionData.number);
304 getRandomServerId(&td->transactionData.server_id);
305 td->transactionData.sessionElement = 0;
308 td->transactionData.server_bit = (1 << td->transactionData.server_id);
314 td->generator.transactions[2].startLatency();
315 start_T3(pNDB, td, async);
325 getRandomSubscriberNumber(td->transactionData.number);
326 getRandomServerId(&td->transactionData.server_id);
328 td->transactionData.server_bit = (1 << td->transactionData.server_id);
329 td->transactionData.do_rollback =
330 getNextRandom(&td->generator.rollbackSequenceT4);
332 memset(td->transactionData.session_details+2,
333 myRandom48(26)+
'A', SESSION_DETAILS_LENGTH-3);
334 td->transactionData.session_details[SESSION_DETAILS_LENGTH-1] = 0;
335 int2store(td->transactionData.session_details,SESSION_DETAILS_LENGTH-2);
341 td->generator.transactions[3].startLatency();
342 start_T4(pNDB, td, async);
350 se = getNextSession(&td->generator.activeSessions);
352 strcpy(td->transactionData.number, se->subscriberNumber);
353 td->transactionData.server_id = se->serverId;
354 td->transactionData.sessionElement = 1;
357 getRandomSubscriberNumber(td->transactionData.number);
358 getRandomServerId(&td->transactionData.server_id);
359 td->transactionData.sessionElement = 0;
362 td->transactionData.server_bit = (1 << td->transactionData.server_id);
363 td->transactionData.do_rollback
364 = getNextRandom(&td->generator.rollbackSequenceT5);
370 td->generator.transactions[4].startLatency();
371 start_T5(pNDB, td, async);
376 data->generator.transactions[0].stopLatency();
377 data->generator.transactions[0].count++;
380 data->generator.totalTransactions++;
385 data->generator.transactions[1].stopLatency();
386 data->generator.transactions[1].count++;
389 data->generator.totalTransactions++;
395 data->generator.transactions[2].stopLatency();
396 data->generator.transactions[2].count++;
398 if(data->transactionData.branchExecuted)
399 data->generator.transactions[2].branchExecuted++;
402 data->generator.totalTransactions++;
408 data->generator.transactions[3].stopLatency();
409 data->generator.transactions[3].count++;
411 if(data->transactionData.branchExecuted)
412 data->generator.transactions[3].branchExecuted++;
413 if(data->transactionData.do_rollback)
414 data->generator.transactions[3].rollbackExecuted++;
416 if(data->transactionData.branchExecuted &&
417 !data->transactionData.do_rollback){
418 insertSession(&data->generator.activeSessions,
419 data->transactionData.number,
420 data->transactionData.server_id);
424 data->generator.totalTransactions++;
430 data->generator.transactions[4].stopLatency();
431 data->generator.transactions[4].count++;
433 if(data->transactionData.branchExecuted)
434 data->generator.transactions[4].branchExecuted++;
435 if(data->transactionData.do_rollback)
436 data->generator.transactions[4].rollbackExecuted++;
438 if(data->transactionData.sessionElement &&
439 !data->transactionData.do_rollback){
440 deleteSession(&data->generator.activeSessions);
444 data->generator.totalTransactions++;
456 int minEventSendPoll,
463 double benchTimeStart;
467 myRandom48Init(data->randomSeed);
469 for(i = 0; i<parallellism; i++){
470 initGeneratorStatistics(&data[i].generator);
474 memcpy(startUp, data, (parallellism *
sizeof(
ThreadData)));
479 periodStop = userGetTime() + (double)data[0].warmUpSeconds;
481 while(userGetTime() < periodStop){
482 doOneTransaction(startUp, parallellism,
483 millisSendPoll, minEventSendPoll, forceSendPoll);
486 ndbout_c(
"Waiting for startup to finish");
494 for(i = 0; i<parallellism; i++){
495 if(startUp[i].runState != Runnable){
504 ndbout_c(
"Benchmark period starts");
509 benchTimeStart = userGetTime();
511 periodStop = benchTimeStart + (double)data[0].testSeconds;
512 while(userGetTime() < periodStop)
513 doOneTransaction(data, parallellism,
514 millisSendPoll, minEventSendPoll, forceSendPoll);
516 benchTimeEnd = userGetTime();
518 ndbout_c(
"Benchmark period done");
526 for(i = 0; i<parallellism; i++){
527 if(data[i].runState != Runnable){
540 periodStop = userGetTime() + (double)data[0].coolDownSeconds;
541 while(userGetTime() < periodStop){
542 doOneTransaction(startUp, parallellism,
543 millisSendPoll, minEventSendPoll, forceSendPoll);
549 for(i = 0; i<parallellism; i++){
550 if(startUp[i].runState != Runnable){
564 for(j = 0; j<parallellism; j++){
565 st = &data[j].generator;
567 st->outerLoopTime = benchTimeEnd - benchTimeStart;
568 st->outerTps = getTps(st->totalTransactions, st->outerLoopTime);