]> granicus.if.org Git - icinga2/commitdiff
Shuffle items before config validation
authorJean Flach <jean-marcel.flach@icinga.com>
Fri, 31 Aug 2018 11:11:50 +0000 (13:11 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 20 Sep 2018 09:45:54 +0000 (11:45 +0200)
refs #6581

lib/config/configitem.cpp

index c790f8794eb3a8b54c782b3c0111d14820da34c6..d930872873a7155404682cadd9889b0062d9c05f 100644 (file)
@@ -38,6 +38,8 @@
 #include "base/function.hpp"
 #include <sstream>
 #include <fstream>
+#include <algorithm>
+#include <random>
 
 using namespace icinga;
 
@@ -428,6 +430,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);