Skip to content

Commit

Permalink
fix random seed bug. improve accuracy of benchmark statistics by usin…
Browse files Browse the repository at this point in the history
…g average on the client durations
  • Loading branch information
oranagra committed Mar 26, 2015
1 parent aabf965 commit 16324fc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
30 changes: 19 additions & 11 deletions client.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ inline unsigned long int ts_diff_now(struct timeval a)
return bval - aval;
}

inline timeval timeval_factorial_avarge( timeval a, timeval b, unsigned int weight)
{
timeval tv;
double factor = ((double)weight - 1) / weight;
tv.tv_sec = factor * a.tv_sec + (double)b.tv_sec / weight ;
tv.tv_usec = factor * a.tv_usec + (double)b.tv_usec / weight ;
return (tv);
}

client::request::request(request_type type, unsigned int size, struct timeval* sent_time, unsigned int keys)
: m_type(type), m_size(size), m_keys(keys)
{
Expand Down Expand Up @@ -955,9 +964,10 @@ unsigned long int client_group::get_total_latency(void)
unsigned long int client_group::get_duration_usec(void)
{
unsigned long int duration = 0;
for (std::vector<client*>::iterator i = m_clients.begin(); i != m_clients.end(); i++) {
if ((*i)->get_stats()->get_duration_usec() > duration)
duration = (*i)->get_stats()->get_duration_usec();
unsigned int thread_counter = 1;
for (std::vector<client*>::iterator i = m_clients.begin(); i != m_clients.end(); i++, thread_counter++) {
float factor = ((float)(thread_counter - 1) / thread_counter);
duration = factor * duration + (float)(*i)->get_stats()->get_duration_usec() / thread_counter ;
}

return duration;
Expand All @@ -966,10 +976,10 @@ unsigned long int client_group::get_duration_usec(void)
void client_group::merge_run_stats(run_stats* target)
{
assert(target != NULL);

unsigned int iteration_counter = 1;
for (std::vector<client*>::iterator i = m_clients.begin(); i != m_clients.end(); i++) {
target->merge(*(*i)->get_stats());
}
target->merge(*(*i)->get_stats(), iteration_counter++);
}
}

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

}

void run_stats::merge(const run_stats& other)
void run_stats::merge(const run_stats& other, int iteration)
{
bool new_stats = false;

if (!m_start_time.tv_sec)
m_start_time = other.m_start_time;
if (!m_end_time.tv_sec)
m_end_time = other.m_end_time;
m_start_time = timeval_factorial_avarge( m_start_time, other.m_start_time, iteration );
m_end_time = timeval_factorial_avarge( m_end_time, other.m_end_time, iteration );

// aggregate the one_second_stats vectors. this is not efficient
// but it's not really important (small numbers, not realtime)
Expand Down
2 changes: 1 addition & 1 deletion client.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class run_stats {

void aggregate_average(const std::vector<run_stats>& all_stats);
void summarize(totals& result) const;
void merge(const run_stats& other);
void merge(const run_stats& other, int iteration);
bool save_csv(const char *filename);
void debug_dump(void);
void print(FILE *file, bool histogram);
Expand Down
6 changes: 4 additions & 2 deletions memtier_benchmark.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ run_stats run_benchmark(int run_id, benchmark_config* cfg, object_generator* obj
unsigned long int total_ops = 0;
unsigned long int total_bytes = 0;
unsigned long int duration = 0;
unsigned int thread_counter = 0;
unsigned long int total_latency = 0;

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

unsigned long int cur_ops = total_ops-prev_ops;
Expand Down
1 change: 1 addition & 0 deletions obj_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ random_generator::random_generator()

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

0 comments on commit 16324fc

Please sign in to comment.