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/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,
78 librados::callback_t safe);
83 librados::IoCtx io_ctx;
84 librados::Rados rados;
85 struct o_bench_data data;
87 omap_generator_t omap_generator;
91 Mutex thread_is_free_lock;
93 int busythreads_count;
94 librados::callback_t comp;
95 librados::callback_t safe;
102 int entries_per_omap;
108 friend class AioWriter;
112 : test(&OmapBench::test_write_objects_in_parallel),
113 omap_generator(generate_uniform_omap),
114 thread_is_free_lock("OmapBench::thread_is_free_lock"),
115 data_lock("OmapBench::data_lock"),
116 busythreads_count(0),
117 comp(NULL), safe(aio_is_safe),
120 prefix(rados_id+".obj."),
121 threads(3), objects(100), entries_per_omap(10), key_size(10),
122 value_size(100), increment(10)
125 * Parses command line args, initializes rados and ioctx
127 int setup(int argc, const char** argv);
130 * Callback for when an AioCompletion (called from an AioWriter)
131 * is safe. deletes the AioWriter that called it,
132 * Updates data, updates busythreads, and signals thread_is_free.
134 * @param c provided by aio_write - not used
135 * @param arg the AioWriter that contains this AioCompletion
137 static void aio_is_safe(rados_completion_t c, void *arg);
140 * Generates a random string len characters long
142 static string random_string(int len);
145 * runs the test specified by test using the omap generator specified by
153 * Prints all keys and values for all omap entries for all objects
155 int print_written_omap();
158 * Displays relevant constants and the histogram generated through a test
160 void print_results();
163 * Writes an object with the specified AioWriter.
165 * @param aiow the AioWriter to write with
166 * @param omap the omap to write
167 * @post: an asynchronous omap_set is launched
169 int write_omap_asynchronously(AioWriter *aiow,
170 const std::map<std::string,bufferlist> &map);
174 * Generates an omap with omap_entries entries, each with keys key_size
175 * characters long and with string values value_size characters long.
177 * @param out_map pointer to the map to be created
180 static int generate_uniform_omap(const int omap_entries, const int key_size,
181 const int value_size, std::map<std::string,bufferlist> * out_omap);
184 * The same as generate_uniform_omap except that string lengths are picked
185 * randomly between 1 and the int arguments
187 static int generate_non_uniform_omap(const int omap_entries,
189 const int value_size, std::map<std::string,bufferlist> * out_omap);
191 static int generate_small_non_random_omap(const int omap_entries,
192 const int key_size, const int value_size,
193 std::map<std::string,bufferlist> * out_omap);
196 * Uses aio_write to write omaps generated by omap_gen to OBJECTS objects
197 * using THREADS AioWriters at a time.
199 * @param omap_gen the method used to generate the omaps.
201 int test_write_objects_in_parallel(omap_generator_t omap_gen);
207 #endif /* OMAP_BENCH_HPP_ */