2 * Generate latency statistics for a configurable number of object map write
3 * operations of configurable size.
5 * Created on: May 21, 2012
6 * Author: Eleanor Cawthon
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 OMAP_BENCH_HPP_
15 #define OMAP_BENCH_HPP_
17 #include "common/ceph_mutex.h"
18 #include "common/Cond.h"
19 #include "include/rados/librados.hpp"
24 using ceph::bufferlist
;
33 std::map
<int,int> freq_map
;
36 : avg_latency(0.0), min_latency(DBL_MAX
), max_latency(0.0),
38 started_ops(0), completed_ops(0)
44 typedef int (*omap_generator_t
)(const int omap_entries
, const int key_size
,
46 std::map
<std::string
,bufferlist
> *out_omap
);
47 typedef int (OmapBench::*test_t
)(omap_generator_t omap_gen
);
55 std::map
<std::string
,bufferlist
> omap
;
57 friend class OmapBench
;
59 Writer(OmapBench
*omap_bench
);
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();
68 class AioWriter
: public Writer
{
70 librados::AioCompletion
* aioc
;
71 friend class OmapBench
;
74 AioWriter(OmapBench
*omap_bench
);
75 ~AioWriter() override
;
76 virtual librados::AioCompletion
* get_aioc();
77 virtual void set_aioc(librados::callback_t complete
);
82 librados::IoCtx io_ctx
;
83 librados::Rados rados
;
84 struct o_bench_data data
;
86 omap_generator_t omap_generator
;
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
;
102 int entries_per_omap
;
108 friend class AioWriter
;
112 : test(&OmapBench::test_write_objects_in_parallel
),
113 omap_generator(generate_uniform_omap
),
114 busythreads_count(0),
115 comp(aio_is_complete
),
118 prefix(rados_id
+".obj."),
119 threads(3), objects(100), entries_per_omap(10), key_size(10),
120 value_size(100), increment(10)
123 * Parses command line args, initializes rados and ioctx
125 int setup(int argc
, const char** argv
);
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.
132 * @param c provided by aio_write - not used
133 * @param arg the AioWriter that contains this AioCompletion
135 static void aio_is_complete(rados_completion_t c
, void *arg
);
138 * Generates a random string len characters long
140 static string
random_string(int len
);
143 * runs the test specified by test using the omap generator specified by
151 * Prints all keys and values for all omap entries for all objects
153 int print_written_omap();
156 * Displays relevant constants and the histogram generated through a test
158 void print_results();
161 * Writes an object with the specified AioWriter.
163 * @param aiow the AioWriter to write with
164 * @param omap the omap to write
165 * @post: an asynchronous omap_set is launched
167 int write_omap_asynchronously(AioWriter
*aiow
,
168 const std::map
<std::string
,bufferlist
> &map
);
172 * Generates an omap with omap_entries entries, each with keys key_size
173 * characters long and with string values value_size characters long.
175 * @param out_map pointer to the map to be created
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
);
182 * The same as generate_uniform_omap except that string lengths are picked
183 * randomly between 1 and the int arguments
185 static int generate_non_uniform_omap(const int omap_entries
,
187 const int value_size
, std::map
<std::string
,bufferlist
> * out_omap
);
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
);
194 * Uses aio_write to write omaps generated by omap_gen to OBJECTS objects
195 * using THREADS AioWriters at a time.
197 * @param omap_gen the method used to generate the omaps.
199 int test_write_objects_in_parallel(omap_generator_t omap_gen
);
205 #endif /* OMAP_BENCH_HPP_ */