@@ -83,14 +83,14 @@ void init(const std::string& key_path, const std::string& db_path, rocksdb::DB**
83
83
options->max_open_files = -1 ; // pre-load indexes and filters
84
84
85
85
// 2GB config
86
- // options->write_buffer_size = 2 * 1048576;
87
- // options->max_bytes_for_level_base = 10 * 1048576;
88
- // options->target_file_size_base = 2 * 1048576;
86
+ options->write_buffer_size = 2 * 1048576 ;
87
+ options->max_bytes_for_level_base = 10 * 1048576 ;
88
+ options->target_file_size_base = 2 * 1048576 ;
89
89
90
90
// 100GB config
91
- options->write_buffer_size = 64 * 1048576 ;
92
- options->max_bytes_for_level_base = 256 * 1048576 ;
93
- options->target_file_size_base = 64 * 1048576 ;
91
+ // options->write_buffer_size = 64 * 1048576;
92
+ // options->max_bytes_for_level_base = 256 * 1048576;
93
+ // options->target_file_size_base = 64 * 1048576;
94
94
95
95
if (use_direct_io > 0 )
96
96
options->use_direct_reads = true ;
@@ -192,42 +192,7 @@ void testScan(const std::string& key_path, rocksdb::DB* db, uint64_t key_count)
192
192
std::cout << " elapsed: " << (static_cast <double >(elapsed) / 1000000000 .) << " \n " ;
193
193
std::cout << " throughput: " << (static_cast <double >(key_count) / (static_cast <double >(elapsed) / 1000000000 .)) << " \n " ;
194
194
}
195
- /*
196
- void warmup(rocksdb::DB* db, uint64_t key_range, uint64_t query_count) {
197
- struct timespec ts_start;
198
- struct timespec ts_end;
199
- uint64_t elapsed;
200
-
201
- std::cout << "warming up\n";
202
- clock_gettime(CLOCK_MONOTONIC, &ts_start);
203
-
204
- for (uint64_t i = 0; i < query_count; i++) {
205
- uint64_t key = key_range / query_count * i + 1;
206
- key = htobe64(key);
207
-
208
- rocksdb::Slice s_key(reinterpret_cast<const char*>(&key), sizeof(key));
209
- std::string s_value;
210
- uint64_t value;
211
-
212
- rocksdb::Status status = db->Get(rocksdb::ReadOptions(), s_key, &s_value);
213
-
214
- if (status.ok()) {
215
- assert(s_value.size() >= sizeof(uint64_t));
216
- value = *reinterpret_cast<const uint64_t*>(s_value.data());
217
- (void)value;
218
- }
219
- }
220
-
221
- clock_gettime(CLOCK_MONOTONIC, &ts_end);
222
- elapsed = static_cast<uint64_t>(ts_end.tv_sec) * 1000000000UL +
223
- static_cast<uint64_t>(ts_end.tv_nsec) -
224
- static_cast<uint64_t>(ts_start.tv_sec) * 1000000000UL +
225
- static_cast<uint64_t>(ts_start.tv_nsec);
226
195
227
- std::cout << "elapsed: " << (static_cast<double>(elapsed) / 1000000000.) << "\n";
228
- std::cout << "throughput: " << (static_cast<double>(query_count) / (static_cast<double>(elapsed) / 1000000000.)) << "\n";
229
- }
230
- */
231
196
void warmup (const std::string key_path, uint64_t key_count, uint64_t sample_gap, rocksdb::DB* db) {
232
197
std::ifstream keyFile (key_path);
233
198
std::vector<uint64_t > keys;
@@ -360,17 +325,6 @@ void benchOpenRangeQuery(rocksdb::DB* db, rocksdb::Options* options, uint64_t ke
360
325
uint64_t j = 0 ;
361
326
for (it->Seek (s_key); it->Valid () && j < scan_length; it->Next (), j++) {
362
327
uint64_t found_key = *reinterpret_cast <const uint64_t *>(it->key ().data ());
363
-
364
- // std::cout << std::hex << found_key << std::dec << "========================================\n";
365
-
366
- // if (i < 20)
367
- // std::cout << std::hex << found_key << std::dec << "\n";
368
- /*
369
- for (int k = 0; k < 8; k++)
370
- std::cout << std::hex << (uint16_t)it->key().data()[k] << " ";
371
- std::cout << std::dec << "\n";
372
- */
373
-
374
328
assert (it->value ().size () >= sizeof (uint64_t ));
375
329
value = *reinterpret_cast <const uint64_t *>(it->value ().data ());
376
330
(void )value;
@@ -461,70 +415,8 @@ void benchClosedRangeQuery(rocksdb::DB* db, rocksdb::Options* options, uint64_t
461
415
std::cout << latencies;
462
416
}
463
417
464
- /*
465
- void benchClosedRangeQuery(rocksdb::DB* db, uint64_t key_count, uint64_t key_gap,
466
- uint64_t query_count, uint64_t range_size) {
467
- std::random_device rd;
468
- std::mt19937_64 e(rd());
469
- std::uniform_int_distribution<unsigned long long> dist(0, (key_count * key_gap));
470
-
471
- std::vector<uint64_t> query_keys;
472
-
473
- for (uint64_t i = 0; i < query_count; i++) {
474
- uint64_t r = dist(e);
475
- query_keys.push_back(r);
476
- }
477
-
478
- struct timespec ts_start;
479
- struct timespec ts_end;
480
- uint64_t elapsed;
481
-
482
- printf("closed range query\n");
483
- rocksdb::Iterator* it = db->NewIterator(rocksdb::ReadOptions());
484
-
485
- clock_gettime(CLOCK_MONOTONIC, &ts_start);
486
-
487
- uint64_t count = 0;
488
-
489
- for (uint64_t i = 0; i < query_count; i++) {
490
- uint64_t key = query_keys[i];
491
- key = htobe64(key);
492
- rocksdb::Slice s_key(reinterpret_cast<const char*>(&key), sizeof(key));
493
-
494
- uint64_t until_key = query_keys[i] + 1000000;
495
- until_key = htobe64(until_key);
496
- rocksdb::Slice s_until_key(reinterpret_cast<const char*>(&until_key), sizeof(until_key));
497
- bool inclusive = false;
498
-
499
- std::string s_value;
500
- uint64_t value;
501
-
502
- uint64_t j = 0;
503
- for (it->SeekUntil(s_key, s_until_key, inclusive); it->Valid(); it->Next(), j++) {
504
- uint64_t found_key = *reinterpret_cast<const uint64_t*>(it->key().data());
505
- if (be64toh(found_key) >= be64toh(until_key))
506
- break;
507
- count++;
508
- }
509
- }
510
-
511
- std::cout << "count per op = " << ((count + 0.0) / query_count) << "\n";
512
-
513
- clock_gettime(CLOCK_MONOTONIC, &ts_end);
514
- elapsed = static_cast<uint64_t>(ts_end.tv_sec) * 1000000000UL +
515
- static_cast<uint64_t>(ts_end.tv_nsec) -
516
- static_cast<uint64_t>(ts_start.tv_sec) * 1000000000UL +
517
- static_cast<uint64_t>(ts_start.tv_nsec);
518
-
519
- std::cout << "elapsed: " << (static_cast<double>(elapsed) / 1000000000.) << "\n";
520
- std::cout << "throughput: " << (static_cast<double>(query_count) / (static_cast<double>(elapsed) / 1000000000.)) << "\n";
521
-
522
- delete it;
523
- }
524
- */
525
-
526
418
void printIO () {
527
- FILE* fp = fopen (" /sys/block/sda/sda2 /stat" , " r" );
419
+ FILE* fp = fopen (" /sys/block/sda/sda1 /stat" , " r" );
528
420
if (fp == NULL ) {
529
421
printf (" Error: empty fp\n " );
530
422
printf (" %s\n " , strerror (errno));
@@ -538,7 +430,7 @@ void printIO() {
538
430
}
539
431
540
432
uint64_t getIOCount () {
541
- std::ifstream io_file (std::string (" /sys/block/sda/sda2 /stat" ));
433
+ std::ifstream io_file (std::string (" /sys/block/sda/sda1 /stat" ));
542
434
uint64_t io_count = 0 ;
543
435
io_file >> io_count;
544
436
return io_count;
@@ -572,18 +464,19 @@ int main(int argc, const char* argv[]) {
572
464
std::cout << " \t 0: no filter\n " ;
573
465
std::cout << " \t 1: Bloom filter\n " ;
574
466
std::cout << " \t 2: SuRF\n " ;
575
- std::cout << " \t 2 : SuRF Hash\n " ;
576
- std::cout << " \t 2 : SuRF Real\n " ;
467
+ std::cout << " \t 3 : SuRF Hash\n " ;
468
+ std::cout << " \t 4 : SuRF Real\n " ;
577
469
std::cout << " arg 3: compression?\n " ;
578
470
std::cout << " \t 0: no compression\n " ;
579
471
std::cout << " \t 1: Snappy\n " ;
580
472
std::cout << " arg 4: use direct I/O?\n " ;
581
473
std::cout << " \t 0: no\n " ;
582
474
std::cout << " \t 1: yes\n " ;
583
475
std::cout << " arg 5: query type\n " ;
584
- std::cout << " \t 0: point query\n " ;
585
- std::cout << " \t 1: open range query\n " ;
586
- std::cout << " \t 2: closed range query\n " ;
476
+ std::cout << " \t 0: init\n " ;
477
+ std::cout << " \t 1: point query\n " ;
478
+ std::cout << " \t 2: open range query\n " ;
479
+ std::cout << " \t 3: closed range query\n " ;
587
480
std::cout << " arg 6: range size\n " ;
588
481
std::cout << " arg 7: warmup # of queries\n " ;
589
482
return -1 ;
@@ -597,20 +490,19 @@ int main(int argc, const char* argv[]) {
597
490
uint64_t range_size = (uint64_t )atoi (argv[6 ]);
598
491
uint64_t warmup_query_count = (uint64_t )atoi (argv[7 ]);
599
492
uint64_t scan_length = 1 ;
600
- // uint64_t range_size = 5000000;
601
493
602
- const std::string kKeyPath = " /home/huanchen/rocksdb/filter_experiment/ poisson_timestamps.csv" ;
494
+ const std::string kKeyPath = " poisson_timestamps.csv" ;
603
495
const uint64_t kValueSize = 1000 ;
604
496
const uint64_t kKeyRange = 10000000000000 ;
605
497
const uint64_t kQueryCount = 50000 ;
606
498
607
499
// 2GB config
608
- // const uint64_t kKeyCount = 2000000;
609
- // const uint64_t kWarmupSampleGap = 100;
500
+ const uint64_t kKeyCount = 2000000 ;
501
+ const uint64_t kWarmupSampleGap = 100 ;
610
502
611
503
// 100GB config
612
- const uint64_t kKeyCount = 100000000 ;
613
- const uint64_t kWarmupSampleGap = kKeyCount / warmup_query_count;
504
+ // const uint64_t kKeyCount = 100000000;
505
+ // const uint64_t kWarmupSampleGap = kKeyCount / warmup_query_count;
614
506
615
507
// =========================================================================
616
508
@@ -620,6 +512,9 @@ int main(int argc, const char* argv[]) {
620
512
621
513
init (kKeyPath , db_path, &db, &options, &table_options, use_direct_io, kKeyCount , kValueSize , filter_type, compression_type);
622
514
515
+ if (query_type == 0 )
516
+ return 0 ;
517
+
623
518
// =========================================================================
624
519
625
520
// testScan(db, kKeyCount);
@@ -635,34 +530,34 @@ int main(int argc, const char* argv[]) {
635
530
// std::cout << options.statistics->ToString() << "\n";
636
531
// printIO();
637
532
638
- uint64_t mem_free_after = getMemFree ();
639
- uint64_t mem_available_after = getMemAvailable ();
640
- std::cout << " Mem Free diff: " << (mem_free_before - mem_free_after) << " \n " ;
641
- std::cout << " Mem Aavilable diff: " << (mem_available_before - mem_available_after) << " \n " ;
533
+ // uint64_t mem_free_after = getMemFree();
534
+ // uint64_t mem_available_after = getMemAvailable();
535
+ // std::cout << "Mem Free diff: " << (mem_free_before - mem_free_after) << "\n";
536
+ // std::cout << "Mem Aavilable diff: " << (mem_available_before - mem_available_after) << "\n";
642
537
643
538
uint64_t io_before = getIOCount ();
644
- mem_free_before = getMemFree ();
645
- mem_available_before = getMemAvailable ();
539
+ // mem_free_before = getMemFree();
540
+ // mem_available_before = getMemAvailable();
646
541
647
- if (query_type == 0 )
542
+ if (query_type == 1 )
648
543
benchPointQuery (db, &options, kKeyRange , kQueryCount );
649
- else if (query_type == 1 )
650
- benchOpenRangeQuery (db, &options, kKeyRange , kQueryCount , scan_length);
651
544
else if (query_type == 2 )
545
+ benchOpenRangeQuery (db, &options, kKeyRange , kQueryCount , scan_length);
546
+ else if (query_type == 3 )
652
547
benchClosedRangeQuery (db, &options, kKeyRange , kQueryCount , range_size);
653
548
654
549
uint64_t io_after = getIOCount ();
655
- mem_free_after = getMemFree ();
656
- mem_available_after = getMemAvailable ();
550
+ // mem_free_after = getMemFree();
551
+ // mem_available_after = getMemAvailable();
657
552
// std::cout << options.statistics->ToString() << "\n";
658
553
// std::string stats;
659
554
// db->GetProperty(rocksdb::Slice("rocksdb.stats"), &stats);
660
555
// std::cout << stats << "\n";
661
556
// printIO();
662
557
663
558
std::cout << " I/O count: " << (io_after - io_before) << " \n " ;
664
- std::cout << " Mem Free diff: " << (mem_free_before - mem_free_after) << " \n " ;
665
- std::cout << " Mem Aavilable diff: " << (mem_available_before - mem_available_after) << " \n " ;
559
+ // std::cout << "Mem Free diff: " << (mem_free_before - mem_free_after) << "\n";
560
+ // std::cout << "Mem Aavilable diff: " << (mem_available_before - mem_available_after) << "\n";
666
561
667
562
close (db);
668
563
0 commit comments