-
Notifications
You must be signed in to change notification settings - Fork 7
/
ycsb.cc
432 lines (377 loc) · 14.4 KB
/
ycsb.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#include <iostream>
#include <chrono>
#include <random>
#include <cstring>
#include <vector>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <atomic>
#include <thread>
//#include "tbb/tbb.h"
#include "iceberg_table.h"
using namespace std;
// index types
enum {
TYPE_ICEBERG,
TYPE_CUCKOO,
TYPE_DASH,
};
enum {
OP_INSERT,
OP_UPDATE,
OP_READ,
OP_SCAN,
OP_DELETE,
};
enum {
WORKLOAD_A,
WORKLOAD_B,
WORKLOAD_C,
WORKLOAD_D,
WORKLOAD_E,
};
enum {
RANDINT_KEY,
STRING_KEY,
};
enum {
UNIFORM,
ZIPFIAN,
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////Helper functions for Icerberg HashTable/////////////////
typedef struct thread_data {
uint32_t id;
iceberg_table *ht;
} thread_data_t;
/////////////////////////////////////////////////////////////////////////////////
static uint64_t LOAD_SIZE = 64000000;
static uint64_t RUN_SIZE = 1280000000;
void ycsb_load_run_randint(int index_type, int wl, int kt, int ap, int num_thread,
std::vector<uint64_t> &init_keys,
std::vector<uint64_t> &keys,
std::vector<int> &ranges,
std::vector<int> &ops,
char *pmem_dir)
{
std::string init_file;
std::string txn_file;
if (ap == UNIFORM) {
if (kt == RANDINT_KEY && wl == WORKLOAD_A) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loada_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnsa_unif_int.dat";
} else if (kt == RANDINT_KEY && wl == WORKLOAD_B) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loadb_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnsb_unif_int.dat";
} else if (kt == RANDINT_KEY && wl == WORKLOAD_C) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loadc_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnsc_unif_int.dat";
} else if (kt == RANDINT_KEY && wl == WORKLOAD_D) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loadd_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnsd_unif_int.dat";
} else if (kt == RANDINT_KEY && wl == WORKLOAD_E) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loade_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnse_unif_int.dat";
}
} else {
if (kt == RANDINT_KEY && wl == WORKLOAD_A) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loada_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnsa_unif_int.dat";
} else if (kt == RANDINT_KEY && wl == WORKLOAD_B) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loadb_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnsb_unif_int.dat";
} else if (kt == RANDINT_KEY && wl == WORKLOAD_C) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loadc_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnsc_unif_int.dat";
} else if (kt == RANDINT_KEY && wl == WORKLOAD_D) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loadd_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnsd_unif_int.dat";
} else if (kt == RANDINT_KEY && wl == WORKLOAD_E) {
init_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/loade_unif_int.dat";
txn_file = "/mnt/nvme3/RECIPE/index-microbench/workloads/txnse_unif_int.dat";
}
}
std::ifstream infile_load(init_file);
std::string op;
uint64_t key;
int range;
std::string insert("INSERT");
std::string update("UPDATE");
std::string read("READ");
std::string scan("SCAN");
int count = 0;
while (infile_load.good()) {
infile_load >> op >> key;
if (op.compare(insert) != 0) {
std::cout << "READING LOAD FILE FAIL!\n";
return ;
}
init_keys.push_back(key);
count++;
}
count--;
fprintf(stderr, "Loaded %d keys\n", count);
std::ifstream infile_txn(txn_file);
uint64_t txn_count = 0;
while (infile_txn.good()) {
infile_txn >> op >> key;
if (op.compare(insert) == 0) {
ops.push_back(OP_INSERT);
keys.push_back(key);
ranges.push_back(1);
} else if (op.compare(update) == 0) {
ops.push_back(OP_UPDATE);
keys.push_back(key);
ranges.push_back(1);
} else if (op.compare(read) == 0) {
ops.push_back(OP_READ);
keys.push_back(key);
ranges.push_back(1);
} else if (op.compare(scan) == 0) {
infile_txn >> range;
ops.push_back(OP_SCAN);
keys.push_back(key);
ranges.push_back(range);
} else {
std::cout << "UNRECOGNIZED CMD!\n";
return;
}
txn_count++;
}
txn_count--;
fprintf(stderr, "Loaded %" PRIu64 " txn keys\n", txn_count);
std::atomic<int> range_complete, range_incomplete;
range_complete.store(0);
range_incomplete.store(0);
if (index_type == TYPE_ICEBERG) {
iceberg_table hashtable;
#ifdef PMEM
iceberg_init(&hashtable, 24, pmem_dir);
#else
iceberg_init(&hashtable, 24);
#endif
thread_data_t *tds = (thread_data_t *) malloc(num_thread * sizeof(thread_data_t));
std::atomic<int> next_thread_id;
{
// Load
auto starttime = std::chrono::system_clock::now();
next_thread_id.store(0);
auto func = [&]() {
int thread_id = next_thread_id.fetch_add(1);
tds[thread_id].id = thread_id;
tds[thread_id].ht = &hashtable;
uint64_t start_key = LOAD_SIZE / num_thread * (uint64_t)thread_id;
uint64_t end_key = start_key + LOAD_SIZE / num_thread;
for (uint64_t i = start_key; i < end_key; i++) {
if(!iceberg_insert(tds[thread_id].ht, init_keys[i],
init_keys[i], thread_id)) {
printf("Failed insert\n");
exit(0);
}
//printf("\rInsert %ld", i);
//fflush(stdout);
}
};
std::vector<std::thread> thread_group;
for (int i = 0; i < num_thread; i++)
thread_group.push_back(std::thread{func});
for (int i = 0; i < num_thread; i++)
thread_group[i].join();
iceberg_end(&hashtable);
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now() - starttime);
printf("Throughput: load, %f ,ops/us\n", (LOAD_SIZE * 1.0) / duration.count());
#if 0
#if PMEM
iceberg_dismount(&hashtable);
starttime = std::chrono::system_clock::now();
iceberg_mount(&hashtable, 24, 2);
duration = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now() - starttime);
printf("Throughput: mount, %f ,ops/us\n", (LOAD_SIZE * 1.0) / duration.count());
#endif
#endif
}
{
// Run
auto starttime = std::chrono::system_clock::now();
next_thread_id.store(0);
auto func = [&]() {
int thread_id = next_thread_id.fetch_add(1);
tds[thread_id].id = thread_id;
tds[thread_id].ht = &hashtable;
uint64_t start_key = txn_count / num_thread * (uint64_t)thread_id;
uint64_t end_key = start_key + txn_count / num_thread;
#ifdef LATENCY
std::vector<double> insert_times;
std::vector<double> query_times;
#endif
for (uint64_t i = start_key; i < end_key; i++) {
if (ops[i] == OP_INSERT) {
#ifdef LATENCY
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
#endif
if(!iceberg_insert(tds[thread_id].ht, keys[i],
keys[i], thread_id)) {
printf("Failed insert\n");
exit(0);
}
#ifdef LATENCY
std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
insert_times.emplace_back(std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count());
#endif
} else if (ops[i] == OP_READ) {
uintptr_t val;
#ifdef LATENCY
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
#endif
auto ret = iceberg_get_value(tds[thread_id].ht, keys[i], &val, thread_id);
if (val != keys[i]) {
std::cout << "[ICEBERG] wrong key read: " << val << " expected: " << keys[i] << " ret: " << ret << std::endl;
exit(1);
}
#ifdef LATENCY
std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
query_times.emplace_back(std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count());
#endif
} else if (ops[i] == OP_SCAN) {
std::cout << "NOT SUPPORTED CMD!\n";
exit(0);
} else if (ops[i] == OP_UPDATE) {
std::cout << "NOT SUPPORTED CMD!\n";
exit(0);
}
}
#ifdef LATENCY
std::ofstream f;
f.open("ycsb_insert_times_" + std::to_string(thread_id) + ".log");
for (auto time : insert_times) {
f << time << '\n';
}
f.close();
std::ofstream g;
g.open("ycsb_query_times_" + std::to_string(thread_id) + ".log");
for (auto time : query_times) {
g << time << '\n';
}
g.close();
#endif
};
std::vector<std::thread> thread_group;
for (int i = 0; i < num_thread; i++)
thread_group.push_back(std::thread{func});
for (int i = 0; i < num_thread; i++)
thread_group[i].join();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now() - starttime);
printf("Throughput: run, %f ,ops/us\n", (txn_count * 1.0) / duration.count());
}
// TODO: Add a iceberg destroy function
}
}
int main(int argc, char **argv) {
#ifdef PMEM
#define NARGS 7
#else
#define NARGS 6
#endif
if (argc != NARGS) {
#ifdef PMEM
std::cout << "Usage: ./ycsb <index type> <ycsb workload type> <key distribution> <access pattern> <number of threads> <pmem directory>\n";
#else
std::cout << "Usage: ./ycsb <index type> <ycsb workload type> <key distribution> <access pattern> <number of threads>\n";
#endif
std::cout << "1. index type: iceberg cuckoo dash\n";
std::cout << "2. ycsb workload type: a, b, c, e\n";
std::cout << "3. key distribution: randint\n";
std::cout << "4. access pattern: uniform\n";
std::cout << "5. number of threads (integer)\n";
#ifdef PMEM
std::cout << "6. directory where pmme files should be stored.\n";
#endif
return 1;
}
printf("%s, workload%s, %s, %s, threads %s\n", argv[1], argv[2], argv[3], argv[4], argv[5]);
int index_type;
if (strcmp(argv[1], "iceberg") == 0)
index_type = TYPE_ICEBERG;
else if (strcmp(argv[1], "cuckoo") == 0)
index_type = TYPE_CUCKOO;
else if (strcmp(argv[1], "dash") == 0)
index_type = TYPE_DASH;
else {
fprintf(stderr, "Unknown index type: %s\n", argv[1]);
exit(1);
}
int wl;
if (strcmp(argv[2], "a") == 0) {
wl = WORKLOAD_A;
} else if (strcmp(argv[2], "b") == 0) {
wl = WORKLOAD_B;
} else if (strcmp(argv[2], "c") == 0) {
wl = WORKLOAD_C;
} else if (strcmp(argv[2], "d") == 0) {
wl = WORKLOAD_D;
} else if (strcmp(argv[2], "e") == 0) {
wl = WORKLOAD_E;
} else {
fprintf(stderr, "Unknown workload: %s\n", argv[2]);
exit(1);
}
int kt;
if (strcmp(argv[3], "randint") == 0) {
kt = RANDINT_KEY;
} else {
fprintf(stderr, "Unknown key type: %s\n", argv[3]);
exit(1);
}
int ap;
if (strcmp(argv[4], "uniform") == 0) {
ap = UNIFORM;
} else if (strcmp(argv[4], "zipfian") == 0) {
ap = ZIPFIAN;
} else {
fprintf(stderr, "Unknown access pattern: %s\n", argv[4]);
exit(1);
}
int num_thread = atoi(argv[5]);
char *pmem_dir = NULL;
#ifdef PMEM
pmem_dir = argv[6];
#endif
//tbb::task_scheduler_init init(num_thread);
if (kt != STRING_KEY) {
std::vector<uint64_t> init_keys;
std::vector<uint64_t> keys;
std::vector<int> ranges;
std::vector<int> ops;
init_keys.reserve(LOAD_SIZE);
keys.reserve(RUN_SIZE);
ranges.reserve(RUN_SIZE);
ops.reserve(RUN_SIZE);
memset(&init_keys[0], 0x00, LOAD_SIZE * sizeof(uint64_t));
memset(&keys[0], 0x00, RUN_SIZE * sizeof(uint64_t));
memset(&ranges[0], 0x00, RUN_SIZE * sizeof(int));
memset(&ops[0], 0x00, RUN_SIZE * sizeof(int));
ycsb_load_run_randint(index_type, wl, kt, ap, num_thread, init_keys, keys, ranges, ops, pmem_dir);
}
/*
else {
std::vector<Key *> init_keys;
std::vector<Key *> keys;
std::vector<int> ranges;
std::vector<int> ops;
init_keys.reserve(LOAD_SIZE);
keys.reserve(RUN_SIZE);
ranges.reserve(RUN_SIZE);
ops.reserve(RUN_SIZE);
memset(&init_keys[0], 0x00, LOAD_SIZE * sizeof(Key *));
memset(&keys[0], 0x00, RUN_SIZE * sizeof(Key *));
memset(&ranges[0], 0x00, RUN_SIZE * sizeof(int));
memset(&ops[0], 0x00, RUN_SIZE * sizeof(int));
ycsb_load_run_string(index_type, wl, kt, ap, num_thread, init_keys, keys, ranges, ops);
}
*/
return 0;
}