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);
45 static void getRandomChangedTime(ChangedTime changedTime);
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 int 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;
112 static void getRandomChangedTime(ChangedTime changedTime)
114 memset(changedTime, myRandom48(26)+
'A', CHANGED_TIME_LENGTH);
115 changedTime[CHANGED_TIME_LENGTH] = 0;
121 trans->branchExecuted = 0;
122 trans->rollbackExecuted = 0;
123 trans->latencyCounter = myRandom48(127);
124 trans->latency.reset();
129 return(list->numberInList == SESSION_LIST_LENGTH);
134 return(list->numberInList == 0);
138 SubscriberNumber number,
142 if( listFull(list) )
return;
144 e = &list->list[list->writeIndex];
146 strcpy(e->subscriberNumber, number);
147 e->serverId = serverId;
149 list->writeIndex = (list->writeIndex + 1) % SESSION_LIST_LENGTH;
150 list->numberInList++;
152 if( list->numberInList > maxsize )
153 maxsize = list->numberInList;
158 if( listEmpty(list) )
return(0);
160 return(&list->list[list->readIndex]);
165 if( listEmpty(list) )
return;
167 list->readIndex = (list->readIndex + 1) % SESSION_LIST_LENGTH;
168 list->numberInList--;
175 if( initSequence(&gen->transactionSequence,
176 transactionDefinition) != 0 ) {
177 ndbout_c(
"could not set the transaction types");
181 if( initSequence(&gen->rollbackSequenceT4,
182 rollbackDefinition) != 0 ) {
183 ndbout_c(
"could not set the rollback sequence");
187 if( initSequence(&gen->rollbackSequenceT5,
188 rollbackDefinition) != 0 ) {
189 ndbout_c(
"could not set the rollback sequence");
193 for(i = 0; i < NUM_TRANSACTION_TYPES; i++ )
194 clearTransaction(&gen->transactions[i]);
196 gen->totalTransactions = 0;
198 gen->activeSessions.numberInList = 0;
199 gen->activeSessions.readIndex = 0;
200 gen->activeSessions.writeIndex = 0;
206 doOneTransaction(
ThreadData * td,
int p,
int millis,
int minEvents,
int force)
209 unsigned int transactionType;
214 for(i = 0; i<p; i++){
215 if(td[i].runState == Runnable){
216 transactionType = getNextRandom(&td[i].generator.transactionSequence);
218 switch(transactionType) {
220 doTransaction_T1(td[i].pNDB, &td[i], async);
223 doTransaction_T2(td[i].pNDB, &td[i], async);
226 doTransaction_T3(td[i].pNDB, &td[i], async);
229 doTransaction_T4(td[i].pNDB, &td[i], async);
232 doTransaction_T5(td[i].pNDB, &td[i], async);
235 ndbout_c(
"Unknown transaction type: %d", transactionType);
251 getRandomSubscriberNumber(td->transactionData.number);
252 getRandomChangedBy(td->transactionData.changed_by);
254 sizeof(td->transactionData.changed_time),
255 "%ld - %d", td->changedTime++, myRandom48(65536*1024));
257 td->transactionData.location = td->transactionData.changed_by[0];
263 td->generator.transactions[0].startLatency();
265 start_T1(pNDB, td, async);
275 getRandomSubscriberNumber(td->transactionData.number);
281 td->generator.transactions[1].startLatency();
283 start_T2(pNDB, td, async);
295 se = getNextSession(&td->generator.activeSessions);
297 strcpy(td->transactionData.number, se->subscriberNumber);
298 td->transactionData.server_id = se->serverId;
299 td->transactionData.sessionElement = 1;
301 getRandomSubscriberNumber(td->transactionData.number);
302 getRandomServerId(&td->transactionData.server_id);
303 td->transactionData.sessionElement = 0;
306 td->transactionData.server_bit = (1 << td->transactionData.server_id);
312 td->generator.transactions[2].startLatency();
313 start_T3(pNDB, td, async);
323 getRandomSubscriberNumber(td->transactionData.number);
324 getRandomServerId(&td->transactionData.server_id);
326 td->transactionData.server_bit = (1 << td->transactionData.server_id);
327 td->transactionData.do_rollback =
328 getNextRandom(&td->generator.rollbackSequenceT4);
331 memset(td->transactionData.session_details,
332 myRandom48(26)+
'A', SESSION_DETAILS_LENGTH);
334 td->transactionData.session_details[SESSION_DETAILS_LENGTH] = 0;
340 td->generator.transactions[3].startLatency();
341 start_T4(pNDB, td, async);
349 se = getNextSession(&td->generator.activeSessions);
351 strcpy(td->transactionData.number, se->subscriberNumber);
352 td->transactionData.server_id = se->serverId;
353 td->transactionData.sessionElement = 1;
356 getRandomSubscriberNumber(td->transactionData.number);
357 getRandomServerId(&td->transactionData.server_id);
358 td->transactionData.sessionElement = 0;
361 td->transactionData.server_bit = (1 << td->transactionData.server_id);
362 td->transactionData.do_rollback
363 = getNextRandom(&td->generator.rollbackSequenceT5);
369 td->generator.transactions[4].startLatency();
370 start_T5(pNDB, td, async);
375 data->generator.transactions[0].stopLatency();
376 data->generator.transactions[0].count++;
379 data->generator.totalTransactions++;
384 data->generator.transactions[1].stopLatency();
385 data->generator.transactions[1].count++;
388 data->generator.totalTransactions++;
394 data->generator.transactions[2].stopLatency();
395 data->generator.transactions[2].count++;
397 if(data->transactionData.branchExecuted)
398 data->generator.transactions[2].branchExecuted++;
401 data->generator.totalTransactions++;
407 data->generator.transactions[3].stopLatency();
408 data->generator.transactions[3].count++;
410 if(data->transactionData.branchExecuted)
411 data->generator.transactions[3].branchExecuted++;
412 if(data->transactionData.do_rollback)
413 data->generator.transactions[3].rollbackExecuted++;
415 if(data->transactionData.branchExecuted &&
416 !data->transactionData.do_rollback){
417 insertSession(&data->generator.activeSessions,
418 data->transactionData.number,
419 data->transactionData.server_id);
423 data->generator.totalTransactions++;
429 data->generator.transactions[4].stopLatency();
430 data->generator.transactions[4].count++;
432 if(data->transactionData.branchExecuted)
433 data->generator.transactions[4].branchExecuted++;
434 if(data->transactionData.do_rollback)
435 data->generator.transactions[4].rollbackExecuted++;
437 if(data->transactionData.sessionElement &&
438 !data->transactionData.do_rollback){
439 deleteSession(&data->generator.activeSessions);
443 data->generator.totalTransactions++;
455 int minEventSendPoll,
462 double benchTimeStart;
466 myRandom48Init(data->randomSeed);
468 for(i = 0; i<parallellism; i++){
469 initGeneratorStatistics(&data[i].generator);
473 memcpy(startUp, data, (parallellism *
sizeof(
ThreadData)));
478 periodStop = userGetTime() + (double)data[0].warmUpSeconds;
480 while(userGetTime() < periodStop){
481 doOneTransaction(startUp, parallellism,
482 millisSendPoll, minEventSendPoll, forceSendPoll);
485 ndbout_c(
"Waiting for startup to finish");
493 for(i = 0; i<parallellism; i++){
494 if(startUp[i].runState != Runnable){
503 ndbout_c(
"Benchmark period starts");
508 benchTimeStart = userGetTime();
510 periodStop = benchTimeStart + (double)data[0].testSeconds;
511 while(userGetTime() < periodStop)
512 doOneTransaction(data, parallellism,
513 millisSendPoll, minEventSendPoll, forceSendPoll);
515 benchTimeEnd = userGetTime();
517 ndbout_c(
"Benchmark period done");
525 for(i = 0; i<parallellism; i++){
526 if(data[i].runState != Runnable){
539 periodStop = userGetTime() + (double)data[0].coolDownSeconds;
540 while(userGetTime() < periodStop){
541 doOneTransaction(startUp, parallellism,
542 millisSendPoll, minEventSendPoll, forceSendPoll);
548 for(i = 0; i<parallellism; i++){
549 if(startUp[i].runState != Runnable){
563 for(j = 0; j<parallellism; j++){
564 st = &data[j].generator;
566 st->outerLoopTime = benchTimeEnd - benchTimeStart;
567 st->outerTps = getTps(st->totalTransactions, st->outerLoopTime);