Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions eth_validator_watcher/mod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,27 +321,30 @@ PYBIND11_MODULE(eth_validator_watcher_ext, m) {
std::size_t chunk = (vals.size() / n) + 1;
std::vector<std::thread> threads;
std::vector<std::map<std::string, MetricsByLabel>> thread_metrics(n);
std::map<std::string, MetricsByLabel> metrics;

for (size_t i = 0; i < n; i++) {
threads.push_back(std::thread([slot, i, chunk, &vals, &thread_metrics] {
std::size_t from = i * chunk;
std::size_t to = std::min(from + chunk, vals.size());
process(slot, from, to, vals, thread_metrics[i]);
}));
}
{
py::gil_scoped_release release;
for (size_t i = 0; i < n; i++) {
threads.push_back(std::thread([slot, i, chunk, &vals, &thread_metrics] {
std::size_t from = i * chunk;
std::size_t to = std::min(from + chunk, vals.size());
process(slot, from, to, vals, thread_metrics[i]);
}));
}

for (auto& thread: threads) {
thread.join();
}
for (auto& thread: threads) {
thread.join();
}

std::map<std::string, MetricsByLabel> metrics;
merge(thread_metrics, &metrics);
merge(thread_metrics, &metrics);
}

py::dict pymetrics;
for (const auto& [label, metric]: metrics) {
pymetrics[py::str(label)] = metric;
}

return pymetrics;
});
}