From 51cdd593da05ba13db9ef11f0e300f0e86b2d205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Aleksandrovi=C4=8D=20Klimov?= Date: Mon, 19 Feb 2024 14:26:06 +0100 Subject: [PATCH] Don't unnecessarily shuffle items before config validation Before ae693cb7e1df1b885142854cf8a0f8a7600a3fb7 (#9577) we've repeatedly looped over all items in parallel like this: while not types.done: for t in types: if not t.done and t.dependencies.done: with parallel(all_items, CONCURRENCY) as some_items: for i in some_items: if i.type is t: i.commit() I.e. all items got distributed over CONCURRENCY threads, but not always equally. E.g. it was the hosts' turn, but only two threads got hosts and did all the work. The others didn't do actual work (due to the lack of hosts in their queue) which reduced the performance. c721c302cd9c96bee25a20b3862dad347345648a (#6581) fixed it by shuffling all_items first. ae693cb7e1df1b885142854cf8a0f8a7600a3fb7 (#9577) made the latter unnecessary by replacing the above algorithm with this: while not types.done: for t in types: if not t.done and t.dependencies.done: with parallel(all_items[t], CONCURRENCY) as some_items: for i in some_items: if i.type is t: i.commit() I.e. parallel() gets only items of type t, so all threads get e.g. hosts. --- lib/config/configitem.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 9dc0f1aa2..f54b90c95 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -439,12 +439,6 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue if (!total) 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. - for (auto& kv : itemsByType) { - std::shuffle(std::begin(kv.second), std::end(kv.second), std::default_random_engine{}); - } - #ifdef I2_DEBUG Log(LogDebug, "configitem") << "Committing " << total << " new items.";