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