summaryrefslogtreecommitdiffstats
path: root/benchmarks/vldb/ts_parmsweep.cpp
blob: a9203abf0e6657bbcdfc5810ffc68a4d631fbd8f (plain)
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
/*
 *
 */

#define ENABLE_TIMER

#include "framework/DynamicExtension.h"
#include "shard/TrieSpline.h"
#include "query/rangecount.h"
#include "framework/interface/Record.h"
#include "file_util.h"
#include "standard_benchmarks.h"

#include <gsl/gsl_rng.h>

#include "psu-util/timer.h"


typedef de::Record<uint64_t, uint64_t> Rec;
typedef de::TrieSpline<Rec> Shard;
typedef de::rc::Query<Shard, true> Q;
typedef de::DynamicExtension<Shard, Q, de::LayoutPolicy::TEIRING, de::DeletePolicy::TOMBSTONE, de::SerialScheduler> Ext;
typedef de::DynamicExtension<Shard, Q, de::LayoutPolicy::LEVELING, de::DeletePolicy::TOMBSTONE, de::SerialScheduler> Ext2;
typedef Q::Parameters QP;

void usage(char *progname) {
    fprintf(stderr, "%s reccnt datafile queryfile\n", progname);
}

int main(int argc, char **argv) {

    if (argc < 4) {
        usage(argv[0]);
        exit(EXIT_FAILURE);
    }

    size_t n = atol(argv[1]);
    std::string d_fname = std::string(argv[2]);
    std::string q_fname = std::string(argv[3]);

    gsl_rng * rng = gsl_rng_alloc(gsl_rng_mt19937);
    
    auto data = read_sosd_file<Rec>(d_fname, n);
    std::vector<size_t> to_delete(n * delete_proportion);
    size_t j=0;
    for (size_t i=0; i<data.size() && j<to_delete.size(); i++) {
        if (gsl_rng_uniform(rng) <= delete_proportion) {
            to_delete[j++] = i;
        } 
    }
    auto queries = read_range_queries<QP>(q_fname, .001);

    const std::vector<de::LayoutPolicy> policies = {de::LayoutPolicy::LEVELING, de::LayoutPolicy::TEIRING};
    const std::vector<size_t> buffer_sizes = {1000, 4000, 8000, 12000, 15000, 20000};
    const std::vector<size_t> scale_factors = {2, 4, 6, 8, 10, 12};

    for (const auto &bs : buffer_sizes) {
        for (const auto &sf : scale_factors) {
            auto extension = new Ext(bs, bs, sf, 0, 64);
            /* warmup structure w/ 10% of records */
            size_t warmup = .1 * n;
            size_t delete_idx = 0;
            insert_records<Ext, Rec>(extension, 0, warmup, data, to_delete, delete_idx, false, rng);

            extension->await_next_epoch();

            TIMER_INIT();

            TIMER_START();
            insert_records<Ext, Rec>(extension, warmup, data.size(), data, to_delete, delete_idx, true, rng);
            TIMER_STOP();

            auto insert_latency = TIMER_RESULT();
            size_t insert_throughput = (size_t) ((double) (n - warmup) / (double) insert_latency * 1e9);

            TIMER_START();
            run_queries<Ext, Q>(extension, queries);
            TIMER_STOP();

            auto query_latency = TIMER_RESULT() / queries.size();

            auto ext_size = extension->get_memory_usage() + extension->get_aux_memory_usage();

            fprintf(stdout, "TIERING\t%ld\t%ld\t%ld\t%ld\t%ld\n", bs, sf, insert_throughput, query_latency, ext_size);
            delete extension;
        }
    }

    for (const auto &bs : buffer_sizes) {
        for (const auto &sf : scale_factors) {
            auto extension = new Ext2(bs, bs, sf, 0, 64);
            /* warmup structure w/ 10% of records */
            size_t warmup = .1 * n;
            size_t delete_idx = 0;
            insert_records<Ext2, Rec>(extension, 0, warmup, data, to_delete, delete_idx, false, rng);

            extension->await_next_epoch();

            TIMER_INIT();

            TIMER_START();
            insert_records<Ext2, Rec>(extension, warmup, data.size(), data, to_delete, delete_idx, true, rng);
            TIMER_STOP();

            auto insert_latency = TIMER_RESULT();
            size_t insert_throughput = (size_t) ((double) (n - warmup) / (double) insert_latency * 1e9);

            TIMER_START();
            run_queries<Ext2, Q>(extension, queries);
            TIMER_STOP();

            auto query_latency = TIMER_RESULT() / queries.size();

            auto ext_size = extension->get_memory_usage() + extension->get_aux_memory_usage();

            fprintf(stdout, "LEVELING\t%ld\t%ld\t%ld\t%ld\t%ld\n", bs, sf, insert_throughput, query_latency, ext_size);
            delete extension;
        }
    }

    gsl_rng_free(rng);
    fflush(stderr);
}