Skip to content

Commit 40d47a0

Browse files
author
DovKfir
committed
version 1.2.6: random data fix, latency histogram improvements
1 parent e8ab241 commit 40d47a0

File tree

6 files changed

+91
-62
lines changed

6 files changed

+91
-62
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Version 1.2.6
2+
* Improve latency histogram accuracy and range
3+
* Fix --random-data when using many threads
4+
15
* Version 1.2.5
26
* Bugfix in --randomize
37

client.cpp

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,22 @@
4444
#include <assert.h>
4545
#endif
4646

47+
#include <math.h>
4748
#include <algorithm>
4849

4950
#include "client.h"
5051
#include "obj_gen.h"
5152
#include "memtier_benchmark.h"
5253

54+
float get_2_meaningful_digits(float val)
55+
{
56+
float log = floor(log10(val));
57+
float factor = pow(10, log-1); // to save 2 digits
58+
float new_val = round( val / factor);
59+
new_val *= factor;
60+
return new_val;
61+
}
62+
5363
void client_event_handler(evutil_socket_t sfd, short evtype, void *opaque)
5464
{
5565
client *c = (client *) opaque;
@@ -1067,8 +1077,6 @@ run_stats::run_stats() :
10671077
{
10681078
memset(&m_start_time, 0, sizeof(m_start_time));
10691079
memset(&m_end_time, 0, sizeof(m_end_time));
1070-
memset(m_get_latency, 0, sizeof(m_get_latency));
1071-
memset(m_set_latency, 0, sizeof(m_set_latency));
10721080
}
10731081

10741082
void run_stats::set_start_time(struct timeval* start_time)
@@ -1122,10 +1130,7 @@ void run_stats::update_get_op(struct timeval* ts, unsigned int bytes, unsigned i
11221130
m_totals.m_ops++;
11231131
m_totals.m_latency += latency;
11241132

1125-
unsigned int msec_latency = latency / 1000;
1126-
if (msec_latency > MAX_LATENCY_HISTOGRAM)
1127-
msec_latency = MAX_LATENCY_HISTOGRAM;
1128-
m_get_latency[msec_latency]++;
1133+
m_get_latency_map[get_2_meaningful_digits((float)latency/1000)]++;
11291134
}
11301135

11311136
void run_stats::update_set_op(struct timeval* ts, unsigned int bytes, unsigned int latency)
@@ -1140,10 +1145,7 @@ void run_stats::update_set_op(struct timeval* ts, unsigned int bytes, unsigned i
11401145
m_totals.m_ops++;
11411146
m_totals.m_latency += latency;
11421147

1143-
unsigned int msec_latency = latency / 1000;
1144-
if (msec_latency > MAX_LATENCY_HISTOGRAM)
1145-
msec_latency = MAX_LATENCY_HISTOGRAM;
1146-
m_set_latency[msec_latency]++;
1148+
m_set_latency_map[get_2_meaningful_digits(latency/1000)]++;
11471149
}
11481150

11491151
unsigned int run_stats::get_duration(void)
@@ -1214,24 +1216,24 @@ bool run_stats::save_csv(const char *filename)
12141216
total_set_ops += i->m_ops_set;
12151217
}
12161218

1217-
unsigned long int total_count = 0;
1219+
1220+
double total_count_float = 0;
1221+
int i=0;
12181222
fprintf(f, "\n" "Full-Test GET Latency\n");
12191223
fprintf(f, "Latency (<= msec),Percent\n");
1220-
for (int i = 0; i <= MAX_LATENCY_HISTOGRAM; i++) {
1221-
if (m_get_latency[i] > 0) {
1222-
total_count += m_get_latency[i];
1223-
fprintf(f, "%u,%.2f\n", i, (double) total_count / total_get_ops * 100);
1224-
}
1224+
for ( latency_map_itr it = m_get_latency_map.begin() ; it != m_get_latency_map.end() ; it++ ) {
1225+
total_count_float += it->second;
1226+
fprintf(f, "%u,%.2f\n", i, total_count_float / total_get_ops * 100);
1227+
i++;
12251228
}
1226-
1229+
i=0;
12271230
fprintf(f, "\n" "Full-Test SET Latency\n");
12281231
fprintf(f, "Latency (<= msec),Percent\n");
1229-
total_count = 0;
1230-
for (int i = 0; i <= MAX_LATENCY_HISTOGRAM; i++) {
1231-
if (m_set_latency[i] > 0) {
1232-
total_count += m_set_latency[i];
1233-
fprintf(f, "%u,%.2f\n", i, (double) total_count / total_set_ops * 100);
1234-
}
1232+
1233+
for ( latency_map_itr it = m_set_latency_map.begin(); it != m_set_latency_map.end() ; it++ ) {
1234+
total_count_float += it->second;
1235+
fprintf(f, "%u,%.2f\n", i, total_count_float / total_get_ops * 100);
1236+
i++;
12351237
}
12361238

12371239
fclose(f);
@@ -1259,14 +1261,14 @@ void run_stats::debug_dump(void)
12591261
i->m_get_misses);
12601262
}
12611263

