]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/kv_store_bench.h
buildsys: switch source download to quincy
[ceph.git] / ceph / src / test / kv_store_bench.h
CommitLineData
7c673cae
FG
1/*
2 * Benchmarking suite for key-value store
3 *
4 * September 2, 2012
5 * Eleanor Cawthon
6 * eleanor.cawthon@inktank.com
7 *
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.
12 */
13
14#ifndef KVSTOREBENCH_H_
15#define KVSTOREBENCH_H_
16
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"
7c673cae
FG
21#include "common/Cond.h"
22
23#include <string>
24#include <climits>
25#include <cfloat>
26#include <iostream>
27
28using namespace std;
29using ceph::bufferlist;
30
31/**
32 * stores pairings from op type to time taken for that op (for latency), and to
33 * time that op completed to the nearest second (for throughput).
34 */
35struct kv_bench_data {
36 JSONFormatter throughput_jf;
37
38 JSONFormatter latency_jf;
39};
40
41class KvStoreBench;
42
43/**
44 * keeps track of the number of milliseconds between two events - used to
45 * measure latency
46 */
47struct StopWatch {
48 utime_t begin_time;
49 utime_t end_time;
50
51 void start_time() {
52 begin_time = ceph_clock_now();
53 }
54 void stop_time() {
55 end_time = ceph_clock_now();
56 }
57 double get_time() {
58 return (end_time - begin_time) * 1000;
59 }
60 void clear() {
61 begin_time = end_time = utime_t();
62 }
63};
64
65/**
66 * arguments passed to the callback method when the op is being timed
67 */
68struct timed_args {
69 StopWatch sw;
70 //kv_bench_data data;
71 KvStoreBench * kvsb;
72 bufferlist val;
73 int err;
74 char op;
75
76 timed_args ()
77 : kvsb(NULL),
78 err(0),
79 op(' ')
80 {};
81
82 timed_args (KvStoreBench * k)
83 : kvsb(k),
84 err(0),
85 op(' ')
86 {}
87};
88
89typedef pair<string, bufferlist> (KvStoreBench::*next_gen_t)(bool new_elem);
90
91class KvStoreBench {
92
93protected:
94
95 //test setup variables set from command line
96 int entries; //the number of entries to write initially
97 int ops; //the number of operations to time
98 int clients; //the total number of clients running this test - used
99 //in the aio test to coordinate the end of the initial sets
100 int key_size;//number of characters in keys to write
101 int val_size;//number of characters in values to write
102 int max_ops_in_flight;
103 bool clear_first;//if true, remove all objects in pool before starting tests
104
105 //variables passed to KeyValueStructure
106 int k;
107 int cache_size; //number of index entries to store in cache
108 double cache_refresh; //cache_size / cache_refresh entries are read each time
109 //the index is read
110 string client_name;
111 bool verbose;//if true, display debug output
112
113 //internal
114 map<int, char> probs;//map of numbers from 1 to 100 to chars representing
115 //operation types - used to generate random operations
116 set<string> key_set;//set of keys already in the data set
117 KeyValueStructure * kvs;
118 kv_bench_data data;//stores throughput and latency from completed tests
9f95a23c
TL
119 ceph::mutex data_lock = ceph::make_mutex("data lock");
120 ceph::condition_variable op_avail; // signaled when an op completes
7c673cae 121 int ops_in_flight;//number of operations currently in progress
9f95a23c
TL
122 ceph::mutex ops_in_flight_lock =
123 ceph::make_mutex("KvStoreBench::ops_in_flight_lock");
7c673cae
FG
124 //these are used for cleanup and setup purposes - they are NOT passed to kvs!
125 librados::Rados rados;
126 string rados_id;
127 string pool_name;
128 bool io_ctx_ready;
129 librados::IoCtx io_ctx;
130
131 /**
132 * Prints JSON-formatted throughput and latency data.
133 *
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}
137 */
138 void print_time_data();
139
140public:
141
142 KvStoreBench();
143
144 //after this is called, objects created by the KeyValueStructure remain.
145 ~KvStoreBench();
146
147 /**
148 * parses command line arguments, sets up this rados instance, clears the
149 * pool if clear_first is true and calls kvs->setup.
150 */
151 int setup(int argc, const char** argv);
152
153 /**
154 * Returns a string of random characters of length len
155 */
156 string random_string(int len);
157
158 /**
159 * Inserts entries random keys and values asynchronously.
160 */
161 int test_random_insertions();
162
163 /**
164 * calls test_random_insertions, then does ops randomly chosen operations
165 * asynchronously, with max_ops_in_flight operations at a time.
166 */
167 int test_teuthology_aio(next_gen_t distr, const map<int, char> &probs);
168
169 /**
170 * calls test_random_insertions, then does ops randomly chosen operations
171 * synchronously.
172 */
173 int test_teuthology_sync(next_gen_t distr, const map<int, char> &probs);
174
175 /**
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
178 * the key set.
179 */
180 pair<string, bufferlist> rand_distr(bool new_elem);
181
182 /**
183 * Called when aio operations complete. Updates data.
184 */
185 static void aio_callback_timed(int * err, void *arg);
186
187 /**
188 * Calls test_ methods. Change to call, for example, multiple runs of a test
189 * with different settings. Currently just calls test_teuthology_aio.
190 */
191 int teuthology_tests();
192
193};
194
195#endif /* KVSTOREBENCH_H_ */