summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHaavard <havardpe@yahoo-inc.com>2016-10-13 11:47:41 +0000
committerHaavard <havardpe@yahoo-inc.com>2016-10-13 11:47:41 +0000
commit1a82b35e6a5d10f91230c897acc4f84f9140a684 (patch)
tree52d905192725f1ce351e9facf0b98507cec6ef06 /searchcore
parent2ef4027bb000beb8390255c84ed236288985ad28 (diff)
isolate work sharing (detangle from iterator init/step)
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp29
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_thread.h10
2 files changed, 17 insertions, 22 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
index dd19d2c8e14..5728bbcd487 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
@@ -97,7 +97,7 @@ const double *get_score_feature(const RankProgram &rankProgram) {
//-----------------------------------------------------------------------------
MatchThread::Context::Context(double rankDropLimit, MatchTools & matchTools, RankProgram & ranking, HitCollector & hits,
- DocidRangeScheduler & scheduler, uint32_t num_threads) :
+ uint32_t num_threads) :
matches(0),
_matches_limit(matchTools.match_limiter().sample_hits_per_thread(num_threads)),
_score_feature(get_score_feature(ranking)),
@@ -105,8 +105,7 @@ MatchThread::Context::Context(double rankDropLimit, MatchTools & matchTools, Ran
_rankDropLimit(rankDropLimit),
_hits(hits),
_doom(matchTools.doom()),
- _limiter(matchTools.match_limiter()),
- _idle_observer(scheduler.make_idle_observer())
+ _limiter(matchTools.match_limiter())
{
}
@@ -152,19 +151,15 @@ MatchThread::limit(MaybeMatchPhaseLimiter & limiter, IteratorT & search, uint32_
LOG(debug, "SearchIterator after limiter: %s", search->asString().c_str());
}
-template <typename IteratorT>
-uint32_t
-MatchThread::updateRange(uint32_t nextDocId, DocidRange & docid_range, IteratorT & search) {
- DocidRange todo(nextDocId, docid_range.end);
+bool
+MatchThread::try_share(DocidRange &docid_range, uint32_t next_docid) {
+ DocidRange todo(next_docid, docid_range.end);
DocidRange my_work = scheduler.share_range(thread_id, todo);
if (my_work.end < todo.end) {
docid_range = my_work;
- search->initRange(docid_range.begin, docid_range.end);
- nextDocId = search->seekFirst(docid_range.begin);
- } else {
- nextDocId = search->seekNext(nextDocId);
+ return true;
}
- return nextDocId;
+ return false;
}
template <typename IteratorT, bool do_rank, bool do_limit, bool do_share_work>
@@ -184,8 +179,9 @@ MatchThread::inner_match_loop(Context & context, IteratorT & search, DocidRange
if (do_limit && context.isAtLimit()) {
limit(context.limiter(), search, context.matches, docId, docid_range.end);
docId = search->seekFirst(docId + 1);
- } else if (do_share_work && context.anyOneIdle()) {
- docId = updateRange(docId + 1, docid_range, search);
+ } else if (do_share_work && any_idle() && try_share(docid_range, docId + 1)) {
+ search->initRange(docid_range.begin, docid_range.end);
+ docId = search->seekFirst(docid_range.begin);
} else {
docId = search->seekNext(docId + 1);
}
@@ -197,7 +193,7 @@ void
MatchThread::match_loop(MatchTools &matchTools, IteratorT search,
RankProgram &ranking, HitCollector &hits)
{
- Context context(matchParams.rankDropLimit, matchTools, ranking, hits, scheduler, num_threads);
+ Context context(matchParams.rankDropLimit, matchTools, ranking, hits, num_threads);
for (DocidRange docid_range = scheduler.first_range(thread_id);
!docid_range.empty();
docid_range = scheduler.next_range(thread_id))
@@ -223,7 +219,7 @@ void
MatchThread::match_loop_helper_2(MatchTools &matchTools, IteratorT search,
RankProgram &ranking, HitCollector &hits)
{
- if (scheduler.make_idle_observer().is_always_zero()) {
+ if (idle_observer.is_always_zero()) {
match_loop<IteratorT, do_rank, do_limit, false>(matchTools, std::move(search), ranking, hits);
} else {
match_loop<IteratorT, do_rank, do_limit, true>(matchTools, std::move(search), ranking, hits);
@@ -365,6 +361,7 @@ MatchThread::MatchThread(size_t thread_id_in,
matchToolsFactory(mtf),
communicator(com),
scheduler(sched),
+ idle_observer(scheduler.make_idle_observer()),
_distributionKey(distributionKey),
resultProcessor(rp),
mergeDirector(md),
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.h b/searchcore/src/vespa/searchcore/proton/matching/match_thread.h
index 09d6f4db313..968c01b512f 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.h
@@ -38,6 +38,7 @@ private:
const MatchToolsFactory &matchToolsFactory;
IMatchLoopCommunicator &communicator;
DocidRangeScheduler &scheduler;
+ IdleObserver idle_observer;
uint32_t _distributionKey;
ResultProcessor &resultProcessor;
vespalib::DualMergeDirector &mergeDirector;
@@ -50,13 +51,12 @@ private:
class Context {
public:
Context(double rankDropLimit, MatchTools &matchTools, RankProgram & ranking, HitCollector & hits,
- DocidRangeScheduler & scheduler, uint32_t num_threads) __attribute__((noinline));
+ uint32_t num_threads) __attribute__((noinline));
void rankHit(uint32_t docId);
void addHit(uint32_t docId) { _hits.addHit(docId, 0.0); }
bool isBelowLimit() const { return matches < _matches_limit; }
bool isAtLimit() const { return matches == _matches_limit; }
bool doom() const { return _doom.doom(); }
- bool anyOneIdle() const { return _idle_observer.get() > 0; }
MaybeMatchPhaseLimiter & limiter() { return _limiter; }
uint32_t matches;
private:
@@ -67,7 +67,6 @@ private:
HitCollector & _hits;
const Doom & _doom;
MaybeMatchPhaseLimiter & _limiter;
- IdleObserver _idle_observer;
};
double updateEstimates(MaybeMatchPhaseLimiter & limiter, uint32_t matches, uint32_t searchedSoFar, uint32_t left) __attribute__((noinline));
@@ -75,8 +74,8 @@ private:
template <typename IteratorT>
void limit(MaybeMatchPhaseLimiter & limiter, IteratorT & search, uint32_t matches, uint32_t docId, uint32_t endId) __attribute__((noinline));
- template <typename IteratorT>
- uint32_t updateRange(uint32_t nextDocId, DocidRange & docid_range, IteratorT & search) __attribute__((noinline));
+ bool any_idle() const { return (idle_observer.get() > 0); }
+ bool try_share(DocidRange &docid_range, uint32_t next_docid) __attribute__((noinline));
template <typename IteratorT, bool do_rank, bool do_limit, bool do_share_work>
void inner_match_loop(Context & params, IteratorT & search, DocidRange docid_range) __attribute__((noinline));
@@ -110,4 +109,3 @@ public:
} // namespace proton::matching
} // namespace proton
-