diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2023-02-01 15:53:13 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2023-02-07 12:42:19 +0000 |
commit | 1cfb2ee3902ee22a6a2df828c58f0ec514acfc7c (patch) | |
tree | 82b167da8f7df132f12cd9406c982a1c786cbac2 | |
parent | 95e694413c0d4638c95e1d1285b6a45727dc616a (diff) |
profile global filter calculation
4 files changed, 47 insertions, 9 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp index 86b21445919..fa95d729c2c 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp @@ -230,7 +230,7 @@ MatchToolsFactory(QueryLimiter & queryLimiter, _match_limiter = std::make_unique<NoMatchPhaseLimiter>(); } trace.addEvent(4, "Complete query setup"); - if (root_trace.shouldTrace(4)) { + if (trace.hasTrace()) { vespalib::slime::ObjectInserter inserter(root_trace.createCursor("query_setup"), "traces"); vespalib::slime::inject(trace.getTraces(), inserter); } diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.cpp b/searchcore/src/vespa/searchcore/proton/matching/query.cpp index 9217b985ba5..b7e3f32a6f6 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/query.cpp @@ -292,7 +292,7 @@ Query::handle_global_filter(Blueprint& blueprint, uint32_t docid_limit, trace->addEvent(5, vespalib::make_string("Calculate global filter (estimated_hit_ratio (%f) <= upper_limit (%f))", estimated_hit_ratio, global_filter_upper_limit)); } - global_filter = GlobalFilter::create(blueprint, docid_limit, thread_bundle); + global_filter = GlobalFilter::create(blueprint, docid_limit, thread_bundle, trace); if (!global_filter->is_active() && trace && trace->shouldTrace(5)) { trace->addEvent(5, "Global filter matches everything"); } diff --git a/searchlib/src/vespa/searchlib/queryeval/global_filter.cpp b/searchlib/src/vespa/searchlib/queryeval/global_filter.cpp index 2d88883780a..f4ee9bf9bc2 100644 --- a/searchlib/src/vespa/searchlib/queryeval/global_filter.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/global_filter.cpp @@ -2,11 +2,17 @@ #include "global_filter.h" #include "blueprint.h" +#include "profiled_iterator.h" #include <vespa/vespalib/util/require.h> #include <vespa/vespalib/util/thread_bundle.h> +#include <vespa/vespalib/util/execution_profiler.h> #include <vespa/searchlib/common/bitvector.h> +#include <vespa/searchlib/engine/trace.h> +#include <vespa/vespalib/data/slime/slime.h> #include <cassert> +using search::engine::Trace; +using vespalib::ExecutionProfiler; using vespalib::Runnable; using vespalib::ThreadBundle; using vespalib::Trinary; @@ -80,12 +86,15 @@ struct PartResult { : matches_any(Trinary::Undefined), bits(std::move(bits_in)) {} }; -PartResult make_part(Blueprint &blueprint, uint32_t begin, uint32_t end) { +PartResult make_part(Blueprint &blueprint, uint32_t begin, uint32_t end, ExecutionProfiler *profiler) { bool strict = true; auto constraint = Blueprint::FilterConstraint::UPPER_BOUND; auto filter = blueprint.createFilterSearch(strict, constraint); auto matches_any = filter->matches_any(); if (matches_any == Trinary::Undefined) { + if (profiler) { + filter = ProfiledIterator::profile(*profiler, std::move(filter)); + } filter->initRange(begin, end); auto bits = filter->get_hits(begin); // count bits in parallel and cache the results for later @@ -101,10 +110,31 @@ struct MakePart : Runnable { uint32_t begin; uint32_t end; PartResult result; - MakePart(Blueprint &blueprint_in, uint32_t begin_in, uint32_t end_in) noexcept - : blueprint(blueprint_in), begin(begin_in), end(end_in), result() {} - void run() override { result = make_part(blueprint, begin, end); } + std::unique_ptr<ExecutionProfiler> profiler; + MakePart(MakePart &&) = default; + MakePart(Blueprint &blueprint_in, uint32_t begin_in, uint32_t end_in, int32_t profile_depth) + : blueprint(blueprint_in), begin(begin_in), end(end_in), result(), profiler() + { + if (profile_depth != 0) { + profiler = std::make_unique<ExecutionProfiler>(profile_depth); + } + } + void run() override { result = make_part(blueprint, begin, end, profiler.get()); } + ~MakePart(); }; +MakePart::~MakePart() = default; + +void maybe_insert_profiler_results(Trace *trace, int32_t profile_depth, const std::vector<MakePart> &parts) { + if (trace && profile_depth != 0) { + auto &obj = trace->createCursor("global_filter_execution"); + auto &arr = obj.setArray("threads"); + for (auto &&part: parts) { + auto &dst = arr.addObject().setArray("traces").addObject(); + dst.setString("tag", "global_filter_profiling"); + part.profiler->report(dst); + } + } +} } @@ -159,8 +189,9 @@ GlobalFilter::create(std::vector<std::unique_ptr<BitVector>> vectors) } std::shared_ptr<GlobalFilter> -GlobalFilter::create(Blueprint &blueprint, uint32_t docid_limit, ThreadBundle &thread_bundle) +GlobalFilter::create(Blueprint &blueprint, uint32_t docid_limit, ThreadBundle &thread_bundle, Trace *trace) { + int32_t profile_depth = (trace && trace->getLevel() > 0) ? trace->match_profile_depth() : 0; uint32_t num_threads = thread_bundle.size(); std::vector<MakePart> parts; parts.reserve(num_threads); @@ -169,12 +200,13 @@ GlobalFilter::create(Blueprint &blueprint, uint32_t docid_limit, ThreadBundle &t uint32_t rest_docs = (docid_limit - docid) % num_threads; while (docid < docid_limit) { uint32_t part_size = per_thread + (parts.size() < rest_docs); - parts.emplace_back(blueprint, docid, docid + part_size); + parts.emplace_back(blueprint, docid, docid + part_size, profile_depth); docid += part_size; } assert(parts.size() <= num_threads); assert((docid == docid_limit) || parts.empty()); thread_bundle.run(parts); + maybe_insert_profiler_results(trace, profile_depth, parts); std::vector<std::unique_ptr<BitVector>> vectors; vectors.reserve(parts.size()); for (MakePart &part: parts) { diff --git a/searchlib/src/vespa/searchlib/queryeval/global_filter.h b/searchlib/src/vespa/searchlib/queryeval/global_filter.h index 66f85299dd1..c2b7b6617fc 100644 --- a/searchlib/src/vespa/searchlib/queryeval/global_filter.h +++ b/searchlib/src/vespa/searchlib/queryeval/global_filter.h @@ -8,6 +8,8 @@ namespace vespalib { struct ThreadBundle; } namespace search { class BitVector; } +namespace search::engine { class Trace; } + namespace search::queryeval { class Blueprint; @@ -22,6 +24,7 @@ class Blueprint; class GlobalFilter : public std::enable_shared_from_this<GlobalFilter> { public: + using Trace = search::engine::Trace; GlobalFilter() noexcept; GlobalFilter(const GlobalFilter &) = delete; GlobalFilter(GlobalFilter &&) = delete; @@ -39,7 +42,10 @@ public: static std::shared_ptr<GlobalFilter> create(std::vector<uint32_t> docids, uint32_t size); static std::shared_ptr<GlobalFilter> create(std::unique_ptr<BitVector> vector); static std::shared_ptr<GlobalFilter> create(std::vector<std::unique_ptr<BitVector>> vectors); - static std::shared_ptr<GlobalFilter> create(Blueprint &blueprint, uint32_t docid_limit, vespalib::ThreadBundle &thread_bundle); + static std::shared_ptr<GlobalFilter> create(Blueprint &blueprint, uint32_t docid_limit, vespalib::ThreadBundle &thread_bundle, Trace *trace); + static std::shared_ptr<GlobalFilter> create(Blueprint &blueprint, uint32_t docid_limit, vespalib::ThreadBundle &thread_bundle) { + return create(blueprint, docid_limit, thread_bundle, nullptr); + } }; } // namespace |