summaryrefslogtreecommitdiffstats
path: root/benchmarks/tail-latency/mixed_workload.cpp
blob: f4bfdda1961be2d116951fea9bd4e3ffa6f5a8e5 (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
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
/*
 *
 */

#define ENABLE_TIMER
#define TS_TEST

#include <thread>

#include "framework/scheduling/SerialScheduler.h"
#include "framework/util/Configuration.h"
#include "util/types.h"
#include "file_util.h"
#include "framework/DynamicExtension.h"
#include "framework/interface/Record.h"
#include "framework/scheduling/FIFOScheduler.h"
#include "query/rangecount.h"
#include "shard/TrieSpline.h"
#include "standard_benchmarks.h"

#include "framework/reconstruction/FixedShardCountPolicy.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> Q;
typedef de::DynamicExtension<Shard, Q, de::DeletePolicy::TOMBSTONE,
                             de::FIFOScheduler>
    Ext;
typedef Q::Parameters QP;
typedef de::DEConfiguration<Shard, Q, de::DeletePolicy::TOMBSTONE,
                            de::FIFOScheduler>
    Conf;

std::atomic<size_t> idx;
std::atomic<bool> inserts_done = false;

size_t query_ratio = 3;

std::atomic<size_t> total_res = 0;
size_t reccnt = 0;

size_t g_thrd_cnt = 0;

void operation_thread(Ext *extension, std::vector<QP> *queries,
                      std::vector<Rec> *records) {
  TIMER_INIT();
  while (!inserts_done.load()) {
    auto type = rand() % 10;

    if (type < 8) {
      auto q_idx = rand() % queries->size();

      auto q = (*queries)[q_idx];

      TIMER_START();
      auto res = extension->query(std::move(q)).get();
      TIMER_STOP();

      fprintf(stdout, "Q\t%ld\t%ld\n", g_thrd_cnt, TIMER_RESULT());

      total_res.fetch_add(res);

    } else {
      for (size_t i = 0; i < 1000; i++) {
        auto insert_idx = idx.fetch_add(1);
        if (insert_idx >= reccnt) {
          inserts_done.store(true);
          break;
        }

        TIMER_START();
        while (!extension->insert((*records)[insert_idx])) {
          usleep(1);
        }
        TIMER_STOP();

        fprintf(stdout, "I\t%ld\t%ld\n", g_thrd_cnt, TIMER_RESULT());

        if (idx.load() == reccnt) {
          inserts_done.store(true);
        }
      }
    }
  }
}

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]);

  auto data = read_sosd_file<Rec>(d_fname, n);
  auto queries = read_range_queries<QP>(q_fname, .0001);

  std::vector<size_t> sfs = {8}; //, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
  size_t buffer_size = 8000;
  std::vector<size_t> policies = {
      5
  };

  std::vector<size_t> thread_counts = {1, 2, 4, 8, 16, 32};

  reccnt = n;

  for (auto pol : policies) {
    for (auto internal_thread_cnt : thread_counts) {
      auto policy = get_policy<Shard, Q>(sfs[0], buffer_size, pol, n);
      auto config = Conf(std::move(policy));
      config.recon_enable_maint_on_flush = true;
      config.recon_maint_disabled = false;
      config.buffer_flush_trigger = 4000;
      config.maximum_threads = internal_thread_cnt;

      g_thrd_cnt = internal_thread_cnt;

      auto extension = new Ext(std::move(config));

      /* warmup structure w/ 10% of records */
      size_t warmup = .1 * n;
      for (size_t k = 0; k < warmup; k++) {
        while (!extension->insert(data[k])) {
          usleep(1);
        }
      }

      extension->await_version();

      idx.store(warmup);

      size_t thrd_cnt = 8;
      std::thread thrds[thrd_cnt];

      for (size_t i=0; i<thrd_cnt; i++) {
        thrds[i] = std::thread(operation_thread, extension, &queries, &data);
      }

      for (size_t i=0; i<thrd_cnt; i++) {
        thrds[i].join();
      }

      fprintf(stderr, "%ld\n", total_res.load());
      total_res.store(0);
      inserts_done.store(false);
      delete extension;
    }
  }

  fflush(stderr);
}