Merge pull request #6581 from Icinga/fix/speedup-config

Shuffle items before config validation
This commit is contained in:
Michael Friedrich 2018-09-04 11:15:13 +02:00 committed by GitHub
commit 81b9c9cef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -39,6 +39,8 @@
#include <boost/algorithm/string/join.hpp>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <random>
using namespace icinga;
@ -437,6 +439,10 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
if (items.empty())
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)
newItems.push_back(ip.first);