summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-09-14 14:59:05 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-09-14 14:59:05 +0200
commit66cd305337c44b84589fb91e95d3d9662f8e6c5e (patch)
tree0ee43a40ab1d8a0b2b6e1ba837c97a6bfa011834 /vespalib
parentbeb641c2a972af3c992ce46407297e87c3d8e193 (diff)
Limit the number of task s in flight to 2x number of threads in the pool.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/threadexecutor.h5
-rw-r--r--vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/util/threadstackexecutorbase.h4
3 files changed, 12 insertions, 1 deletions
diff --git a/vespalib/src/vespa/vespalib/util/threadexecutor.h b/vespalib/src/vespa/vespalib/util/threadexecutor.h
index 3ec19ea9a71..c202a0a2373 100644
--- a/vespalib/src/vespa/vespalib/util/threadexecutor.h
+++ b/vespalib/src/vespa/vespalib/util/threadexecutor.h
@@ -15,6 +15,11 @@ class ThreadExecutor : public Executor,
public Syncable
{
public:
+ /**
+ * Get number of threads in the executor pool.
+ * @return number of threads in the pool
+ */
+ virtual size_t getNumThreads() const = 0;
};
} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp b/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp
index 76557762479..21d1de2a29b 100644
--- a/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp
+++ b/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp
@@ -155,6 +155,10 @@ ThreadStackExecutorBase::start(uint32_t threads)
}
}
+size_t ThreadStackExecutorBase::getNumThreads() const {
+ return _pool->GetNumStartedThreads();
+}
+
void
ThreadStackExecutorBase::internalSetTaskLimit(uint32_t taskLimit)
{
diff --git a/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.h b/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.h
index 4ea27a2bcde..ee142659027 100644
--- a/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.h
+++ b/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.h
@@ -98,7 +98,7 @@ private:
void unblock();
};
- std::unique_ptr<FastOS_ThreadPool> _pool;
+ std::unique_ptr<FastOS_ThreadPool> _pool;
Monitor _monitor;
Stats _stats;
Gate _executorCompletion;
@@ -223,6 +223,8 @@ public:
**/
void wait_for_task_count(uint32_t task_count);
+ size_t getNumThreads() const override;
+
/**
* Shut down this executor. This will make this executor reject
* all new tasks.