-
Notifications
You must be signed in to change notification settings - Fork 409
/
PSWorkload.cpp
179 lines (159 loc) · 5.73 KB
/
PSWorkload.cpp
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
// Copyright 2022 PingCAP, Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <Common/MemoryTracker.h>
#include <Encryption/MockKeyManager.h>
#include <PSWorkload.h>
#include <Poco/Logger.h>
#include <Storages/Page/V2/PageStorage.h>
#include <Storages/Page/V3/PageStorageImpl.h>
#include <TestUtils/MockDiskDelegator.h>
void StressWorkload::onDumpResult()
{
UInt64 time_interval = stop_watch.elapsedMilliseconds();
LOG_INFO(options.logger, fmt::format("result in {}ms", time_interval));
double seconds_run = 1.0 * time_interval / 1000;
size_t total_pages_written = 0;
size_t total_bytes_written = 0;
for (auto & writer : writers)
{
total_pages_written += writer->pages_used;
total_bytes_written += writer->bytes_used;
}
size_t total_pages_read = 0;
size_t total_bytes_read = 0;
for (auto & reader : readers)
{
total_pages_read += reader->pages_used;
total_bytes_read += reader->bytes_used;
}
LOG_INFO(options.logger,
fmt::format(
"W: {} pages, {:.4f} GB, {:.4f} GB/s",
total_pages_written,
static_cast<double>(total_bytes_written) / DB::GB,
static_cast<double>(total_bytes_written) / DB::GB / seconds_run));
LOG_INFO(options.logger,
fmt::format(
"R: {} pages, {:.4f} GB, {:.4f} GB/s",
total_pages_read,
static_cast<double>(total_bytes_read) / DB::GB,
static_cast<double>(total_bytes_read) / DB::GB / seconds_run));
if (options.status_interval != 0)
{
LOG_INFO(options.logger, metrics_dumper->toString());
}
}
void StressWorkload::initPageStorage(DB::PageStorage::Config & config, String path_prefix)
{
DB::FileProviderPtr file_provider = std::make_shared<DB::FileProvider>(std::make_shared<DB::MockKeyManager>(false), false);
if (path_prefix.empty())
{
// FIXME: running with `MockDiskDelegatorMulti` is not well-testing
if (options.paths.empty())
throw DB::Exception("Can not run without paths");
if (options.paths.size() == 1)
delegator = std::make_shared<DB::tests::MockDiskDelegatorSingle>(options.paths[0]);
else
delegator = std::make_shared<DB::tests::MockDiskDelegatorMulti>(options.paths);
}
else
{
// Running Special test use this path
delegator = std::make_shared<DB::tests::MockDiskDelegatorSingle>(options.paths[0] + "/" + path_prefix);
}
if (options.running_ps_version == 2)
{
ps = std::make_shared<DB::PS::V2::PageStorage>("stress_test", delegator, config, file_provider);
}
else if (options.running_ps_version == 3)
{
ps = std::make_shared<DB::PS::V3::PageStorageImpl>("stress_test", delegator, config, file_provider);
}
else
{
throw DB::Exception(fmt::format("Invalid PageStorage version {}",
options.running_ps_version));
}
ps->restore();
{
size_t num_of_pages = 0;
ps->traverse([&num_of_pages](const DB::Page & page) {
(void)page;
num_of_pages++;
});
LOG_INFO(StressEnv::logger, fmt::format("Recover {} pages.", num_of_pages));
}
}
void StressWorkload::startBackgroundTimer()
{
// A background thread that do GC
gc = std::make_shared<PSGc>(ps);
gc->start();
// A background thread that scan all pages
scanner = std::make_shared<PSScanner>(ps);
scanner->start();
if (options.status_interval > 0)
{
// Dump metrics periodically
metrics_dumper = std::make_shared<PSMetricsDumper>(options.status_interval);
metrics_dumper->start();
}
if (options.timeout_s > 0)
{
// Expected timeout for testing
stress_time = std::make_shared<StressTimeout>(options.timeout_s);
stress_time->start();
}
}
void StressWorkloadManger::runWorkload()
{
if (options.just_init_pages || options.situation_mask == NORMAL_WORKLOAD)
{
String name;
WorkloadCreator func;
std::tie(name, func) = get(NORMAL_WORKLOAD);
auto workload = std::shared_ptr<StressWorkload>(func(options));
LOG_INFO(StressEnv::logger, fmt::format("Start Running {} , {}", name, workload->desc()));
workload->run();
if (!options.just_init_pages)
{
workload->onDumpResult();
}
return;
}
// skip NORMAL_WORKLOAD
funcs.erase(funcs.find(NORMAL_WORKLOAD));
LOG_INFO(options.logger, toWorkloadSelctedString());
for (auto & it : funcs)
{
if (options.situation_mask & it.first)
{
auto & name = it.second.first;
auto & creator = it.second.second;
auto workload = creator(options);
LOG_INFO(StressEnv::logger, fmt::format("Start Running {} , {}", name, workload->desc()));
workload->run();
if (options.verify && !workload->verify())
{
LOG_WARNING(StressEnv::logger, fmt::format("work load : {} failed.", name));
workload->onFailed();
break;
}
else
{
workload->onDumpResult();
}
}
}
}