2 * Benchmarking suite for key-value store
6 * eleanor.cawthon@inktank.com
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
14 #ifndef KVSTOREBENCH_H_
15 #define KVSTOREBENCH_H_
17 #include "key_value_store/key_value_structure.h"
18 #include "key_value_store/kv_flat_btree_async.h"
19 #include "common/Clock.h"
20 #include "global/global_context.h"
21 #include "common/Mutex.h"
22 #include "common/Cond.h"
30 using ceph::bufferlist;
33 * stores pairings from op type to time taken for that op (for latency), and to
34 * time that op completed to the nearest second (for throughput).
36 struct kv_bench_data {
37 JSONFormatter throughput_jf;
39 JSONFormatter latency_jf;
45 * keeps track of the number of milliseconds between two events - used to
53 begin_time = ceph_clock_now();
56 end_time = ceph_clock_now();
59 return (end_time - begin_time) * 1000;
62 begin_time = end_time = utime_t();
67 * arguments passed to the callback method when the op is being timed
83 timed_args (KvStoreBench * k)
90 typedef pair<string, bufferlist> (KvStoreBench::*next_gen_t)(bool new_elem);
96 //test setup variables set from command line
97 int entries; //the number of entries to write initially
98 int ops; //the number of operations to time
99 int clients; //the total number of clients running this test - used
100 //in the aio test to coordinate the end of the initial sets
101 int key_size;//number of characters in keys to write
102 int val_size;//number of characters in values to write
103 int max_ops_in_flight;
104 bool clear_first;//if true, remove all objects in pool before starting tests
106 //variables passed to KeyValueStructure
108 int cache_size; //number of index entries to store in cache
109 double cache_refresh; //cache_size / cache_refresh entries are read each time
112 bool verbose;//if true, display debug output
115 map<int, char> probs;//map of numbers from 1 to 100 to chars representing
116 //operation types - used to generate random operations
117 set<string> key_set;//set of keys already in the data set
118 KeyValueStructure * kvs;
119 kv_bench_data data;//stores throughput and latency from completed tests
121 Cond op_avail;//signaled when an op completes
122 int ops_in_flight;//number of operations currently in progress
123 Mutex ops_in_flight_lock;
124 //these are used for cleanup and setup purposes - they are NOT passed to kvs!
125 librados::Rados rados;
129 librados::IoCtx io_ctx;
132 * Prints JSON-formatted throughput and latency data.
134 * Throughput data is {'char representing the operation type':time the op
135 * completed to the nearest second}
136 * Latency is {'char representing the operation type':time taken by the op}
138 void print_time_data();
144 //after this is called, objects created by the KeyValueStructure remain.
148 * parses command line arguments, sets up this rados instance, clears the
149 * pool if clear_first is true and calls kvs->setup.
151 int setup(int argc, const char** argv);
154 * Returns a string of random characters of length len
156 string random_string(int len);
159 * Inserts entries random keys and values asynchronously.
161 int test_random_insertions();
164 * calls test_random_insertions, then does ops randomly chosen operations
165 * asynchronously, with max_ops_in_flight operations at a time.
167 int test_teuthology_aio(next_gen_t distr, const map<int, char> &probs);
170 * calls test_random_insertions, then does ops randomly chosen operations
173 int test_teuthology_sync(next_gen_t distr, const map<int, char> &probs);
176 * returns a key-value pair. If new_elem is true, the key is randomly
177 * generated. If it is false, the key is selected from the keys currently in
180 pair<string, bufferlist> rand_distr(bool new_elem);
183 * Called when aio operations complete. Updates data.
185 static void aio_callback_timed(int * err, void *arg);
188 * Calls test_ methods. Change to call, for example, multiple runs of a test
189 * with different settings. Currently just calls test_teuthology_aio.
191 int teuthology_tests();
195 #endif /* KVSTOREBENCH_H_ */