From d116b94389538aa8e0e7354fae77693b980de4f0 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Mon, 24 Feb 2025 11:14:52 -0500 Subject: Query Preemption: still has one or two bugs, but mostly works --- benchmarks/tail-latency/insert_query_threads.cpp | 185 +++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 benchmarks/tail-latency/insert_query_threads.cpp (limited to 'benchmarks/tail-latency/insert_query_threads.cpp') diff --git a/benchmarks/tail-latency/insert_query_threads.cpp b/benchmarks/tail-latency/insert_query_threads.cpp new file mode 100644 index 0000000..1f35f3d --- /dev/null +++ b/benchmarks/tail-latency/insert_query_threads.cpp @@ -0,0 +1,185 @@ +/* + * + */ + +#define ENABLE_TIMER +#define TS_TEST + +#include + +#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 + +#include "psu-util/timer.h" + +typedef de::Record Rec; +typedef de::TrieSpline Shard; +typedef de::rc::Query Q; +typedef de::DynamicExtension + Ext; +typedef Q::Parameters QP; +typedef de::DEConfiguration + Conf; + +std::atomic idx; +std::atomic inserts_done = false; + +ssize_t query_ratio = 8; + +std::atomic total_res = 0; +size_t reccnt = 0; + +size_t g_thrd_cnt = 0; + +std::atomic total_insert_time = 0; +std::atomic total_insert_count = 0; +std::atomic total_query_time = 0; +std::atomic total_query_count = 0; + +void query_thread(Ext *extension, std::vector *queries) { + TIMER_INIT(); + while (!inserts_done.load()) { + total_query_count.fetch_add(1); + auto q_idx = rand() % queries->size(); + + auto q = (*queries)[q_idx]; + + TIMER_START(); + auto res = extension->query(std::move(q)).get(); + TIMER_STOP(); + + total_query_time.fetch_add(TIMER_RESULT()); + total_res.fetch_add(res); + } +} + +void insert_thread(Ext *extension, std::vector *records, size_t start_idx, size_t stop_idx) { + TIMER_INIT(); + + TIMER_START(); + + for (size_t i=start_idx; iinsert((*records)[i])) { + usleep(1); + } + } + + TIMER_STOP(); + total_insert_time.fetch_add(TIMER_RESULT()); +} + +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(d_fname, n); + auto queries = read_range_queries(q_fname, .0001); + + std::vector sfs = {8}; //, 4, 8, 16, 32, 64, 128, 256, 512, 1024}; + size_t buffer_size = 8000; + std::vector policies = { + 5 + }; + + std::vector thread_counts = {8, 16, 32}; + + size_t insert_threads = 1; + size_t query_threads = 6; + + reccnt = n; + + for (auto pol : policies) { + for (auto internal_thread_cnt : thread_counts) { + auto policy = get_policy(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; + + total_insert_time.store(0); + total_query_time.store(0); + total_query_count.store(0); + + 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); + + std::thread i_thrds[insert_threads]; + std::thread q_thrds[query_threads]; + + size_t per_insert_thrd = (n - warmup) / insert_threads; + size_t start = warmup; + + for (size_t i=0; i