Skip to content

Commit bd78fe1

Browse files
author
VadimTk
committed
added percentile calculation
1 parent edc9652 commit bd78fe1

File tree

6 files changed

+226
-3
lines changed

6 files changed

+226
-3
lines changed

load_multi_schema.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export LD_LIBRARY_PATH=/data/opt/bin/mysql-5.7.11-linux-glibc2.5-x86_64/lib/
2+
DBNAME=$1
3+
WH=$2
4+
NSCHEMA=$3
5+
HOST=127.0.0.1
6+
STEP=5
7+
8+
schema=0
9+
10+
while [ $schema -lt $NSCHEMA ]
11+
do
12+
DBFULLNAME=${DBNAME}_${schema}
13+
echo "Creating schema $DBFULLNAME"
14+
mysqladmin -h $HOST -f drop $DBFULLNAME
15+
mysqladmin -h $HOST create $DBFULLNAME
16+
mysql -h $HOST $DBFULLNAME < create_table.sql
17+
mysql -h $HOST $DBFULLNAME < add_fkey_idx.sql
18+
mkdir -p out
19+
20+
./tpcc_load -h $HOST -d $DBFULLNAME -u root -p "" -w $WH -l 1 -m 1 -n $WH >> out/1_$DBFULLNAME.out &
21+
22+
x=1
23+
24+
while [ $x -le $WH ]
25+
do
26+
echo $x $(( $x + $STEP - 1 ))
27+
./tpcc_load -h $HOST -d $DBFULLNAME -u root -p "" -w $WH -l 2 -m $x -n $(( $x + $STEP - 1 )) >> out/2_$DBFULLNAME.$x.out &
28+
./tpcc_load -h $HOST -d $DBFULLNAME -u root -p "" -w $WH -l 3 -m $x -n $(( $x + $STEP - 1 )) >> out/3_$DBFULLNAME.$x.out &
29+
./tpcc_load -h $HOST -d $DBFULLNAME -u root -p "" -w $WH -l 4 -m $x -n $(( $x + $STEP - 1 )) >> out/4_$DBFULLNAME.$x.out &
30+
x=$(( $x + $STEP ))
31+
done
32+
33+
for job in `jobs -p`
34+
do
35+
echo $job
36+
wait $job
37+
done
38+
39+
schema=$(( $schema + 1 ))
40+
41+
done

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ INC= -I. `mysql_config --include`
1313
CFLAGS= -w -O3 -g
1414

1515
TRANSACTIONS= neword.o payment.o ordstat.o delivery.o slev.o
16-
OBJS= main.o spt_proc.o driver.o support.o sequence.o rthist.o $(TRANSACTIONS)
16+
OBJS= main.o spt_proc.o driver.o support.o sequence.o rthist.o sb_percentile.o $(TRANSACTIONS)
1717

1818
.SUFFIXES:
1919
.SUFFIXES: .o .c

src/driver.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "trans_if.h" /* prototypes for transacation interface calls */
1212
#include "sequence.h"
1313
#include "rthist.h"
14+
#include "sb_percentile.h"
1415

1516
static int other_ware (int home_ware);
1617
static int do_neword (int t_num);
@@ -42,6 +43,7 @@ extern double max_rt[];
4243
extern double total_rt[];
4344

4445
extern long clk_tck;
46+
extern sb_percentile_t local_percentile;
4547

4648
#define MAX_RETRY 2000
4749

