1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include "os/filestore/FileStore.h"
#include "include/Context.h"
#include "common/ceph_argparse.h"
#include "global/global_init.h"
#include "common/Mutex.h"
#include "common/Cond.h"
#include <boost/scoped_ptr.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/binomial_distribution.hpp>
#include <gtest/gtest.h>
#include "include/unordered_map.h"
void usage(const string &name) {
std::cerr << "Usage: " << name << " [xattr|omap] store_path store_journal"
<< std::endl;
}
const int THREADS = 5;
template <typename T>
typename T::iterator rand_choose(T &cont) {
if (cont.size() == 0) {
return cont.end();
}
int index = rand() % cont.size();
typename T::iterator retval = cont.begin();
for (; index > 0; --index) ++retval;
return retval;
}
class OnApplied : public Context {
public:
Mutex *lock;
Cond *cond;
int *in_progress;
ObjectStore::Transaction *t;
OnApplied(Mutex *lock,
Cond *cond,
int *in_progress,
ObjectStore::Transaction *t)
: lock(lock), cond(cond),
in_progress(in_progress), t(t) {
Mutex::Locker l(*lock);
(*in_progress)++;
}
void finish(int r) override {
Mutex::Locker l(*lock);
(*in_progress)--;
cond->Signal();
}
};
uint64_t get_time() {
time_t start;
time(&start);
return start * 1000;
}
double print_time(uint64_t ms) {
return ((double)ms)/1000;
}
uint64_t do_run(ObjectStore *store, int attrsize, int numattrs,
int run,
int transsize, int ops,
ostream &out) {
Mutex lock("lock");
Cond cond;
int in_flight = 0;
ObjectStore::Sequencer osr(__func__);
ObjectStore::Transaction t;
map<coll_t, pair<set<string>, ObjectStore::Sequencer*> > collections;
for (int i = 0; i < 3*THREADS; ++i) {
coll_t coll(spg_t(pg_t(0, i + 1000*run), shard_id_t::NO_SHARD));
t.create_collection(coll, 0);
set<string> objects;
for (int i = 0; i < transsize; ++i) {
stringstream obj_str;
obj_str << i;
t.touch(coll,
ghobject_t(hobject_t(sobject_t(obj_str.str(), CEPH_NOSNAP))));
objects.insert(obj_str.str());
}
collections[coll] = make_pair(objects, new ObjectStore::Sequencer(coll.to_str()));
}
store->queue_transaction(&osr, std::move(t));
bufferlist bl;
for (int i = 0; i < attrsize; ++i) {
bl.append('\0');
}
uint64_t start = get_time();
for (int i = 0; i < ops; ++i) {
{
Mutex::Locker l(lock);
while (in_flight >= THREADS)
cond.Wait(lock);
}
ObjectStore::Transaction *t = new ObjectStore::Transaction;
map<coll_t, pair<set<string>, ObjectStore::Sequencer*> >::iterator iter =
rand_choose(collections);
for (set<string>::iterator obj = iter->second.first.begin();
obj != iter->second.first.end();
++obj) {
for (int j = 0; j < numattrs; ++j) {
stringstream ss;
ss << i << ", " << j << ", " << *obj;
t->setattr(iter->first,
ghobject_t(hobject_t(sobject_t(*obj, CEPH_NOSNAP))),
ss.str().c_str(),
bl);
}
}
store->queue_transaction(iter->second.second, std::move(*t),
new OnApplied(&lock, &cond, &in_flight,
t));
delete t;
}
{
Mutex::Locker l(lock);
while (in_flight)
cond.Wait(lock);
}
return get_time() - start;
}
int main(int argc, char **argv) {
vector<const char*> args;
argv_to_vec(argc, (const char **)argv, args);
if (args.empty()) {
cerr << argv[0] << ": -h or --help for usage" << std::endl;
exit(1);
}
if (ceph_argparse_need_usage(args)) {
usage(argv[0]);
exit(0);
}
auto cct = global_init(0, args, CEPH_ENTITY_TYPE_CLIENT,
CODE_ENVIRONMENT_UTILITY,
CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
common_init_finish(g_ceph_context);
std::cerr << "args: " << args << std::endl;
if (args.size() < 3) {
usage(argv[0]);
return 1;
}
string store_path(args[1]);
string store_dev(args[2]);
boost::scoped_ptr<ObjectStore> store(new FileStore(cct.get(), store_path,
store_dev));
std::cerr << "mkfs starting" << std::endl;
ceph_assert(!store->mkfs());
ceph_assert(!store->mount());
std::cerr << "mounted" << std::endl;
std::cerr << "attrsize\tnumattrs\ttranssize\tops\ttime" << std::endl;
int runs = 0;
int total_size = 11;
for (int i = 6; i < total_size; ++i) {
for (int j = (total_size - i); j >= 0; --j) {
std::cerr << "starting run " << runs << std::endl;
++runs;
uint64_t time = do_run(store.get(), (1 << i), (1 << j), runs,
10,
1000, std::cout);
std::cout << (1 << i) << "\t"
<< (1 << j) << "\t"
<< 10 << "\t"
<< 1000 << "\t"
<< print_time(time) << std::endl;
}
}
store->umount();
return 0;
}
|