1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
7 #include "distribution.h"
8 #include "stat_collector.h"
10 #include <boost/scoped_ptr.hpp>
11 #include "common/Mutex.h"
12 #include "common/Cond.h"
13 #include "common/Thread.h"
15 struct OnWriteApplied;
17 struct OnReadComplete;
20 class Bencher : public Thread {
29 Distribution<boost::tuple<std::string,uint64_t,uint64_t, OpType> > > op_dist;
30 ceph::shared_ptr<StatCollector> stat_collector;
31 boost::scoped_ptr<Backend> backend;
32 const uint64_t max_in_flight;
33 const uint64_t max_duration;
34 const uint64_t max_ops;
44 Distribution<boost::tuple<std::string, uint64_t, uint64_t, OpType> > *op_gen,
45 ceph::shared_ptr<StatCollector> stat_collector,
47 uint64_t max_in_flight,
48 uint64_t max_duration,
51 stat_collector(stat_collector),
53 max_in_flight(max_in_flight),
54 max_duration(max_duration),
56 lock("Bencher::lock"),
60 Distribution<boost::tuple<std::string, uint64_t, uint64_t, OpType> > *op_gen,
61 StatCollector *stat_collector,
63 uint64_t max_in_flight,
64 uint64_t max_duration,
67 stat_collector(stat_collector),
69 max_in_flight(max_in_flight),
70 max_duration(max_duration),
72 lock("Bencher::lock"),
76 Distribution<std::string> *object_gen,
77 Distribution<uint64_t> *offset_gen,
78 Distribution<uint64_t> *length_gen,
79 Distribution<OpType> *op_type_gen,
80 StatCollector *stat_collector,
82 uint64_t max_in_flight,
83 uint64_t max_duration,
86 new FourTupleDist<std::string, uint64_t, uint64_t, OpType>(
87 object_gen, offset_gen, length_gen, op_type_gen)),
88 stat_collector(stat_collector),
90 max_in_flight(max_in_flight),
91 max_duration(max_duration),
93 lock("Bencher::lock"),
98 const set<std::string> &objects,
104 void *entry() override {
108 friend struct OnWriteApplied;
109 friend struct OnWriteCommit;
110 friend struct OnReadComplete;
111 friend struct Cleanup;
114 class SequentialLoad :
116 boost::tuple<string, uint64_t, uint64_t, Bencher::OpType> > {
120 set<string>::iterator object_pos;
122 boost::scoped_ptr<Distribution<Bencher::OpType> > op_dist;
123 SequentialLoad(const SequentialLoad &other);
126 const set<string> &_objects, uint64_t size,
128 Distribution<Bencher::OpType> *op_dist)
129 : objects(_objects), size(size), length(length),
130 object_pos(objects.begin()), cur_pos(0),
133 boost::tuple<string, uint64_t, uint64_t, Bencher::OpType>
134 operator()() override {
135 boost::tuple<string, uint64_t, uint64_t, Bencher::OpType> ret =
136 boost::make_tuple(*object_pos, cur_pos, length, (*op_dist)());
138 if (cur_pos >= size) {
142 if (object_pos == objects.end())
143 object_pos = objects.begin();