Shuffle items before config validation

This commit is contained in:
Jean Flach 2018-08-31 13:11:50 +02:00 committed by Michael Friedrich
parent 504b8a17a3
commit c721c302cd
1 changed files with 6 additions and 0 deletions

View File

@ -39,6 +39,8 @@
#include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/join.hpp>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <algorithm>
#include <random>
using namespace icinga; using namespace icinga;
@ -437,6 +439,10 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
if (items.empty()) if (items.empty())
return true; return true;
// Shuffle all items to evenly distribute them over the threads of the workqueue. This increases perfomance
// noticably in environments with lots of objects and available threads.
std::shuffle(std::begin(items), std::end(items), std::default_random_engine {});
for (const auto& ip : items) for (const auto& ip : items)
newItems.push_back(ip.first); newItems.push_back(ip.first);