Skip to content

Commit 16324fc

Browse files
committed
fix random seed bug. improve accuracy of benchmark statistics by using average on the client durations
1 parent aabf965 commit 16324fc

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

client.cpp

100644100755
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ inline unsigned long int ts_diff_now(struct timeval a)
7979
return bval - aval;
8080
}
8181

82+
inline timeval timeval_factorial_avarge( timeval a, timeval b, unsigned int weight)
83+
{
84+
timeval tv;
85+
double factor = ((double)weight - 1) / weight;
86+
tv.tv_sec = factor * a.tv_sec + (double)b.tv_sec / weight ;
87+
tv.tv_usec = factor * a.tv_usec + (double)b.tv_usec / weight ;
88+
return (tv);
89+
}
90+
8291
client::request::request(request_type type, unsigned int size, struct timeval* sent_time, unsigned int keys)
8392
: m_type(type), m_size(size), m_keys(keys)
8493
{
@@ -955,9 +964,10 @@ unsigned long int client_group::get_total_latency(void)
955964
unsigned long int client_group::get_duration_usec(void)
956965
{
957966
unsigned long int duration = 0;
958-
for (std::vector<client*>::iterator i = m_clients.begin(); i != m_clients.end(); i++) {
959-
if ((*i)->get_stats()->get_duration_usec() > duration)
960-
duration = (*i)->get_stats()->get_duration_usec();
967+
unsigned int thread_counter = 1;
968+
for (std::vector<client*>::iterator i = m_clients.begin(); i != m_clients.end(); i++, thread_counter++) {
969+
float factor = ((float)(thread_counter - 1) / thread_counter);
970+
duration = factor * duration + (float)(*i)->get_stats()->get_duration_usec() / thread_counter ;
961971
}
962972

963973
return duration;
@@ -966,10 +976,10 @@ unsigned long int client_group::get_duration_usec(void)
966976
void client_group::merge_run_stats(run_stats* target)
967977
{
968978
assert(target != NULL);
969-
979+
unsigned int iteration_counter = 1;
970980
for (std::vector<client*>::iterator i = m_clients.begin(); i != m_clients.end(); i++) {
971-
target->merge(*(*i)->get_stats());
972-
}
981+
target->merge(*(*i)->get_stats(), iteration_counter++);
982+
}
973983
}
974984

975985
void client_group::write_client_stats(const char *prefix)
@@ -1294,14 +1304,12 @@ void run_stats::aggregate_average(const std::vector<run_stats>& all_stats)
12941304

12951305
}
12961306

1297-
void run_stats::merge(const run_stats& other)
1307+
void run_stats::merge(const run_stats& other, int iteration)
12981308
{
12991309
bool new_stats = false;
13001310

1301-
if (!m_start_time.tv_sec)
1302-
m_start_time = other.m_start_time;
1303-
if (!m_end_time.tv_sec)
1304-
m_end_time = other.m_end_time;
1311+
m_start_time = timeval_factorial_avarge( m_start_time, other.m_start_time, iteration );
1312+
m_end_time = timeval_factorial_avarge( m_end_time, other.m_end_time, iteration );
13051313

13061314
// aggregate the one_second_stats vectors. this is not efficient
13071315
// but it's not really important (small numbers, not realtime)

client.h

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class run_stats {
106106

107107
void aggregate_average(const std::vector<run_stats>& all_stats);
108108
void summarize(totals& result) const;
109-
void merge(const run_stats& other);
109+
void merge(const run_stats& other, int iteration);
110110
bool save_csv(const char *filename);
111111
void debug_dump(void);
112112
void print(FILE *file, bool histogram);

memtier_benchmark.cpp

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ run_stats run_benchmark(int run_id, benchmark_config* cfg, object_generator* obj
735735
unsigned long int total_ops = 0;
736736
unsigned long int total_bytes = 0;
737737
unsigned long int duration = 0;
738+
unsigned int thread_counter = 0;
738739
unsigned long int total_latency = 0;
739740

740741
for (std::vector<cg_thread*>::iterator i = threads.begin(); i != threads.end(); i++) {
@@ -744,8 +745,9 @@ run_stats run_benchmark(int run_id, benchmark_config* cfg, object_generator* obj
744745
total_ops += (*i)->m_cg->get_total_ops();
745746
total_bytes += (*i)->m_cg->get_total_bytes();
746747
total_latency += (*i)->m_cg->get_total_latency();
747-
if ((*i)->m_cg->get_duration_usec() > duration)
748-
duration = (*i)->m_cg->get_duration_usec();
748+
thread_counter++;
749+
float factor = ((float)(thread_counter - 1) / thread_counter);
750+
duration = factor * duration + (float)(*i)->m_cg->get_duration_usec() / thread_counter ;
749751
}
750752

751753
unsigned long int cur_ops = total_ops-prev_ops;

obj_gen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ random_generator::random_generator()
4141

4242
void random_generator::set_seed(int seed)
4343
{
44+
seed++; //http://stackoverflow.com/questions/27386470/srand0-and-srand1-give-the-same-results
4445
#ifdef HAVE_RANDOM_R
4546
memset(&m_data_blob, 0, sizeof(m_data_blob));
4647
memset(m_state_array, 0, sizeof(m_state_array));

0 commit comments

Comments
 (0)