1262-
for (int i = 0; i <= MAX_LATENCY_HISTOGRAM; i++) {
1263-
if (m_get_latency[i] > 0)
1264-
benchmark_debug_log(" GET <= %u msec: %u\n", i, m_get_latency[i]);
1265-
}
12661264

1267-
for (int i = 0; i <= MAX_LATENCY_HISTOGRAM; i++) {
1268-
if (m_set_latency[i] > 0)
1269-
benchmark_debug_log(" SET <= %u msec: %u\n", i, m_set_latency[i]);
1265+
for( latency_map_itr it = m_get_latency_map.begin() ; it != m_get_latency_map.end() ; it++) {
1266+
if (it->second)
1267+
benchmark_debug_log(" GET <= %u msec: %u\n", it->first, it->second);
1268+
}
1269+
for( latency_map_itr it = m_set_latency_map.begin() ; it != m_set_latency_map.end() ; it++) {
1270+
if (it->second)
1271+
benchmark_debug_log(" SET <= %u msec: %u\n", it->first, it->second);
12701272
}
12711273
}
12721274

@@ -1284,12 +1286,14 @@ void run_stats::aggregate_average(const std::vector<run_stats>& all_stats)
12841286
m_totals.add(i_totals);
12851287

12861288
// aggregate latency data
1287-
for (int j = 0; j < MAX_LATENCY_HISTOGRAM + 1; j++) {
1288-
m_get_latency[j] += i->m_get_latency[j];
1289-
m_set_latency[j] += i->m_set_latency[j];
1290-
}
1291-
}
12921289

1290+
for( latency_map_itr_const it = i->m_get_latency_map.begin() ; it != i->m_get_latency_map.end() ; it++) {
1291+
m_get_latency_map[it->first] += it->second;
1292+
}
1293+
for( latency_map_itr_const it = i->m_set_latency_map.begin() ; it != i->m_set_latency_map.end() ; it++) {
1294+
m_set_latency_map[it->first] += it->second;
1295+
}
1296+
}
12931297
m_totals.m_ops_sec_set /= all_stats.size();
12941298
m_totals.m_ops_sec_get /= all_stats.size();
12951299
m_totals.m_ops_sec /= all_stats.size();
@@ -1342,11 +1346,13 @@ void run_stats::merge(const run_stats& other, int iteration)
13421346
m_totals.m_ops += other.m_totals.m_ops;
13431347

13441348
// aggregate latency data
1345-
for (int i = 0; i < MAX_LATENCY_HISTOGRAM + 1; i++) {
1346-
m_get_latency[i] += other.m_get_latency[i];
1347-
m_set_latency[i] += other.m_set_latency[i];
1349+
for( latency_map_itr_const it = other.m_get_latency_map.begin() ; it != other.m_get_latency_map.end() ; it++) {
1350+
m_get_latency_map[it->first] += it->second;
1351+
}
1352+
for( latency_map_itr_const it = other.m_set_latency_map.begin() ; it != other.m_set_latency_map.end() ; it++) {
1353+
m_set_latency_map[it->first] += it->second;
13481354
}
1349-
1355+
13501356
}
13511357

13521358
void run_stats::summarize(totals& result) const
@@ -1440,25 +1446,19 @@ void run_stats::print(FILE *out, bool histogram)
14401446
"Request Latency Distribution\n"
14411447
"%-6s %12s %12s\n"
14421448
"------------------------------------------------------------------------\n",
1443-
"Type", "<= msec", "Percent");
1449+
"Type", "<= msec ", "Percent");
14441450

14451451
unsigned long int total_count = 0;
1446-
for (int i = 0; i <= MAX_LATENCY_HISTOGRAM; i++) {
1447-
if (m_set_latency[i] > 0) {
1448-
total_count += m_set_latency[i];
1449-
fprintf(out, "%-6s %12u %12.2f\n",
1450-
"SET", i, (double) total_count / m_totals.m_ops_set * 100);
1451-
}
1452+
for( latency_map_itr_const it = m_set_latency_map.begin() ; it != m_set_latency_map.end() ; it++) {
1453+
total_count += it->second;
1454+
fprintf(out, "%-6s %8.3f %12.2f\n", "SET", it->first, (double) total_count / m_totals.m_ops_set * 100);
14521455
}
1456+
total_count = 0;
14531457

14541458
fprintf(out, "---\n");
1455-
total_count = 0;
1456-
for (int i = 0; i <= MAX_LATENCY_HISTOGRAM; i++) {
1457-
if (m_get_latency[i] > 0) {
1458-
total_count += m_get_latency[i];
1459-
fprintf(out, "%-6s %12u %12.2f\n",
1460-
"GET", i, (double) total_count / m_totals.m_ops_get * 100);
1461-
}
1462-
}
1459+
for( latency_map_itr_const it = m_get_latency_map.begin() ; it != m_get_latency_map.end() ; it++) {
1460+
total_count += it->second;
1461+
fprintf(out, "%-6s %8.3f %12.2f\n", "GET", it->first, (double) total_count / m_totals.m_ops_get * 100);
1462+
}
14631463
}
14641464

