]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/omap_bench.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / test / omap_bench.h
1 /*
2 * Generate latency statistics for a configurable number of object map write
3 * operations of configurable size.
4 *
5 * Created on: May 21, 2012
6 * Author: Eleanor Cawthon
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 OMAP_BENCH_HPP_
15 #define OMAP_BENCH_HPP_
16
17 #include "common/ceph_mutex.h"
18 #include "common/Cond.h"
19 #include "include/rados/librados.hpp"
20 #include <string>
21 #include <map>
22 #include <cfloat>
23
24 using ceph::bufferlist;
25
26 struct o_bench_data {
27 double avg_latency;
28 double min_latency;
29 double max_latency;
30 double total_latency;
31 int started_ops;
32 int completed_ops;
33 std::map<int,int> freq_map;
34 pair<int,int> mode;
35 o_bench_data()
36 : avg_latency(0.0), min_latency(DBL_MAX), max_latency(0.0),
37 total_latency(0.0),
38 started_ops(0), completed_ops(0)
39 {}
40 };
41
42 class OmapBench;
43
44 typedef int (*omap_generator_t)(const int omap_entries, const int key_size,
45 const int value_size,
46 std::map<std::string,bufferlist> *out_omap);
47 typedef int (OmapBench::*test_t)(omap_generator_t omap_gen);
48
49
50 class Writer{
51 protected:
52 string oid;
53 utime_t begin_time;
54 utime_t end_time;
55 std::map<std::string,bufferlist> omap;
56 OmapBench *ob;
57 friend class OmapBench;
58 public:
59 Writer(OmapBench *omap_bench);
60 virtual ~Writer(){};
61 virtual void start_time();
62 virtual void stop_time();
63 virtual double get_time();
64 virtual string get_oid();
65 virtual std::map<std::string,bufferlist> & get_omap();
66 };
67
68 class AioWriter : public Writer{
69 protected:
70 librados::AioCompletion * aioc;
71 friend class OmapBench;
72
73 public:
74 AioWriter(OmapBench *omap_bench);
75 ~AioWriter() override;
76 virtual librados::AioCompletion * get_aioc();
77 virtual void set_aioc(librados::callback_t complete);
78 };
79
80 class OmapBench{
81 protected:
82 librados::IoCtx io_ctx;
83 librados::Rados rados;
84 struct o_bench_data data;
85 test_t test;
86 omap_generator_t omap_generator;
87
88 //aio things
89 ceph::condition_variable thread_is_free;
90 ceph::mutex thread_is_free_lock =
91 ceph::make_mutex("OmapBench::thread_is_free_lock");
92 ceph::mutex data_lock =
93 ceph::make_mutex("OmapBench::data_lock");
94 int busythreads_count;
95 librados::callback_t comp;
96
97 string pool_name;
98 string rados_id;
99 string prefix;
100 int threads;
101 int objects;
102 int entries_per_omap;
103 int key_size;
104 int value_size;
105 double increment;
106
107 friend class Writer;
108 friend class AioWriter;
109
110 public:
111 OmapBench()
112 : test(&OmapBench::test_write_objects_in_parallel),
113 omap_generator(generate_uniform_omap),
114 busythreads_count(0),
115 comp(aio_is_complete),
116 pool_name("rbd"),
117 rados_id("admin"),
118 prefix(rados_id+".obj."),
119 threads(3), objects(100), entries_per_omap(10), key_size(10),
120 value_size(100), increment(10)
121 {}
122 /**
123 * Parses command line args, initializes rados and ioctx
124 */
125 int setup(int argc, const char** argv);
126
127 /**
128 * Callback for when an AioCompletion (called from an AioWriter)
129 * is complete. deletes the AioWriter that called it,
130 * Updates data, updates busythreads, and signals thread_is_free.
131 *
132 * @param c provided by aio_write - not used
133 * @param arg the AioWriter that contains this AioCompletion
134 */
135 static void aio_is_complete(rados_completion_t c, void *arg);
136
137 /**
138 * Generates a random string len characters long
139 */
140 static string random_string(int len);
141
142 /*
143 * runs the test specified by test using the omap generator specified by
144 * omap_generator
145 *
146 * @return error code
147 */
148 int run();
149
150 /*
151 * Prints all keys and values for all omap entries for all objects
152 */
153 int print_written_omap();
154
155 /*
156 * Displays relevant constants and the histogram generated through a test
157 */
158 void print_results();
159
160 /**
161 * Writes an object with the specified AioWriter.
162 *
163 * @param aiow the AioWriter to write with
164 * @param omap the omap to write
165 * @post: an asynchronous omap_set is launched
166 */
167 int write_omap_asynchronously(AioWriter *aiow,
168 const std::map<std::string,bufferlist> &map);
169
170
171 /**
172 * Generates an omap with omap_entries entries, each with keys key_size
173 * characters long and with string values value_size characters long.
174 *
175 * @param out_map pointer to the map to be created
176 * @return error code
177 */
178 static int generate_uniform_omap(const int omap_entries, const int key_size,
179 const int value_size, std::map<std::string,bufferlist> * out_omap);
180
181 /**
182 * The same as generate_uniform_omap except that string lengths are picked
183 * randomly between 1 and the int arguments
184 */
185 static int generate_non_uniform_omap(const int omap_entries,
186 const int key_size,
187 const int value_size, std::map<std::string,bufferlist> * out_omap);
188
189 static int generate_small_non_random_omap(const int omap_entries,
190 const int key_size, const int value_size,
191 std::map<std::string,bufferlist> * out_omap);
192
193 /*
194 * Uses aio_write to write omaps generated by omap_gen to OBJECTS objects
195 * using THREADS AioWriters at a time.
196 *
197 * @param omap_gen the method used to generate the omaps.
198 */
199 int test_write_objects_in_parallel(omap_generator_t omap_gen);
200
201 };
202
203
204
205 #endif /* OMAP_BENCH_HPP_ */
206