summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHÃ¥vard Pettersen <3535158+havardpe@users.noreply.github.com>2022-05-06 14:00:23 +0200
committerGitHub <noreply@github.com>2022-05-06 14:00:23 +0200
commita1d094a22cf68b9270cc60f9cdc7a47f2ea6e9ae (patch)
tree20982746686d0ef39b1ee711afc28b74d5b42f67
parente9ae43a8f24f6dfda402c120538af059a13933fb (diff)
parente11a1a9e34c0eabec5a01eea6b44aa14bb906ba4 (diff)
Merge pull request #22495 from vespa-engine/toregge/use-atomic-member-variables-in-query-limiter
Use atomic _maxThreads, _coverage and _minHits member variables in
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp16
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/querylimiter.h10
2 files changed, 16 insertions, 10 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp
index 837d1d2c2a9..df656177cbc 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp
@@ -19,7 +19,7 @@ void
QueryLimiter::grabToken(const Doom & doom)
{
std::unique_lock<std::mutex> guard(_lock);
- while ((_maxThreads > 0) && (_activeThreads >= _maxThreads) && !doom.hard_doom()) {
+ for (auto max_threads = get_max_threads(); (max_threads > 0) && (_activeThreads >= max_threads) && !doom.hard_doom(); max_threads = get_max_threads()) {
vespalib::duration left = doom.hard_left();
if (left > vespalib::duration::zero()) {
_cond.wait_for(guard, left);
@@ -49,18 +49,20 @@ QueryLimiter::QueryLimiter() :
void
QueryLimiter::configure(int maxThreads, double coverage, uint32_t minHits)
{
- _maxThreads = maxThreads;
- _coverage = coverage;
- _minHits = minHits;
+ std::lock_guard<std::mutex> guard(_lock);
+ _maxThreads.store(maxThreads, std::memory_order_relaxed);
+ _coverage.store(coverage, std::memory_order_relaxed);
+ _minHits.store(minHits, std::memory_order_relaxed);
+ _cond.notify_all();
}
QueryLimiter::Token::UP
QueryLimiter::getToken(const Doom & doom, uint32_t numDocs, uint32_t numHits, bool hasSorting, bool hasGrouping)
{
- if (_maxThreads > 0) {
+ if (get_max_threads() > 0) {
if (hasSorting || hasGrouping) {
- if (numHits > _minHits) {
- if (numDocs * _coverage < numHits) {
+ if (numHits > get_min_hits()) {
+ if (numDocs * get_coverage() < numHits) {
return std::make_unique<LimitedToken>(doom, *this);
}
}
diff --git a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h
index 57a0568b57e..67faf74a65d 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h
@@ -40,9 +40,13 @@ private:
int _activeThreads;
// These are updated asynchronously at reconfig.
- volatile int _maxThreads;
- volatile double _coverage;
- volatile uint32_t _minHits;
+ std::atomic<int> _maxThreads;
+ std::atomic<double> _coverage;
+ std::atomic<uint32_t> _minHits;
+
+ [[nodiscard]] int get_max_threads() const noexcept { return _maxThreads.load(std::memory_order_relaxed); }
+ [[nodiscard]] double get_coverage() const noexcept { return _coverage.load(std::memory_order_relaxed); }
+ [[nodiscard]] uint32_t get_min_hits() const noexcept { return _minHits.load(std::memory_order_relaxed); }
};
}