summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-04 07:47:12 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-01-04 07:47:12 +0000
commit8f3cf5aa28519c85211812d218f9e63a7e605edd (patch)
tree73f0a7b3ee7d83ec0223248292660758ad22b3ef /searchlib
parentb28f2e1353432a076d9a5fe4a98bc72dcf476f6b (diff)
Add test for distribution of tasks
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/common/isequencedtaskexecutor.h7
2 files changed, 16 insertions, 2 deletions
diff --git a/searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp b/searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp
index 558d24551a8..fcc7fd7300d 100644
--- a/searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp
+++ b/searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp
@@ -234,6 +234,17 @@ TEST("require that you get correct number of executors") {
EXPECT_EQUAL(7u, seven.getNumExecutors());
}
+TEST("require that you distribute well") {
+ SequencedTaskExecutor seven(7);
+ EXPECT_EQUAL(7u, seven.getNumExecutors());
+ EXPECT_EQUAL(97u, seven.getComponentHashSize());
+ EXPECT_EQUAL(0u, seven.getComponentEffectiveHashSize());
+ for (uint32_t id=0; id < 1000; id++) {
+ EXPECT_EQUAL((id%97)%7, seven.getExecutorId(id).getId());
+ }
+ EXPECT_EQUAL(97u, seven.getComponentHashSize());
+ EXPECT_EQUAL(97u, seven.getComponentEffectiveHashSize());
+}
}
diff --git a/searchlib/src/vespa/searchlib/common/isequencedtaskexecutor.h b/searchlib/src/vespa/searchlib/common/isequencedtaskexecutor.h
index d1318a2b71c..109e8319148 100644
--- a/searchlib/src/vespa/searchlib/common/isequencedtaskexecutor.h
+++ b/searchlib/src/vespa/searchlib/common/isequencedtaskexecutor.h
@@ -71,7 +71,6 @@ public:
* Wrap lambda function into a task and schedule it to be run.
* Caller must ensure that pointers and references are valid and
* call sync before tearing down pointed to/referenced data.
- * All tasks must be scheduled from same thread.
*
* @param componentId component id
* @param function function to be wrapped in a task and later executed
@@ -86,7 +85,6 @@ public:
* Wrap lambda function into a task and schedule it to be run.
* Caller must ensure that pointers and references are valid and
* call sync before tearing down pointed to/referenced data.
- * All tasks must be scheduled from same thread.
*
* @param id executor id
* @param function function to be wrapped in a task and later executed
@@ -95,6 +93,11 @@ public:
void execute(ExecutorId id, FunctionType &&function) {
executeTask(id, vespalib::makeLambdaTask(std::forward<FunctionType>(function)));
}
+ /**
+ * For testing only
+ */
+ uint32_t getComponentHashSize() const { return _component2Id.size(); }
+ uint32_t getComponentEffectiveHashSize() const { return _nextId; }
private:
mutable std::vector<uint8_t> _component2Id;
mutable std::mutex _mutex;