]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/obj_bencher.h
import ceph quincy 17.2.4
[ceph.git] / ceph / src / common / obj_bencher.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2009 Sage Weil <sage@newdream.net>
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
15 #ifndef CEPH_OBJ_BENCHER_H
16 #define CEPH_OBJ_BENCHER_H
17
18 #include "common/ceph_context.h"
19 #include "common/Formatter.h"
20 #include "ceph_time.h"
21 #include <cfloat>
22
23 using ceph::mono_clock;
24
25 struct bench_interval_data {
26 double min_bandwidth = DBL_MAX;
27 double max_bandwidth = 0;
28 double avg_bandwidth = 0;
29 int bandwidth_cycles = 0;
30 double bandwidth_diff_sum = 0;
31 int min_iops = INT_MAX;
32 int max_iops = 0;
33 double avg_iops = 0;
34 int iops_cycles = 0;
35 double iops_diff_sum = 0;
36 };
37
38 struct bench_data {
39 bool done; //is the benchmark is done
40 uint64_t object_size; //the size of the objects
41 uint64_t op_size; // the size of the read/write ops
42 bool hints;
43 // same as object_size for write tests
44 int in_flight; //number of reads/writes being waited on
45 int started;
46 int finished;
47 double min_latency;
48 double max_latency;
49 double avg_latency;
50 struct bench_interval_data idata; // data that is updated by time intervals and not by events
51 double latency_diff_sum;
52 std::chrono::duration<double> cur_latency; //latency of last completed transaction - in seconds by default
53 mono_time start_time; //start time for benchmark - use the monotonic clock as we'll measure the passage of time
54 char *object_contents; //pointer to the contents written to each object
55 };
56
57 const int OP_WRITE = 1;
58 const int OP_SEQ_READ = 2;
59 const int OP_RAND_READ = 3;
60
61 // Object is composed of <oid,namespace>
62 typedef std::pair<std::string, std::string> Object;
63
64 class ObjBencher {
65 bool show_time;
66 Formatter *formatter = NULL;
67 std::ostream *outstream = NULL;
68 public:
69 CephContext *cct;
70 protected:
71 ceph::mutex lock = ceph::make_mutex("ObjBencher::lock");
72
73 static void *status_printer(void *bencher);
74
75 struct bench_data data;
76
77 int fetch_bench_metadata(const std::string& metadata_file, uint64_t* op_size,
78 uint64_t* object_size, int* num_ops, int* num_objects, int* prev_pid);
79
80 int write_bench(int secondsToRun, int concurrentios, const std::string& run_name_meta, unsigned max_objects, int prev_pid);
81 int seq_read_bench(int secondsToRun, int num_ops, int num_objects, int concurrentios, int writePid, bool no_verify=false);
82 int rand_read_bench(int secondsToRun, int num_ops, int num_objects, int concurrentios, int writePid, bool no_verify=false);
83
84 int clean_up(int num_objects, int prevPid, int concurrentios);
85 bool more_objects_matching_prefix(const std::string& prefix, std::list<Object>* name);
86
87 virtual int completions_init(int concurrentios) = 0;
88 virtual void completions_done() = 0;
89
90 virtual int create_completion(int i, void (*cb)(void *, void*), void *arg) = 0;
91 virtual void release_completion(int slot) = 0;
92
93 virtual bool completion_is_done(int slot) = 0;
94 virtual int completion_wait(int slot) = 0;
95 virtual int completion_ret(int slot) = 0;
96
97 virtual int aio_read(const std::string& oid, int slot, bufferlist *pbl, size_t len, size_t offset) = 0;
98 virtual int aio_write(const std::string& oid, int slot, bufferlist& bl, size_t len, size_t offset) = 0;
99 virtual int aio_remove(const std::string& oid, int slot) = 0;
100 virtual int sync_read(const std::string& oid, bufferlist& bl, size_t len) = 0;
101 virtual int sync_write(const std::string& oid, bufferlist& bl, size_t len) = 0;
102 virtual int sync_remove(const std::string& oid) = 0;
103
104 virtual bool get_objects(std::list< std::pair<std::string, std::string> >* objects, int num) = 0;
105 virtual void set_namespace(const std::string&) {}
106
107 std::ostream& out(std::ostream& os);
108 std::ostream& out(std::ostream& os, utime_t& t);
109 public:
110 explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), data() {}
111 virtual ~ObjBencher() {}
112 int aio_bench(
113 int operation, int secondsToRun,
114 int concurrentios, uint64_t op_size, uint64_t object_size, unsigned max_objects,
115 bool cleanup, bool hints, const std::string& run_name, bool reuse_bench, bool no_verify=false);
116 int clean_up(const std::string& prefix, int concurrentios, const std::string& run_name);
117
118 void set_show_time(bool dt) {
119 show_time = dt;
120 }
121 void set_formatter(Formatter *f) {
122 formatter = f;
123 }
124 void set_outstream(std::ostream& os) {
125 outstream = &os;
126 }
127 int clean_up_slow(const std::string& prefix, int concurrentios);
128 };
129
130
131 #endif