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

#include <cstdlib>
#define ENABLE_TIMER
#define TS_TEST

#include <thread>

#include "file_util.h"
#include "framework/DynamicExtension.h"
#include "framework/interface/Record.h"
#include "framework/scheduling/FIFOScheduler.h"
#include "framework/scheduling/SerialScheduler.h"
#include "framework/util/Configuration.h"
#include "query/pointlookup.h"
#include "shard/ISAMTree.h"
#include "standard_benchmarks.h"
#include "util/types.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::ISAMTree<Rec> Shard;
typedef de::pl::Query<Shard> Q;
typedef de::DynamicExtension<Shard, Q, de::DeletePolicy::TOMBSTONE,
                             de::SerialScheduler>
    Ext;
typedef Q::Parameters QP;
typedef de::DEConfiguration<Shard, Q, de::DeletePolicy::TOMBSTONE,
                            de::SerialScheduler>
    Conf;

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

ssize_t query_ratio = 0;

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

size_t g_thrd_cnt = 0;

std::atomic<size_t> total_insert_time = 0;
std::atomic<size_t> total_insert_count = 0;
std::atomic<size_t> total_query_time = 0;
std::atomic<size_t> total_query_count = 0;

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);
  auto queries =read_sosd_point_lookups<QP>(q_fname, 100);

  size_t buffer_size = 8000;

  auto policy = get_policy<Shard, Q>(4, buffer_size);
  auto config = Conf(std::move(policy));
  auto extension = new Ext(std::move(config));

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

  extension->print_structure();

  TIMER_INIT();
  
  TIMER_START();
  for (size_t i=0; i<10000; i++) {
      auto q_idx = rand() % queries.size();
      auto q = queries[q_idx];
      auto res = extension->query(std::move(q)).get();
      total_res.fetch_add(res.size());
  }
  TIMER_STOP();
  
  fprintf(stdout, "End-to-end Query Latency:\t%ld\n", TIMER_RESULT() / 10000);

  /* run query */

  delete extension;

  policy = get_policy<Shard, Q>(4, buffer_size, 1);
  config = Conf(std::move(policy));
  extension = new Ext(std::move(config));

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

  extension->print_structure();

  TIMER_START();
  for (size_t i=0; i<10000; i++) {
    auto q_idx = rand() % queries.size();
    auto q = queries[q_idx];
    auto res = extension->query(std::move(q)).get();
    total_res.fetch_add(res.size());
  }
  TIMER_STOP();
  
  fprintf(stdout, "End-to-end Query Latency:\t%ld\n", TIMER_RESULT() / 10000);

  delete extension;

  fprintf(stderr, "%ld\n", total_res.load());

  fflush(stderr);
}