Merge lp:~mdcallag/perconatools/tpcc-mysql into lp:~percona-dev/perconatools/tpcc-mysql

Proposed by Mark Callaghan
Status: Needs review
Proposed branch: lp:~mdcallag/perconatools/tpcc-mysql
Merge into: lp:~percona-dev/perconatools/tpcc-mysql
Diff against target: 545 lines (+132/-120)
4 files modified
src/driver.c (+47/-37)
src/main.c (+59/-57)
src/rthist.c (+24/-24)
src/rthist.h (+2/-2)
To merge this branch: bzr merge lp:~mdcallag/perconatools/tpcc-mysql
Reviewer Review Type Date Requested Status
Percona developers Pending
Review via email: mp+73893@code.launchpad.net

Description of the change

Do you have any interest in this change?
I don't mind maintaining this as a separate branch but I think the changes will be useful to you too.

The benefits are:
1) it uses millisecond granularity rather than 10 millisecond granularity for response time buckets
2) it uses double instead of float (this will reduce some rounding errors, but probably isn't a big deal)
3) it uses gettimeofday rather than times to count clock ticks. The granularity from times is too coarse -- it provides at best 10 millisecond granularity. I don't know if this is used for portability, but it is too coarse.

To post a comment you must log in.

Unmerged revisions

27. By Mark Callaghan