@@ -54,6 +56,7 @@ extern long clk_tck;
5456
int driver (int t_num)
5557
{
5658
int i, j;
59+
5760

5861
/* Actually, WaitTimes are needed... */
5962
while( activate_transaction ){
@@ -148,6 +151,7 @@ static int do_neword (int t_num)
148151
if(rt > max_rt[0])
149152
max_rt[0]=rt;
150153
total_rt[0] += rt;
154+
sb_percentile_update(&local_percentile, rt);
151155
hist_inc(0, rt);
152156
if(counting_on){
153157
if( rt < RTIME_NEWORD ){

src/main.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "spt_proc.h"
2020
#include "sequence.h"
2121
#include "rthist.h"
22+
#include "sb_percentile.h"
2223

2324
/* Global SQL Variables */
2425
MYSQL **ctx;
@@ -77,6 +78,8 @@ double cur_max_rt[5];
7778

7879
double prev_total_rt[5];
7980

81+
sb_percentile_t local_percentile;
82+
8083
int activate_transaction;
8184
int counting_on;
8285

@@ -382,6 +385,9 @@ int main( int argc, char *argv[] )
382385
}
383386
}
384387

388+
if (sb_percentile_init(&local_percentile, 100000, 1.0, 1e13))
389+
return NULL;
390+
385391
/* set up threads */
386392

387393
t = malloc( sizeof(pthread_t) * num_conn );
@@ -598,6 +604,8 @@ void alarm_handler(int signum)
598604
int s[5],l[5];
599605
double rt90[5];
600606
double trt[5];
607+
double percentile_val;
608+
double percentile_val99;
601609

602610
for( i=0; i<5; i++ ){
603611
s[i] = success[i];
@@ -607,10 +615,13 @@ void alarm_handler(int signum)
607615
}
608616

609617
time_count += PRINT_INTERVAL;
618+
percentile_val = sb_percentile_calculate(&local_percentile, 95);
619+
percentile_val99 = sb_percentile_calculate(&local_percentile, 99);
620+
sb_percentile_reset(&local_percentile);
610621
// printf("%4d, %d:%.3f|%.3f(%.3f), %d:%.3f|%.3f(%.3f), %d:%.3f|%.3f(%.3f), %d:%.3f|%.3f(%.3f), %d:%.3f|%.3f(%.3f)\n",
611-
printf("%4d, trx: %d max_rt: %.3f, %d|%.3f, %d|%.3f, %d|%.3f, %d|%.3f\n",
622+
printf("%4d, trx: %d, 95%: %.3f, 99%: %.3f, max_rt: %.3f, %d|%.3f, %d|%.3f, %d|%.3f, %d|%.3f\n",
612623
time_count,
613-
( s[0] + l[0] - prev_s[0] - prev_l[0] ),
624+
( s[0] + l[0] - prev_s[0] - prev_l[0] ), percentile_val,percentile_val99,
614625
(double)cur_max_rt[0],
615626
( s[1] + l[1] - prev_s[1] - prev_l[1] ),
616627
(double)cur_max_rt[1],

src/sb_percentile.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/* Copyright (C) 2011 Alexey Kopytov.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; either version 2 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16+
*/
17+
18+
#ifdef HAVE_CONFIG_H
19+
# include "config.h"
20+
#endif
21+
#ifdef _WIN32
22+
#include "sb_win.h"
23+
#endif
24+
25+
#include <stdlib.h>
26+
#include <string.h>
27+
#include <math.h>
28+
#include <pthread.h>
29+
30+
#include "sb_percentile.h"
31+
32+
int sb_percentile_init(sb_percentile_t *percentile,
33+
unsigned int size, double range_min, double range_max)
34+
{
35+
percentile->values = (unsigned long long *)
36+
calloc(size, sizeof(unsigned long long));
37+
percentile->tmp = (unsigned long long *)
38+
calloc(size, sizeof(unsigned long long));
39+
if (percentile->values == NULL || percentile->tmp == NULL)
40+
{
41+
//log_text(LOG_FATAL, "Cannot allocate values array, size = %u", size);
42+
return 1;
43+
}
44+
45+
percentile->range_deduct = log(range_min);
46+
percentile->range_mult = (size - 1) / (log(range_max) -
47+
percentile->range_deduct);
48+
percentile->range_min = range_min;
49+
percentile->range_max = range_max;
50+
percentile->size = size;
51+
percentile->total = 0;
52+
53+
pthread_mutex_init(&percentile->mutex, NULL);
54+
55+
return 0;
56+
}
57+
58+
void sb_percentile_update(sb_percentile_t *percentile, double value)
59+
{
60+
unsigned int n;
61+
62+
if (value < percentile->range_min)
63+
value= percentile->range_min;
64+
else if (value > percentile->range_max)
65+
value= percentile->range_max;
66+
67+
n = floor((log(value) - percentile->range_deduct) * percentile->range_mult
68+
+ 0.5);
69+
70+
pthread_mutex_lock(&percentile->mutex);
71+
percentile->total++;
72+
percentile->values[n]++;
73+
pthread_mutex_unlock(&percentile->mutex);
74+
}
75+
76+
double sb_percentile_calculate(sb_percentile_t *percentile, double percent)
77+
{
78+
unsigned long long ncur, nmax;
79+
unsigned int i;
80+
81+
pthread_mutex_lock(&percentile->mutex);
82+
83+
if (percentile->total == 0)
84+
{
85+
pthread_mutex_unlock(&percentile->mutex);
86+
return 0.0;
87+
}
88+
89+
memcpy(percentile->tmp, percentile->values,
90+
percentile->size * sizeof(unsigned long long));
91+
nmax = floor(percentile->total * percent / 100 + 0.5);
92+
93+
pthread_mutex_unlock(&percentile->mutex);
94+
95+
ncur = percentile->tmp[0];
96+
for (i = 1; i < percentile->size; i++)
97+
{
98+
ncur += percentile->tmp[i];
99+
if (ncur >= nmax)
100+
break;
101+
}
102+
103+
return exp((i) / percentile->range_mult + percentile->range_deduct);
104+
}
105+
106+
void sb_percentile_reset(sb_percentile_t *percentile)
107+
{
108+
pthread_mutex_lock(&percentile->mutex);
109+
percentile->total = 0;
110+
memset(percentile->values, 0, percentile->size * sizeof(unsigned long long));
111+
pthread_mutex_unlock(&percentile->mutex);
112+
}
113+
114+
void sb_percentile_done(sb_percentile_t *percentile)
115+
{
116+
pthread_mutex_destroy(&percentile->mutex);
117+
free(percentile->values);
118+
free(percentile->tmp);
119+
}

src/sb_percentile.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Copyright (C) 2011 Alexey Kopytov.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; either version 2 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16+
*/
17+
18+
#ifndef SB_PERCENTILE_H
19+
#define SB_PERCENTILE_H
20+
21+
#ifdef HAVE_PTHREAD_H
22+
# include <pthread.h>
23+
#endif
24+
25+
typedef struct {
26+
unsigned long long *values;
27+
unsigned long long *tmp;
28+
unsigned long long total;
29+
unsigned int size;
30+
double range_min;
31+
double range_max;
32+
double range_deduct;
33+
double range_mult;
34+
pthread_mutex_t mutex;
35+
} sb_percentile_t;
36+
37+
int sb_percentile_init(sb_percentile_t *percentile,
38+
unsigned int size, double range_min, double range_max);
39+
40+
void sb_percentile_update(sb_percentile_t *percentile, double value);
41+
42+
double sb_percentile_calculate(sb_percentile_t *percentile, double percent);
43+
44+
void sb_percentile_reset(sb_percentile_t *percentile);
45+
46+
void sb_percentile_done(sb_percentile_t *percentile);
47+
48+
#endif

0 commit comments

Comments
 (0)