client.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#include <sys/un.h>
2727
#include <vector>
2828
#include <queue>
29-
29+
#include <map>
30+
#include <iterator>
3031
#include <event2/event.h>
3132
#include <event2/buffer.h>
3233

@@ -39,7 +40,10 @@ struct benchmark_config;
3940
class object_generator;
4041
class data_object;
4142

42-
#define MAX_LATENCY_HISTOGRAM 5000
43+
typedef std::map<float, int> latency_map;
44+
typedef std::map<float, int>::iterator latency_map_itr;
45+
typedef std::map<float, int>::const_iterator latency_map_itr_const;
46+
4347
class run_stats {
4448
protected:
4549
struct one_second_stats {
@@ -92,8 +96,8 @@ class run_stats {
9296
std::vector<one_second_stats> m_stats;
9397
one_second_stats m_cur_stats;
9498

95-
unsigned int m_get_latency[MAX_LATENCY_HISTOGRAM+1];
96-
unsigned int m_set_latency[MAX_LATENCY_HISTOGRAM+1];
99+
latency_map m_get_latency_map;
100+
latency_map m_set_latency_map;
97101
void roll_cur_stats(struct timeval* ts);
98102

99103
public:

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dnl You should have received a copy of the GNU General Public License
1616
dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

1818
AC_PREREQ(2.59)
19-
AC_INIT(memtier_benchmark,1.2.5,[email protected])
19+
AC_INIT(memtier_benchmark,1.2.6,[email protected])
2020
AC_CONFIG_SRCDIR([memtier_benchmark.cpp])
2121
AC_CONFIG_HEADER([config.h])
2222
AM_INIT_AUTOMAKE

obj_gen.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ object_generator::object_generator(const object_generator& copy) :
156156
m_data_size.size_list != NULL) {
157157
m_data_size.size_list = new config_weight_list(*m_data_size.size_list);
158158
}
159-
160-
alloc_value_buffer();
159+
alloc_value_buffer(copy.m_value_buffer);
161160
for (int i = 0; i < OBJECT_GENERATOR_KEY_ITERATORS; i++)
162161
m_next_key[i] = 0;
163162
}
@@ -191,7 +190,7 @@ void object_generator::alloc_value_buffer(void)
191190
unsigned int size = 0;
192191

193192
if (m_value_buffer != NULL)
194-
free(m_value_buffer);
193+
free(m_value_buffer), m_value_buffer = NULL;
195194

196195
if (m_data_size_type == data_size_fixed)
197196
size = m_data_size.size_fixed;
@@ -243,6 +242,27 @@ void object_generator::alloc_value_buffer(void)
243242
}
244243
}
245244

245+
void object_generator::alloc_value_buffer(const char* copy_from)
246+
{
247+
unsigned int size = 0;
248+
249+
if (m_value_buffer != NULL)
250+
free(m_value_buffer), m_value_buffer = NULL;
251+
252+
if (m_data_size_type == data_size_fixed)
253+
size = m_data_size.size_fixed;
254+
else if (m_data_size_type == data_size_range)
255+
size = m_data_size.size_range.size_max;
256+
else if (m_data_size_type == data_size_weighted)
257+
size = m_data_size.size_list->largest();
258+
259+
if (size > 0) {
260+
m_value_buffer = (char*) malloc(size);
261+
assert(m_value_buffer != NULL);
262+
memcpy(m_value_buffer, copy_from, size);
263+
}
264+
}
265+
246266
void object_generator::set_random_data(bool random_data)
247267
{
248268
m_random_data = random_data;

obj_gen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class object_generator {
109109
gaussian_noise m_random;
110110

111111
void alloc_value_buffer(void);
112+
void alloc_value_buffer(const char* copy_from);
112113
void random_init(void);
113114
unsigned int random_range(unsigned int r_min, unsigned int r_max);
114115
unsigned int normal_distribution(unsigned int r_min, unsigned int r_max, double r_stddev, double r_median);

0 commit comments

Comments
 (0)