summaryrefslogtreecommitdiffstats
path: root/benchmarks/insert_query_tput.cpp
diff options
context:
space:
mode:
authorDouglas B. Rumbaugh <dbr4@psu.edu>2024-02-09 14:06:59 -0500
committerGitHub <noreply@github.com>2024-02-09 14:06:59 -0500
commitbc0f3cca3a5b495fcae1d3ad8d09e6d714da5d30 (patch)
tree66333c55feb0ea8875a50e6dc07c8535d241bf1c /benchmarks/insert_query_tput.cpp
parent076e104b8672924c3d80cd1da2fdb5ebee1766ac (diff)
parent46885246313358a3b606eca139b20280e96db10e (diff)
downloaddynamic-extension-bc0f3cca3a5b495fcae1d3ad8d09e6d714da5d30.tar.gz
Merge pull request #1 from dbrumbaugh/new-buffer
Initial Concurrency Implementation
Diffstat (limited to 'benchmarks/insert_query_tput.cpp')
-rw-r--r--benchmarks/insert_query_tput.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/benchmarks/insert_query_tput.cpp b/benchmarks/insert_query_tput.cpp
new file mode 100644
index 0000000..ce05264
--- /dev/null
+++ b/benchmarks/insert_query_tput.cpp
@@ -0,0 +1,121 @@
+/*
+ *
+ */
+
+#define ENABLE_TIMER
+
+#include <thread>
+
+#include "framework/DynamicExtension.h"
+#include "shard/ISAMTree.h"
+#include "query/irs.h"
+#include "framework/interface/Record.h"
+#include "include/data-proc.h"
+
+#include <gsl/gsl_rng.h>
+
+#include "psu-util/timer.h"
+
+
+typedef de::Record<int64_t, int64_t> Rec;
+typedef de::ISAMTree<Rec> ISAM;
+typedef de::irs::Query<Rec, ISAM> Q;
+typedef de::DynamicExtension<Rec, ISAM, Q> Ext;
+typedef de::irs::Parms<Rec> QP;
+
+std::atomic<bool> inserts_done = false;
+
+void query_thread(Ext *extension, std::vector<QP> *queries) {
+ gsl_rng *rng = gsl_rng_alloc(gsl_rng_mt19937);
+ size_t total = 0;
+
+ while (!inserts_done.load()) {
+ auto q_idx = gsl_rng_uniform_int(rng, queries->size());
+
+ auto q = (*queries)[q_idx];
+ q.rng = rng;
+ q.sample_size = 1000;
+
+ auto res = extension->query(&q);
+ auto r = res.get();
+ total += r.size();
+ usleep(1);
+ }
+
+ fprintf(stderr, "%ld\n", total);
+
+ gsl_rng_free(rng);
+}
+
+void insert_thread(Ext *extension, size_t start, std::vector<int64_t> *records) {
+ size_t reccnt = 0;
+ Rec r;
+ for (size_t i=start; i<records->size(); i++) {
+ r.key = (*records)[i];
+ r.value = i;
+
+ while (!extension->insert(r)) {
+ usleep(1);
+ }
+ }
+
+ inserts_done.store(true);
+}
+
+int main(int argc, char **argv) {
+
+ if (argc < 5) {
+ fprintf(stderr, "insert_query_tput reccnt query_threads datafile queryfile\n");
+ exit(EXIT_FAILURE);
+ }
+
+ size_t n = atol(argv[1]);
+ size_t qthread_cnt = atol(argv[2]);
+ std::string d_fname = std::string(argv[3]);
+ std::string q_fname = std::string(argv[4]);
+
+ auto extension = new Ext(1000, 12000, 8, 0, 64);
+ gsl_rng * rng = gsl_rng_alloc(gsl_rng_mt19937);
+
+ auto data = read_sosd_file(d_fname, n);
+ auto queries = read_range_queries<QP>(q_fname, .001);
+
+ /* warmup structure w/ 10% of records */
+ size_t warmup = .1 * n;
+ Rec r;
+ for (size_t i=0; i<warmup; i++) {
+ r.key = data[i];
+ r.value = gsl_rng_uniform_int(rng, n);
+
+ while (!extension->insert(r)) {
+ usleep(1);
+ }
+ }
+
+ extension->await_next_epoch();
+
+ TIMER_INIT();
+
+ std::vector<std::thread> qthreads(qthread_cnt);
+
+ TIMER_START();
+ std::thread i_thrd(insert_thread, extension, warmup, &data);
+ for (size_t i=0; i<qthread_cnt; i++) {
+ qthreads[i] = std::thread(query_thread, extension, &queries);
+ }
+ i_thrd.join();
+ TIMER_STOP();
+
+ for (size_t i=0; i<qthread_cnt; i++) {
+ qthreads[i].join();
+ }
+
+ auto total_latency = TIMER_RESULT();
+ size_t throughput = (size_t) ((double) (n - warmup) / (double) total_latency * 1e9);
+ fprintf(stdout, "T\t%ld\t%ld\n", total_latency, throughput);
+
+ gsl_rng_free(rng);
+ delete extension;
+ fflush(stderr);
+}
+