Use millisecond granularity instead of 10 millisecond granularity.
Use gettimeofday to count ticks instead of times
Use double instead of float

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/driver.c'
2--- src/driver.c 2008-12-04 02:50:59 +0000
3+++ src/driver.c 2011-09-02 22:20:20 +0000
4@@ -5,7 +5,7 @@
5
6 #include <stdio.h>
7 #include <stdlib.h>
8-#include <sys/times.h>
9+#include <sys/time.h>
10 #include "tpc.h" /* prototypes for misc. functions */
11 #include "trans_if.h" /* prototypes for transacation interface calls */
12 #include "sequence.h"
13@@ -35,7 +35,7 @@
14 extern int* retry2[];
15 extern int* failure2[];
16
17-extern float max_rt[];
18+extern double max_rt[];
19
20 extern long clk_tck;
21
22@@ -47,6 +47,21 @@
23 #define RTIME_DELIVERY 80
24 #define RTIME_SLEV 20
25
26+static unsigned long long clock_ticks()
27+{
28+ struct timeval tv;
29+ unsigned long long res;
30+
31+ gettimeofday(&tv, NULL);
32+ res = tv.tv_sec * 1000000 + tv.tv_usec;
33+ return res;
34+}
35+
36+double ticks_to_secs(unsigned long long t2, unsigned long long t1)
37+{
38+ return ((double)(t2 - t1)) / (double) clk_tck;
39+}
40+
41 int driver (int t_num)
42 {
43 int i, j;
44@@ -87,9 +102,8 @@
45 {
46 int c_num;
47 int i,ret;
48- clock_t clk1,clk2;
49- float rt;
50- struct tms tbuf;
51+ unsigned long long clk1,clk2;
52+ double rt;
53 int w_id, d_id, c_id, ol_cnt;
54 int all_local = 1;
55 int notfound = MAXITEMS+1; /* valid item ids are numbered consecutively
56@@ -128,18 +142,18 @@
57 }
58
59 for (i = 0; i < MAX_RETRY; i++) {
60- clk1 = times( &tbuf );
61+ clk1 = clock_ticks();
62 ret = neword(t_num, w_id, d_id, c_id, ol_cnt, all_local, itemid, supware, qty);
63- clk2 = times( &tbuf );
64+ clk2 = clock_ticks();
65
66 if(ret){
67
68- rt = (float)(clk2 - clk1)/(float)clk_tck;
69+ rt = ticks_to_secs(clk2, clk1);
70 if(rt > max_rt[0])
71 max_rt[0]=rt;
72 hist_inc(0, clk2 - clk1);
73 if(counting_on){
74- if( (clk2 - clk1) / clk_tck < RTIME_NEWORD ){
75+ if( rt < RTIME_NEWORD ){
76 success[0]++;
77 success2[0][t_num]++;
78 }else{
79@@ -189,9 +203,8 @@
80 {
81 int c_num;
82 int byname,i,ret;
83- clock_t clk1,clk2;
84- float rt;
85- struct tms tbuf;
86+ unsigned long long clk1,clk2;
87+ double rt;
88 int w_id, d_id, c_w_id, c_d_id, c_id, h_amount;
89 char c_last[17];
90
91@@ -220,18 +233,18 @@
92 }
93
94 for (i = 0; i < MAX_RETRY; i++) {
95- clk1 = times( &tbuf );
96+ clk1 = clock_ticks();
97 ret = payment(t_num, w_id, d_id, byname, c_w_id, c_d_id, c_id, c_last, h_amount);
98- clk2 = times( &tbuf );
99+ clk2 = clock_ticks();
100
101 if(ret){
102
103- rt = (float)(clk2 - clk1)/(float)clk_tck;
104+ rt = ticks_to_secs(clk2, clk1);
105 if(rt > max_rt[1])
106 max_rt[1]=rt;
107 hist_inc(1, clk2 - clk1);
108 if(counting_on){
109- if( (clk2 - clk1) / clk_tck < RTIME_PAYMENT ){
110+ if( rt < RTIME_PAYMENT ){
111 success[1]++;
112 success2[1][t_num]++;
113 }else{
114@@ -268,9 +281,8 @@
115 {
116 int c_num;
117 int byname,i,ret;
118- clock_t clk1,clk2;
119- float rt;
120- struct tms tbuf;
121+ unsigned long long clk1,clk2;
122+ double rt;
123 int w_id, d_id, c_id;
124 char c_last[16];
125
126@@ -291,18 +303,18 @@
127 }
128
129 for (i = 0; i < MAX_RETRY; i++) {
130- clk1 = times( &tbuf );
131+ clk1 = clock_ticks();
132 ret = ordstat(t_num, w_id, d_id, byname, c_id, c_last);
133- clk2 = times( &tbuf );
134+ clk2 = clock_ticks();
135
136 if(ret){
137
138- rt = (float)(clk2 - clk1)/(float)clk_tck;
139+ rt = ticks_to_secs(clk2, clk1);
140 if(rt > max_rt[2])
141 max_rt[2]=rt;
142 hist_inc(2, clk2 - clk1);
143 if(counting_on){
144- if( (clk2 - clk1) / clk_tck < RTIME_ORDSTAT ){
145+ if( rt < RTIME_ORDSTAT ){
146 success[2]++;
147 success2[2][t_num]++;
148 }else{
149@@ -340,9 +352,8 @@
150 {
151 int c_num;
152 int i,ret;
153- clock_t clk1,clk2;
154- float rt;
155- struct tms tbuf;
156+ unsigned long long clk1,clk2;
157+ double rt;
158 int w_id, o_carrier_id;
159
160 if(num_node==0){
161@@ -355,18 +366,18 @@
162 o_carrier_id = RandomNumber(1, 10);
163
164 for (i = 0; i < MAX_RETRY; i++) {
165- clk1 = times( &tbuf );
166+ clk1 = clock_ticks();
167 ret = delivery(t_num, w_id, o_carrier_id);
168- clk2 = times( &tbuf );
169+ clk2 = clock_ticks();
170
171 if(ret){
172
173- rt = (float)(clk2 - clk1)/(float)clk_tck;
174+ rt = ticks_to_secs(clk2, clk1);
175 if(rt > max_rt[3])
176 max_rt[3]=rt;
177 hist_inc(3, clk2 - clk1);
178 if(counting_on){
179- if( (clk2 - clk1) / clk_tck < RTIME_DELIVERY ){
180+ if( rt < RTIME_DELIVERY ){
181 success[3]++;
182 success2[3][t_num]++;
183 }else{
184@@ -404,9 +415,8 @@
185 {
186 int c_num;
187 int i,ret;
188- clock_t clk1,clk2;
189- float rt;
190- struct tms tbuf;
191+ unsigned long long clk1,clk2;
192+ double rt;
193 int w_id, d_id, level;
194
195 if(num_node==0){
196@@ -420,18 +430,18 @@
197 level = RandomNumber(10, 20);
198
199 for (i = 0; i < MAX_RETRY; i++) {
200- clk1 = times( &tbuf );
201+ clk1 = clock_ticks();
202 ret = slev(t_num, w_id, d_id, level);
203- clk2 = times( &tbuf );
204+ clk2 = clock_ticks();
205
206 if(ret){
207
208- rt = (float)(clk2 - clk1)/(float)clk_tck;
209+ rt = ticks_to_secs(clk2, clk1);
210 if(rt > max_rt[4])
211 max_rt[4]=rt;
212 hist_inc(4, clk2 - clk1);
213 if(counting_on){
214- if( (clk2 - clk1) / clk_tck < RTIME_SLEV ){
215+ if( rt < RTIME_SLEV ){
216 success[4]++;
217 success2[4][t_num]++;
218 }else{
219
220=== modified file 'src/main.c'
221--- src/main.c 2011-08-25 22:34:07 +0000
222+++ src/main.c 2011-09-02 22:20:20 +0000
223@@ -64,7 +64,7 @@
224 int prev_s[5];
225 int prev_l[5];
226
227-float max_rt[5];
228+double max_rt[5];
229
230 int activate_transaction;
231 int counting_on;
232@@ -116,7 +116,7 @@
233 {
234 int i, k, t_num, arg_offset;
235 long j;
236- float f;
237+ double f;
238 pthread_t *t;
239 thread_arg *thd_arg;
240 timer_t timer;
241@@ -173,7 +173,9 @@
242 exit(1);
243 }
244
245- clk_tck = sysconf(_SC_CLK_TCK);
246+ /* clk_tck = sysconf(_SC_CLK_TCK); */
247+ clk_tck = 1000000; /* gettimeofday granularity is usec */
248+ fprintf(stdout, "clk_tck is %ld\n", clk_tck);
249
250 /* Parse args */
251
252@@ -437,29 +439,29 @@
253 j += (success[i] + late[i]);
254 }
255
256- f = 100.0 * (float)(success[1] + late[1])/(float)j;
257- printf(" Payment: %3.2f%% (>=43.0%%)",f);
258+ f = 100.0 * (double)(success[1] + late[1])/(double)j;
259+ printf(" Payment: %.3f%% (>=43.0%%)",f);
260 if ( f >= 43.0 ){
261 printf(" [OK]\n");
262 }else{
263 printf(" [NG] *\n");
264 }
265- f = 100.0 * (float)(success[2] + late[2])/(float)j;
266- printf(" Order-Status: %3.2f%% (>= 4.0%%)",f);
267- if ( f >= 4.0 ){
268- printf(" [OK]\n");
269- }else{
270- printf(" [NG] *\n");
271- }
272- f = 100.0 * (float)(success[3] + late[3])/(float)j;
273- printf(" Delivery: %3.2f%% (>= 4.0%%)",f);
274- if ( f >= 4.0 ){
275- printf(" [OK]\n");
276- }else{
277- printf(" [NG] *\n");
278- }
279- f = 100.0 * (float)(success[4] + late[4])/(float)j;
280- printf(" Stock-Level: %3.2f%% (>= 4.0%%)",f);
281+ f = 100.0 * (double)(success[2] + late[2])/(double)j;
282+ printf(" Order-Status: %.3f%% (>= 4.0%%)",f);
283+ if ( f >= 4.0 ){
284+ printf(" [OK]\n");
285+ }else{
286+ printf(" [NG] *\n");
287+ }
288+ f = 100.0 * (double)(success[3] + late[3])/(double)j;
289+ printf(" Delivery: %.3f%% (>= 4.0%%)",f);
290+ if ( f >= 4.0 ){
291+ printf(" [OK]\n");
292+ }else{
293+ printf(" [NG] *\n");
294+ }
295+ f = 100.0 * (double)(success[4] + late[4])/(double)j;
296+ printf(" Stock-Level: %.3f%% (>= 4.0%%)",f);
297 if ( f >= 4.0 ){
298 printf(" [OK]\n");
299 }else{
300@@ -467,36 +469,36 @@
301 }
302
303 printf(" [response time (at least 90%% passed)]\n");
304- f = 100.0 * (float)success[0]/(float)(success[0] + late[0]);
305- printf(" New-Order: %3.2f%% ",f);
306- if ( f >= 90.0 ){
307- printf(" [OK]\n");
308- }else{
309- printf(" [NG] *\n");
310- }
311- f = 100.0 * (float)success[1]/(float)(success[1] + late[1]);
312- printf(" Payment: %3.2f%% ",f);
313- if ( f >= 90.0 ){
314- printf(" [OK]\n");
315- }else{
316- printf(" [NG] *\n");
317- }
318- f = 100.0 * (float)success[2]/(float)(success[2] + late[2]);
319- printf(" Order-Status: %3.2f%% ",f);
320- if ( f >= 90.0 ){
321- printf(" [OK]\n");
322- }else{
323- printf(" [NG] *\n");
324- }
325- f = 100.0 * (float)success[3]/(float)(success[3] + late[3]);
326- printf(" Delivery: %3.2f%% ",f);
327- if ( f >= 90.0 ){
328- printf(" [OK]\n");
329- }else{
330- printf(" [NG] *\n");
331- }
332- f = 100.0 * (float)success[4]/(float)(success[4] + late[4]);
333- printf(" Stock-Level: %3.2f%% ",f);
334+ f = 100.0 * (double)success[0]/(double)(success[0] + late[0]);
335+ printf(" New-Order: %.3f%% ",f);
336+ if ( f >= 90.0 ){
337+ printf(" [OK]\n");
338+ }else{
339+ printf(" [NG] *\n");
340+ }
341+ f = 100.0 * (double)success[1]/(double)(success[1] + late[1]);
342+ printf(" Payment: %.3f%% ",f);
343+ if ( f >= 90.0 ){
344+ printf(" [OK]\n");
345+ }else{
346+ printf(" [NG] *\n");
347+ }
348+ f = 100.0 * (double)success[2]/(double)(success[2] + late[2]);
349+ printf(" Order-Status: %.3f%% ",f);
350+ if ( f >= 90.0 ){
351+ printf(" [OK]\n");
352+ }else{
353+ printf(" [NG] *\n");
354+ }
355+ f = 100.0 * (double)success[3]/(double)(success[3] + late[3]);
356+ printf(" Delivery: %.3f%% ",f);
357+ if ( f >= 90.0 ){
358+ printf(" [OK]\n");
359+ }else{
360+ printf(" [NG] *\n");
361+ }
362+ f = 100.0 * (double)success[4]/(double)(success[4] + late[4]);
363+ printf(" Stock-Level: %.3f%% ",f);
364 if ( f >= 90.0 ){
365 printf(" [OK]\n");
366 }else{
367@@ -504,8 +506,8 @@
368 }
369
370 printf("\n<TpmC>\n");
371- f = (float)(success[0] + late[0]) * 60.0
372- / (float)((measure_time / PRINT_INTERVAL) * PRINT_INTERVAL);
373+ f = (double)(success[0] + late[0]) * 60.0
374+ / (double)((measure_time / PRINT_INTERVAL) * PRINT_INTERVAL);
375 printf(" %.3f TpmC\n",f);
376 exit(0);
377
378@@ -521,7 +523,7 @@
379 {
380 int i;
381 int s[5],l[5];
382- float rt90[5];
383+ double rt90[5];
384
385 for( i=0; i<5; i++ ){
386 s[i] = success[i];
387@@ -530,7 +532,7 @@
388 }
389
390 time_count += PRINT_INTERVAL;
391- printf("%4d, %d(%d):%.2f, %d(%d):%.2f, %d(%d):%.2f, %d(%d):%.2f, %d(%d):%.2f\n",
392+ printf("%4d, %d(%d):%.3f, %d(%d):%.3f, %d(%d):%.3f, %d(%d):%.3f, %d(%d):%.3f\n",
393 time_count,
394 ( s[0] + l[0] - prev_s[0] - prev_l[0] ),
395 ( l[0] - prev_l[0] ),
396@@ -560,7 +562,7 @@
397 {
398 int i;
399 int s[5],l[5];
400- float rt90[5];
401+ double rt90[5];
402
403 for( i=0; i<5; i++ ){
404 s[i] = success[i];
405@@ -569,7 +571,7 @@
406 }
407
408 time_count += PRINT_INTERVAL;
409- printf("%4d, %d(%d):%.2f, %d(%d):%.2f, %d(%d):%.2f, %d(%d):%.2f, %d(%d):%.2f\n",
410+ printf("%4d, %d(%d):%.3f, %d(%d):%.3f, %d(%d):%.3f, %d(%d):%.3f, %d(%d):%.3f\n",
411 time_count,
412 ( s[0] + l[0] - prev_s[0] - prev_l[0] ),
413 ( l[0] - prev_l[0] ),
414
415=== modified file 'src/rthist.c'
416--- src/rthist.c 2011-08-25 22:34:07 +0000
417+++ src/rthist.c 2011-09-02 22:20:20 +0000
418@@ -4,16 +4,15 @@
419 */
420
421 #include <stdio.h>
422-#include <sys/time.h>
423-
424-#define MAXREC 320
425-#define REC_PER_SEC 100
426-
427-extern float max_rt[];
428+
429+#define MAXSEC 32
430+#define REC_PER_SEC 1000
431+
432+extern double max_rt[];
433 extern long clk_tck;
434
435-int total_hist[5][MAXREC * REC_PER_SEC];
436-int cur_hist[5][MAXREC * REC_PER_SEC];
437+int total_hist[5][MAXSEC * REC_PER_SEC];
438+int cur_hist[5][MAXSEC * REC_PER_SEC];
439
440 /* initialize */
441 void hist_init()
442@@ -21,36 +20,37 @@
443 int i,j;
444
445 for( i=0; i<5; i++){
446- for( j=0; j<(MAXREC * REC_PER_SEC); j++){
447+ for( j=0; j<(MAXSEC * REC_PER_SEC); j++){
448 total_hist[i][j] = cur_hist[i][j] = 0;
449 }
450 }
451 }
452
453 /* incliment matched one */
454-void hist_inc( int transaction, time_t rtclk )
455+void hist_inc( int transaction, unsigned long long ticks)
456 {
457 int i;
458
459- i = ( rtclk * REC_PER_SEC )/clk_tck;
460- if(i >= (MAXREC * REC_PER_SEC)){
461- i = (MAXREC * REC_PER_SEC) - 1;
462+ /* "i" is the response time in milliseconds rounded to nearest int */
463+ i = ( ticks * REC_PER_SEC )/clk_tck;
464+ if(i >= (MAXSEC * REC_PER_SEC)){
465+ i = (MAXSEC * REC_PER_SEC) - 1;
466 }
467 ++cur_hist[transaction][i];
468 }
469
470 /* check point, add on total histgram, return 90% line */
471-float hist_ckp( int transaction )
472+double hist_ckp( int transaction )
473 {
474 int i;
475 int total,tmp,line;
476
477 total = tmp = 0;
478- line = MAXREC * REC_PER_SEC;
479- for( i=0; i<(MAXREC * REC_PER_SEC); i++){
480+ line = MAXSEC * REC_PER_SEC;
481+ for( i=0; i<(MAXSEC * REC_PER_SEC); i++){
482 total += cur_hist[transaction][i];
483 }
484- for( i=(MAXREC * REC_PER_SEC)-1; i >= 0 ; i--){
485+ for( i=(MAXSEC * REC_PER_SEC)-1; i >= 0 ; i--){
486 tmp += cur_hist[transaction][i];
487 total_hist[transaction][i] += cur_hist[transaction][i];
488 cur_hist[transaction][i] = 0;
489@@ -58,7 +58,7 @@
490 line = i;
491 }
492 }
493- return ( (float)(line)/(float)(REC_PER_SEC) );
494+ return ( (double)(line)/(double)(REC_PER_SEC) );
495 }
496
497 void hist_report()
498@@ -68,11 +68,11 @@
499
500 for( j=0; j<5; j++){
501 total[j] = tmp[j] = 0;
502- line[j] = MAXREC * REC_PER_SEC;
503- for( i=0; i<(MAXREC * REC_PER_SEC); i++){
504+ line[j] = MAXSEC * REC_PER_SEC;
505+ for( i=0; i<(MAXSEC * REC_PER_SEC); i++){
506 total[j] += total_hist[j][i];
507 }
508- for( i=(MAXREC * REC_PER_SEC)-1; i >= 0 ; i--){
509+ for( i=(MAXSEC * REC_PER_SEC)-1; i >= 0 ; i--){
510 tmp[j] += total_hist[j][i];
511 if( (tmp[j] * 10) <= total[j] ){
512 line[j] = i;
513@@ -99,8 +99,8 @@
514 case 4:
515 printf("\n5.Stock-Level\n\n");
516 }
517- for( i=0; (i<(MAXREC * REC_PER_SEC))&&(i <= line[j]*4); i++){
518- printf("%3.2f, %6d\n",(float)(i+1)/(float)(REC_PER_SEC),total_hist[j][i]);
519+ for( i=0; (i<(MAXSEC * REC_PER_SEC))&&(i <= line[j]*4); i++){
520+ printf("%.3f, %3d\n",(double)(i+1)/(double)(REC_PER_SEC),total_hist[j][i]);
521 }
522 printf("\n");
523 }
524@@ -123,7 +123,7 @@
525 case 4:
526 printf(" Stock-Level : ");
527 }
528- printf("%3.2f (%.2f)\n",(float)(line[j])/(float)(REC_PER_SEC),max_rt[j]);
529+ printf("%.3f (%.6f)\n",(double)(line[j])/(double)(REC_PER_SEC),max_rt[j]);
530 }
531
532 }
533
534=== modified file 'src/rthist.h'
535--- src/rthist.h 2008-12-04 02:50:59 +0000
536+++ src/rthist.h 2011-09-02 22:20:20 +0000
537@@ -3,6 +3,6 @@
538 */
539
540 void hist_init();
541-void hist_inc( int transaction, time_t rtclk );
542-float hist_ckp( int transaction );
543+void hist_inc( int transaction, unsigned long long ticks);
544+double hist_ckp( int transaction );
545 void hist_report();