]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/obj_bencher.h
update sources to v12.1.0
[ceph.git] / ceph / src / common / obj_bencher.h
CommitLineData
7c673cae
FG
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
7c673cae
FG
18#include "common/ceph_context.h"
19#include "common/Formatter.h"
20#include <cfloat>
21
22struct bench_interval_data {
23 double min_bandwidth = DBL_MAX;
24 double max_bandwidth = 0;
25 int min_iops = INT_MAX;
26 int max_iops = 0;
27};
28
29struct bench_history {
30 vector<double> bandwidth;
31 vector<double> latency;
32 vector<long> iops;
33};
34
35struct bench_data {
36 bool done; //is the benchmark is done
37 uint64_t object_size; //the size of the objects
38 uint64_t op_size; // the size of the read/write ops
39 bool hints;
40 // same as object_size for write tests
41 int in_flight; //number of reads/writes being waited on
42 int started;
43 int finished;
44 double min_latency;
45 double max_latency;
46 double avg_latency;
47 struct bench_interval_data idata; // data that is updated by time intervals and not by events
48 struct bench_history history; // data history, used to calculate stddev
49 utime_t cur_latency; //latency of last completed transaction
50 utime_t start_time; //start time for benchmark
51 char *object_contents; //pointer to the contents written to each object
52};
53
54const int OP_WRITE = 1;
55const int OP_SEQ_READ = 2;
56const int OP_RAND_READ = 3;
57
58// Object is composed of <oid,namespace>
59typedef std::pair<std::string, std::string> Object;
60
61class ObjBencher {
62 bool show_time;
63 Formatter *formatter = NULL;
64 ostream *outstream = NULL;
65public:
66 CephContext *cct;
67protected:
68 Mutex lock;
69
70 static void *status_printer(void *bencher);
71
72 struct bench_data data;
73
74 int fetch_bench_metadata(const std::string& metadata_file, uint64_t* op_size,
75 uint64_t* object_size, int* num_objects, int* prevPid);
76
77 int write_bench(int secondsToRun, int concurrentios, const string& run_name_meta, unsigned max_objects);
78 int seq_read_bench(int secondsToRun, int num_objects, int concurrentios, int writePid, bool no_verify=false);
79 int rand_read_bench(int secondsToRun, int num_objects, int concurrentios, int writePid, bool no_verify=false);
80
81 int clean_up(int num_objects, int prevPid, int concurrentios);
82 bool more_objects_matching_prefix(const std::string& prefix, std::list<Object>* name);
83
84 virtual int completions_init(int concurrentios) = 0;
85 virtual void completions_done() = 0;
86
87 virtual int create_completion(int i, void (*cb)(void *, void*), void *arg) = 0;
88 virtual void release_completion(int slot) = 0;
89
90 virtual bool completion_is_done(int slot) = 0;
91 virtual int completion_wait(int slot) = 0;
92 virtual int completion_ret(int slot) = 0;
93
94 virtual int aio_read(const std::string& oid, int slot, bufferlist *pbl, size_t len, size_t offset) = 0;
95 virtual int aio_write(const std::string& oid, int slot, bufferlist& bl, size_t len, size_t offset) = 0;
96 virtual int aio_remove(const std::string& oid, int slot) = 0;
97 virtual int sync_read(const std::string& oid, bufferlist& bl, size_t len) = 0;
98 virtual int sync_write(const std::string& oid, bufferlist& bl, size_t len) = 0;
99 virtual int sync_remove(const std::string& oid) = 0;
100
101 virtual bool get_objects(std::list< std::pair<std::string, std::string> >* objects, int num) = 0;
102 virtual void set_namespace(const std::string&) {}
103
104 ostream& out(ostream& os);
105 ostream& out(ostream& os, utime_t& t);
106public:
107 explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), lock("ObjBencher::lock") {}
108 virtual ~ObjBencher() {}
109 int aio_bench(
110 int operation, int secondsToRun,
111 int concurrentios, uint64_t op_size, uint64_t object_size, unsigned max_objects,
112 bool cleanup, bool hints, const std::string& run_name, bool no_verify=false);
113 int clean_up(const std::string& prefix, int concurrentios, const std::string& run_name);
114
115 void set_show_time(bool dt) {
116 show_time = dt;
117 }
118 void set_formatter(Formatter *f) {
119 formatter = f;
120 }
121 void set_outstream(ostream& os) {
122 outstream = &os;
123 }
124 int clean_up_slow(const std::string& prefix, int concurrentios);
125};
126
127
128#endif