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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/searchlib/docstore/logdatastore.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
#include <vespa/vespalib/util/closure.h>
#include <vespa/vespalib/util/closuretask.h>
#include <vespa/searchlib/transactionlog/nosyncproxy.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
#include <vespa/vespalib/data/databuffer.h>
#include <vespa/fastos/app.h>
#include <unistd.h>
#include <vespa/log/log.h>
LOG_SETUP("documentstore.benchmark");
using namespace search;
class BenchmarkDataStoreApp : public FastOS_Application
{
void usage();
int benchmark(const vespalib::string & directory, size_t numReads, size_t numThreads, size_t perChunk, const vespalib::string & readType);
int Main() override;
void read(size_t numReads, size_t perChunk, const IDataStore * dataStore);
};
void
BenchmarkDataStoreApp::usage()
{
printf("Usage: %s <direcory> <numreads> <numthreads> <objects per read> <normal,directio,mmap,mlock>\n", _argv[0]);
fflush(stdout);
}
int
BenchmarkDataStoreApp::Main()
{
if (_argc >= 2) {
size_t numThreads(16);
size_t numReads(1000000);
size_t perChunk(1);
vespalib::string readType("directio");
vespalib::string directory(_argv[1]);
if (_argc >= 3) {
numReads = strtoul(_argv[2], NULL, 0);
if (_argc >= 4) {
numThreads = strtoul(_argv[3], NULL, 0);
if (_argc >= 5) {
perChunk = strtoul(_argv[4], NULL, 0);
if (_argc >= 5) {
readType = _argv[5];
}
}
}
}
return benchmark(directory, numReads, numThreads, perChunk, readType);
} else {
fprintf(stderr, "Too few arguments\n");
usage();
return 1;
}
return 0;
}
void BenchmarkDataStoreApp::read(size_t numReads, size_t perChunk, const IDataStore * dataStore)
{
vespalib::DataBuffer buf;
struct random_data rstate;
char state[8];
memset(state, 0, sizeof(state));
memset(&rstate, 0, sizeof(rstate));
const size_t docIdLimit(dataStore->getDocIdLimit());
assert(docIdLimit > 0);
initstate_r(getpid(), state, sizeof(state), &rstate);
assert(srandom_r(getpid(), &rstate) == 0);
int32_t rnd(0);
for ( size_t i(0); i < numReads; i++) {
random_r(&rstate, &rnd);
uint32_t lid(rnd%docIdLimit);
for (uint32_t j(lid); j < std::min(docIdLimit, lid+perChunk); j++) {
dataStore->read(j, buf);
buf.clear();
}
}
}
int
BenchmarkDataStoreApp::benchmark(const vespalib::string & dir, size_t numReads, size_t numThreads, size_t perChunk, const vespalib::string & readType)
{
int retval(0);
LogDataStore::Config config;
GrowStrategy growStrategy;
TuneFileSummary tuning;
if (readType == "directio") {
tuning._randRead.setWantDirectIO();
} else if (readType == "normal") {
tuning._randRead.setWantNormal();
} else if (readType == "mmap") {
tuning._randRead.setWantMemoryMap();
}
search::index::DummyFileHeaderContext fileHeaderContext;
vespalib::ThreadStackExecutor executor(config.getNumThreads(), 128*1024);
transactionlog::NoSyncProxy noTlSyncer;
LogDataStore store(executor, dir, config, growStrategy, tuning,
fileHeaderContext,
noTlSyncer, NULL, true);
vespalib::ThreadStackExecutor bmPool(numThreads, 128*1024);
LOG(info, "Start read benchmark with %lu threads doing %lu reads in chunks of %lu reads. Totally %lu objects", numThreads, numReads, perChunk, numThreads * numReads * perChunk);
for (size_t i(0); i < numThreads; i++) {
bmPool.execute(vespalib::makeTask(vespalib::makeClosure(this, &BenchmarkDataStoreApp::read, numReads, perChunk, static_cast<const IDataStore *>(&store))));
}
bmPool.sync();
LOG(info, "Benchmark done.");
return retval;
}
FASTOS_MAIN(BenchmarkDataStoreApp);
|