Skip to content

Commit d056f23

Browse files
turuslankamilsa
andauthored
pvf priority (#2305)
Signed-off-by: turuslan <[email protected]> Co-authored-by: kamilsa <[email protected]>
1 parent 1d5d755 commit d056f23

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

core/parachain/pvf/pvf_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ namespace kagome::parachain {
391391
}
392392
cb(scale::decode<ValidationResult>(r.value()));
393393
},
394+
.kind = timeout_kind,
394395
.timeout =
395396
std::chrono::milliseconds{
396397
timeout_kind == runtime::PvfExecTimeoutKind::Backing

core/parachain/pvf/workers.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "utils/weak_macro.hpp"
2121

2222
namespace kagome::parachain {
23+
constexpr auto kMetricQueueSize = "kagome_pvf_queue_size";
24+
2325
struct AsyncPipe : boost::process::async_pipe {
2426
using async_pipe::async_pipe;
2527
using lowest_layer_type = AsyncPipe;
@@ -133,13 +135,26 @@ namespace kagome::parachain {
133135
.cache_dir = app_config.runtimeCacheDirPath(),
134136
.log_params = app_config.log(),
135137
.force_disable_secure_mode = app_config.disableSecureMode(),
136-
} {}
138+
} {
139+
metrics_registry_->registerGaugeFamily(kMetricQueueSize, "pvf queue size");
140+
std::unordered_map<PvfExecTimeoutKind, std::string> kind_name{
141+
{PvfExecTimeoutKind::Approval, "Approval"},
142+
{PvfExecTimeoutKind::Backing, "Backing"},
143+
};
144+
for (auto &[kind, name] : kind_name) {
145+
metric_queue_size_.emplace(kind,
146+
metrics_registry_->registerGaugeMetric(
147+
kMetricQueueSize, {{"kind", name}}));
148+
}
149+
}
137150

138151
void PvfWorkers::execute(Job &&job) {
139152
REINVOKE(*main_pool_handler_, execute, std::move(job));
140153
if (free_.empty()) {
141154
if (used_ >= max_) {
142-
queue_.emplace(std::move(job));
155+
auto &queue = queues_[job.kind];
156+
queue.emplace_back(std::move(job));
157+
metric_queue_size_.at(job.kind)->set(queue.size());
143158
return;
144159
}
145160
auto used = std::make_shared<Used>(*this);
@@ -157,10 +172,9 @@ namespace kagome::parachain {
157172
if (not r) {
158173
return job.cb(r.error());
159174
}
160-
self->writeCode(
161-
std::move(job),
162-
{.process = std::move(process)},
163-
std::move(used));
175+
self->writeCode(std::move(job),
176+
{.process = std::move(process)},
177+
std::move(used));
164178
});
165179
return;
166180
}
@@ -244,11 +258,16 @@ namespace kagome::parachain {
244258
}
245259

246260
void PvfWorkers::dequeue() {
247-
if (queue_.empty()) {
248-
return;
261+
for (auto &kind :
262+
{PvfExecTimeoutKind::Approval, PvfExecTimeoutKind::Backing}) {
263+
auto &queue = queues_[kind];
264+
if (queue.empty()) {
265+
continue;
266+
}
267+
auto job = std::move(queue.front());
268+
queue.pop_front();
269+
metric_queue_size_.at(kind)->set(queue.size());
270+
findFree(std::move(job));
249271
}
250-
auto job = std::move(queue_.front());
251-
queue_.pop();
252-
findFree(std::move(job));
253272
}
254273
} // namespace kagome::parachain

core/parachain/pvf/workers.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
#pragma once
88

9+
#include <deque>
910
#include <filesystem>
1011
#include <list>
11-
#include <queue>
1212

13+
#include "metrics/metrics.hpp"
1314
#include "parachain/pvf/pvf_worker_types.hpp"
15+
#include "runtime/runtime_api/parachain_host_types.hpp"
1416

1517
namespace boost::asio {
1618
class io_context;
@@ -33,6 +35,8 @@ namespace kagome::common {
3335
} // namespace kagome::common
3436

3537
namespace kagome::parachain {
38+
using runtime::PvfExecTimeoutKind;
39+
3640
struct ProcessAndPipes;
3741

3842
class PvfWorkers : public std::enable_shared_from_this<PvfWorkers> {
@@ -46,6 +50,7 @@ namespace kagome::parachain {
4650
PvfWorkerInputCodeParams code_params;
4751
Buffer args;
4852
Cb cb;
53+
PvfExecTimeoutKind kind;
4954
std::chrono::milliseconds timeout{0};
5055
};
5156
void execute(Job &&job);
@@ -77,6 +82,9 @@ namespace kagome::parachain {
7782
PvfWorkerInputConfig worker_config_;
7883
std::list<Worker> free_;
7984
size_t used_ = 0;
80-
std::queue<Job> queue_;
85+
std::unordered_map<PvfExecTimeoutKind, std::deque<Job>> queues_;
86+
87+
metrics::RegistryPtr metrics_registry_ = metrics::createRegistry();
88+
std::unordered_map<PvfExecTimeoutKind, metrics::Gauge *> metric_queue_size_;
8189
};
8290
} // namespace kagome::parachain

core/storage/rocksdb/rocksdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace kagome::storage {
9393
if (not enable_migration) {
9494
SL_ERROR(log,
9595
"Database migration is disabled, use older kagome version or "
96-
"run with migration enabling flag");
96+
"run with --enable-db-migration flag");
9797
return DatabaseError::IO_ERROR;
9898
}
9999

0 commit comments

Comments
 (0)