summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2020-06-25 15:31:41 +0000
committerGeir Storli <geirst@verizonmedia.com>2020-06-25 15:53:38 +0000
commit4b5340c5fa6d78af845cc19d1667818fb7d6bf70 (patch)
tree6ae44eb8818fa4be4819faf1e44186ded77e5c6f /staging_vespalib
parent4350799ad50b3377d07857838fab9aac3926b8e4 (diff)
Run prepare step of two-phase puts in the shared executor instead of the attribute field executor.
Benchmarking has shown that we get an uneven balance between the underlying threads when using the attribute field executor. This is a sequenced task executor, where each underlying thread only is allowed to handle a subset of the prepare tasks (based on the local document id). Using the shared executor should give an even balance.
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/foreground_thread_executor.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/foreground_thread_executor.h b/staging_vespalib/src/vespa/vespalib/util/foreground_thread_executor.h
new file mode 100644
index 00000000000..575552971fa
--- /dev/null
+++ b/staging_vespalib/src/vespa/vespalib/util/foreground_thread_executor.h
@@ -0,0 +1,31 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/vespalib/util/threadexecutor.h>
+#include <atomic>
+
+namespace vespalib {
+
+/**
+ * Implementation of the ThreadExecutor interface that runs all tasks in the foreground by the calling thread.
+ */
+class ForegroundThreadExecutor : public vespalib::ThreadExecutor {
+private:
+ std::atomic<size_t> _accepted;
+
+public:
+ ForegroundThreadExecutor() : _accepted(0) { }
+ Task::UP execute(Task::UP task) override {
+ task->run();
+ ++_accepted;
+ return Task::UP();
+ }
+ size_t getNumThreads() const override { return 0; }
+ Stats getStats() override {
+ return ExecutorStats(ExecutorStats::QueueSizeT(), _accepted.load(std::memory_order_relaxed), 0);
+ }
+ virtual void setTaskLimit(uint32_t taskLimit) override { (void) taskLimit; }
+};
+
+}