summaryrefslogtreecommitdiffstats
path: root/searchlib/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-12-12 15:44:52 +0100
committerGitHub <noreply@github.com>2023-12-12 15:44:52 +0100
commitefc9e84a4678ce90574cdf3d1dba99b9e04c0a87 (patch)
treea36dd7c01f09fa82bc8cbbc41ee4e1279f80cf8f /searchlib/src
parent96e19ab8cf802a1ddf5087599201511c94ea8814 (diff)
parent81487d4843b65c66f2f14a3346f3b6b51b85e245 (diff)
Merge pull request #29617 from vespa-engine/balder/wire-thread-bundle-to-executeinfo-and-requestcontext
Wire in thread bundle to execute info and request context.
Diffstat (limited to 'searchlib/src')
-rw-r--r--searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp27
-rw-r--r--searchlib/src/tests/queryeval/blueprint/mysearch.h12
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attribute_weighted_set_blueprint.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp5
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/blueprint.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/executeinfo.h36
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/irequestcontext.h9
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp2
12 files changed, 62 insertions, 47 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
index eea6c898aa2..7d994ee4cd6 100644
--- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
@@ -39,13 +39,16 @@ struct WeightOrder {
};
struct RememberExecuteInfo : public MyLeaf {
- ExecuteInfo executeInfo;
+ bool is_strict;
+ double hit_rate;
- using MyLeaf::MyLeaf;
+ RememberExecuteInfo() : MyLeaf(), is_strict(false), hit_rate(0.0) {}
+ RememberExecuteInfo(FieldSpecBaseList fields) : MyLeaf(std::move(fields)), is_strict(false), hit_rate(0.0) {}
void fetchPostings(const ExecuteInfo &execInfo) override {
LeafBlueprint::fetchPostings(execInfo);
- executeInfo = execInfo;
+ is_strict = execInfo.is_strict();
+ hit_rate = execInfo.hit_rate();
}
};
@@ -134,11 +137,11 @@ TEST("test And propagates updated histestimate") {
EXPECT_EQUAL(3u, bp->childCnt());
for (uint32_t i = 0; i < bp->childCnt(); i++) {
const auto & child = dynamic_cast<const RememberExecuteInfo &>(bp->getChild(i));
- EXPECT_EQUAL((i == 0), child.executeInfo.isStrict());
+ EXPECT_EQUAL((i == 0), child.is_strict);
}
- EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).executeInfo.hitRate());
- EXPECT_EQUAL(1.0/250, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).executeInfo.hitRate());
- EXPECT_EQUAL(1.0/(250*25), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).executeInfo.hitRate());
+ EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).hit_rate);
+ EXPECT_EQUAL(1.0/250, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).hit_rate);
+ EXPECT_EQUAL(1.0/(250*25), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).hit_rate);
}
TEST("test Or propagates updated histestimate") {
@@ -154,12 +157,12 @@ TEST("test Or propagates updated histestimate") {
EXPECT_EQUAL(4u, bp->childCnt());
for (uint32_t i = 0; i < bp->childCnt(); i++) {
const auto & child = dynamic_cast<const RememberExecuteInfo &>(bp->getChild(i));
- EXPECT_TRUE(child.executeInfo.isStrict());
+ EXPECT_TRUE(child.is_strict);
}
- EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).executeInfo.hitRate());
- EXPECT_APPROX(0.5, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).executeInfo.hitRate(), 1e-6);
- EXPECT_APPROX(0.5*3.0/5.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).executeInfo.hitRate(), 1e-6);
- EXPECT_APPROX(0.5*3.0*42.0/(5.0*50.0), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(3)).executeInfo.hitRate(), 1e-6);
+ EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).hit_rate);
+ EXPECT_APPROX(0.5, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).hit_rate, 1e-6);
+ EXPECT_APPROX(0.5*3.0/5.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).hit_rate, 1e-6);
+ EXPECT_APPROX(0.5*3.0*42.0/(5.0*50.0), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(3)).hit_rate, 1e-6);
}
TEST("test And Blueprint") {
diff --git a/searchlib/src/tests/queryeval/blueprint/mysearch.h b/searchlib/src/tests/queryeval/blueprint/mysearch.h
index 6cfc7a04368..db7dd2adae6 100644
--- a/searchlib/src/tests/queryeval/blueprint/mysearch.h
+++ b/searchlib/src/tests/queryeval/blueprint/mysearch.h
@@ -58,10 +58,10 @@ public:
if (!_isLeaf) {
ok &= (_md == &md);
}
- for (size_t i = 0; i < _children.size(); ++i) {
- MySearch *child = dynamic_cast<MySearch *>(_children[i].get());
- ok &= (child != 0);
- if (child != 0) {
+ for (const auto & my_search : _children) {
+ auto *child = dynamic_cast<MySearch *>(my_search.get());
+ ok &= (child != nullptr);
+ if (child != nullptr) {
ok &= child->verifyAndInferImpl(md);
}
}
@@ -80,8 +80,8 @@ public:
}
static bool verifyAndInfer(SearchIterator *search, MatchData &md) {
- MySearch *self = dynamic_cast<MySearch *>(search);
- if (self == 0) {
+ auto *self = dynamic_cast<MySearch *>(search);
+ if (self == nullptr) {
return false;
} else {
return self->verifyAndInferImpl(md);
diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_weighted_set_blueprint.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_weighted_set_blueprint.cpp
index 42b2cca06f7..99d3ba3f7aa 100644
--- a/searchlib/src/vespa/searchlib/attribute/attribute_weighted_set_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attribute_weighted_set_blueprint.cpp
@@ -163,7 +163,7 @@ AttributeWeightedSetBlueprint::createFilterSearch(bool strict, FilterConstraint)
void
AttributeWeightedSetBlueprint::fetchPostings(const queryeval::ExecuteInfo &execInfo)
{
- if (execInfo.isStrict()) {
+ if (execInfo.is_strict()) {
for (auto * context : _contexts) {
context->fetchPostings(execInfo);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
index b49ec1bfc9e..b27a67e893b 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
@@ -308,7 +308,7 @@ void
ImportedSearchContext::fetchPostings(const queryeval::ExecuteInfo &execInfo) {
if (!_searchCacheLookup) {
_target_search_context->fetchPostings(execInfo);
- if (!_merger.merge_done() && (execInfo.isStrict() || (_target_attribute.getIsFastSearch() && execInfo.hitRate() > 0.01))) {
+ if (!_merger.merge_done() && (execInfo.is_strict() || (_target_attribute.getIsFastSearch() && execInfo.hit_rate() > 0.01))) {
makeMergedPostings(_target_attribute.getIsFilter());
considerAddSearchCacheEntry();
}
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
index eefb2ea77d5..a291318e837 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
@@ -318,7 +318,7 @@ bool
StringPostingSearchContext<BaseSC, AttrT, DataT>::use_posting_lists_when_non_strict(const queryeval::ExecuteInfo& info) const
{
if (this->isFuzzy()) {
- uint32_t exp_doc_hits = this->_docIdLimit * info.hitRate();
+ uint32_t exp_doc_hits = this->_docIdLimit * info.hit_rate();
constexpr uint32_t fuzzy_use_posting_lists_doc_limit = 10000;
/**
* The above constant was derived after a query latency experiment with fuzzy matching
@@ -441,7 +441,7 @@ NumericPostingSearchContext<BaseSC, AttrT, DataT>::use_posting_lists_when_non_st
constexpr float lookup_match_constant = 5.0;
constexpr float posting_list_merge_constant = 1.0;
- uint32_t exp_doc_hits = this->_docIdLimit * info.hitRate();
+ uint32_t exp_doc_hits = this->_docIdLimit * info.hit_rate();
float avg_values_per_document = static_cast<float>(this->_numValues) / static_cast<float>(this->_docIdLimit);
float lookup_match_cost = exp_doc_hits * avg_values_per_document * lookup_match_constant;
float posting_list_cost = this->estimated_hits_in_range() * posting_list_merge_constant;
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp
index 3ff5c749899..ecdfad433ee 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp
@@ -62,8 +62,7 @@ void
PostingListSearchContextT<DataT>::fillArray()
{
for (auto it(_lowerDictItr); it != _upperDictItr; ++it) {
- _merger.addToArray(PostingListTraverser<PostingStore>(_posting_store,
- it.getData().load_acquire()));
+ _merger.addToArray(PostingListTraverser<PostingStore>(_posting_store, it.getData().load_acquire()));
}
_merger.merge();
}
@@ -110,7 +109,7 @@ PostingListSearchContextT<DataT>::fetchPostings(const queryeval::ExecuteInfo & e
// The threshold for when to use array merging is therefore 0.0025 (0.08 / 32).
constexpr float threshold_for_using_array = 0.0025;
if (!_merger.merge_done() && _uniqueValues >= 2u && this->_dictionary.get_has_btree_dictionary()) {
- if (execInfo.isStrict() || use_posting_lists_when_non_strict(execInfo)) {
+ if (execInfo.is_strict() || use_posting_lists_when_non_strict(execInfo)) {
size_t sum = estimated_hits_in_range();
if (sum < (_docIdLimit * threshold_for_using_array)) {
_merger.reserveArray(_uniqueValues, sum);
diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
index 16a2ba64fa7..043b006d3bd 100644
--- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
@@ -628,10 +628,10 @@ IntermediateBlueprint::visitMembers(vespalib::ObjectVisitor &visitor) const
void
IntermediateBlueprint::fetchPostings(const ExecuteInfo &execInfo)
{
- double nextHitRate = execInfo.hitRate();
+ double nextHitRate = execInfo.hit_rate();
for (size_t i = 0; i < _children.size(); ++i) {
Blueprint & child = *_children[i];
- child.fetchPostings(ExecuteInfo::create(execInfo.isStrict() && inheritStrict(i), nextHitRate, execInfo));
+ child.fetchPostings(ExecuteInfo::create(execInfo.is_strict() && inheritStrict(i), nextHitRate, execInfo));
nextHitRate = computeNextHitRate(child, nextHitRate, execInfo.use_estimate_for_fetch_postings());
}
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp b/searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp
index ac3dfcc3b20..858cb92331a 100644
--- a/searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp
@@ -4,7 +4,7 @@
namespace search::queryeval {
-const ExecuteInfo ExecuteInfo::TRUE(true, 1.0, nullptr, true, true);
-const ExecuteInfo ExecuteInfo::FALSE(false, 1.0, nullptr, true, true);
+const ExecuteInfo ExecuteInfo::TRUE(true, 1.0, nullptr, vespalib::ThreadBundle::trivial(), true, true);
+const ExecuteInfo ExecuteInfo::FALSE(false, 1.0, nullptr, vespalib::ThreadBundle::trivial(), true, true);
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/executeinfo.h b/searchlib/src/vespa/searchlib/queryeval/executeinfo.h
index 01b3ddfd182..3300a2aea4d 100644
--- a/searchlib/src/vespa/searchlib/queryeval/executeinfo.h
+++ b/searchlib/src/vespa/searchlib/queryeval/executeinfo.h
@@ -3,6 +3,7 @@
#pragma once
#include <vespa/vespalib/util/doom.h>
+#include <vespa/vespalib/util/thread_bundle.h>
namespace search::queryeval {
@@ -12,26 +13,27 @@ namespace search::queryeval {
*/
class ExecuteInfo {
public:
- ExecuteInfo() noexcept : ExecuteInfo(false, 1.0, nullptr, true, true) { }
- bool isStrict() const noexcept { return _strict; }
+ ExecuteInfo() noexcept : ExecuteInfo(false, 1.0, nullptr, vespalib::ThreadBundle::trivial(), true, true) { }
+ bool is_strict() const noexcept { return _strict; }
bool create_postinglist_when_non_strict() const noexcept { return _create_postinglist_when_non_strict; }
bool use_estimate_for_fetch_postings() const noexcept { return _use_estimate_for_fetch_postings; }
- double hitRate() const noexcept { return _hitRate; }
+ double hit_rate() const noexcept { return _hitRate; }
bool soft_doom() const noexcept { return _doom && _doom->soft_doom(); }
- const vespalib::Doom * getDoom() const { return _doom; }
+ vespalib::ThreadBundle & thread_bundle() const noexcept { return _thread_bundle; }
+
static const ExecuteInfo TRUE;
static const ExecuteInfo FALSE;
static ExecuteInfo create(bool strict, const ExecuteInfo & org) noexcept {
return create(strict, org._hitRate, org);
}
static ExecuteInfo create(bool strict, double hitRate, const ExecuteInfo & org) noexcept {
- return {strict, hitRate, org.getDoom(), org.create_postinglist_when_non_strict(), org.use_estimate_for_fetch_postings()};
+ return {strict, hitRate, org._doom, org.thread_bundle(), org.create_postinglist_when_non_strict(), org.use_estimate_for_fetch_postings()};
}
- static ExecuteInfo create(bool strict, double hitRate, const vespalib::Doom * doom, bool postinglist_when_non_strict,
- bool use_estimate_for_fetch_postings) noexcept
+ static ExecuteInfo create(bool strict, double hitRate, const vespalib::Doom * doom, vespalib::ThreadBundle & thread_bundle_in,
+ bool postinglist_when_non_strict, bool use_estimate_for_fetch_postings) noexcept
{
- return {strict, hitRate, doom, postinglist_when_non_strict, use_estimate_for_fetch_postings};
+ return {strict, hitRate, doom, thread_bundle_in, postinglist_when_non_strict, use_estimate_for_fetch_postings};
}
static ExecuteInfo createForTest(bool strict) noexcept {
return createForTest(strict, 1.0);
@@ -40,22 +42,24 @@ public:
return createForTest(strict, hitRate, nullptr);
}
static ExecuteInfo createForTest(bool strict, double hitRate, const vespalib::Doom * doom) noexcept {
- return create(strict, hitRate, doom, true, true);
+ return create(strict, hitRate, doom, vespalib::ThreadBundle::trivial(), true, true);
}
private:
- ExecuteInfo(bool strict, double hitRate_in, const vespalib::Doom * doom, bool postinglist_when_non_strict,
- bool use_estimate_for_fetch_postings) noexcept
+ ExecuteInfo(bool strict, double hitRate_in, const vespalib::Doom * doom, vespalib::ThreadBundle & thread_bundle_in,
+ bool postinglist_when_non_strict, bool use_estimate_for_fetch_postings) noexcept
: _doom(doom),
+ _thread_bundle(thread_bundle_in),
_hitRate(hitRate_in),
_strict(strict),
_create_postinglist_when_non_strict(postinglist_when_non_strict),
_use_estimate_for_fetch_postings(use_estimate_for_fetch_postings)
{ }
- const vespalib::Doom * _doom;
- double _hitRate;
- bool _strict;
- bool _create_postinglist_when_non_strict;
- bool _use_estimate_for_fetch_postings;
+ const vespalib::Doom * _doom;
+ vespalib::ThreadBundle & _thread_bundle;
+ double _hitRate;
+ bool _strict;
+ bool _create_postinglist_when_non_strict;
+ bool _use_estimate_for_fetch_postings;
};
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h
index e536727169a..0122352656e 100644
--- a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h
+++ b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h
@@ -11,6 +11,7 @@
#include <vespa/searchlib/attribute/attributevector.h>
#include <vespa/searchlib/attribute/attribute_blueprint_params.h>
#include <vespa/vespalib/util/doom.h>
+#include <vespa/vespalib/util/thread_bundle.h>
#include <limits>
namespace vespalib { class TestClock; }
@@ -25,6 +26,7 @@ public:
vespalib::steady_time hard=vespalib::steady_time::max());
~FakeRequestContext() override;
const vespalib::Doom & getDoom() const override { return _doom; }
+ vespalib::ThreadBundle & thread_bundle() const override { return vespalib::ThreadBundle::trivial(); }
const attribute::IAttributeVector *getAttribute(const vespalib::string &name) const override {
return _attributeContext
? _attributeContext->getAttribute(name)
diff --git a/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h b/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h
index f4c3ae547f0..ad25385be4b 100644
--- a/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h
+++ b/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h
@@ -8,7 +8,10 @@
namespace search::attribute { struct AttributeBlueprintParams; }
namespace search::attribute { class IAttributeVector; }
namespace vespalib::eval { struct Value; }
-namespace vespalib { class Doom; }
+namespace vespalib {
+ class Doom;
+ struct ThreadBundle;
+}
namespace search::queryeval {
@@ -26,6 +29,10 @@ public:
* @return time of soft doom.
*/
virtual const vespalib::Doom & getDoom() const = 0;
+ /**
+ * Provide an optional thread bundle that can be used for multithreading parts of the query.
+ */
+ virtual vespalib::ThreadBundle & thread_bundle() const = 0;
/**
* Provide access to attributevectors
diff --git a/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp
index eb1d217ad6a..f0c75173671 100644
--- a/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp
@@ -61,7 +61,7 @@ SameElementBlueprint::fetchPostings(const ExecuteInfo &execInfo)
if (_terms.empty()) return;
_terms[0]->fetchPostings(execInfo);
double estimate = execInfo.use_estimate_for_fetch_postings() ? _terms[0]->hit_ratio() : _terms[0]->estimate();
- double hit_rate = execInfo.hitRate() * estimate;
+ double hit_rate = execInfo.hit_rate() * estimate;
for (size_t i = 1; i < _terms.size(); ++i) {
Blueprint & term = *_terms[i];
term.fetchPostings(ExecuteInfo::create(false, hit_rate, execInfo));