aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/attribute
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/tests/attribute')
-rw-r--r--searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp19
-rw-r--r--searchlib/src/tests/attribute/benchmark/attributesearcher.h17
-rw-r--r--searchlib/src/tests/attribute/benchmark/attributeupdater.h17
3 files changed, 26 insertions, 27 deletions
diff --git a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp
index 0b90b4eae95..d5ea6fdaffc 100644
--- a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp
+++ b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp
@@ -5,7 +5,7 @@
#include <vespa/searchlib/attribute/attributeguard.h>
#include <vespa/searchlib/attribute/attributefactory.h>
#include <vespa/searchcommon/attribute/config.h>
-#include <vespa/fastos/thread.h>
+#include <thread>
#include <vespa/vespalib/util/signalhandler.h>
#include <iostream>
#include "attributesearcher.h"
@@ -96,7 +96,6 @@ private:
static struct rusage computeDifference(struct rusage & first, struct rusage & second);
};
- FastOS_ThreadPool * _threadPool;
Config _config;
RandomGenerator _rndGen;
@@ -129,12 +128,8 @@ private:
public:
- AttributeBenchmark() : _threadPool(NULL), _config(), _rndGen() {}
- ~AttributeBenchmark() {
- if (_threadPool != NULL) {
- delete _threadPool;
- }
- }
+ AttributeBenchmark() : _config(), _rndGen() {}
+ ~AttributeBenchmark() = default;
int main(int argc, char **argv);
};
@@ -268,7 +263,7 @@ AttributeBenchmark::benchmarkSearch(const AttributePtr & ptr, const std::vector<
} else {
searchers.push_back(new AttributeFindSearcher<T>(ptr, values, _config._numQueries));
}
- _threadPool->NewThread(searchers.back());
+ searchers.back()->start();
}
for (uint32_t i = 0; i < searchers.size(); ++i) {
@@ -299,7 +294,7 @@ AttributeBenchmark::benchmarkSearchWithUpdater(const AttributePtr & ptr,
AttributeUpdaterThread<Vector, T, BT>
updater(ptr, values, _rndGen, _config._validate, _config._commitFreq,
_config._minValueCount, _config._maxValueCount);
- _threadPool->NewThread(&updater);
+ updater.start();
benchmarkSearch(ptr, values);
updater.stop();
updater.join();
@@ -337,8 +332,6 @@ AttributeBenchmark::benchmarkAttribute(const AttributePtr & ptr, const std::vect
} else {
benchmarkSearchWithUpdater<Vector, T, BT>(ptr, values);
}
-
- _threadPool->Close();
}
@@ -569,8 +562,6 @@ AttributeBenchmark::main(int argc, char **argv)
dc._attribute = vespalib::string(argv[optind]);
- _threadPool = new FastOS_ThreadPool();
-
std::cout << "<attribute-benchmark>" << std::endl;
init(dc);
_config.printXML();
diff --git a/searchlib/src/tests/attribute/benchmark/attributesearcher.h b/searchlib/src/tests/attribute/benchmark/attributesearcher.h
index d6e14d6793d..ea2d7190f25 100644
--- a/searchlib/src/tests/attribute/benchmark/attributesearcher.h
+++ b/searchlib/src/tests/attribute/benchmark/attributesearcher.h
@@ -2,7 +2,6 @@
#pragma once
-#include <vespa/searchlib/util/runnable.h>
#include <vespa/searchlib/attribute/attribute.h>
#include <vespa/searchlib/attribute/attributeguard.h>
#include <vespa/searchlib/attribute/search_context.h>
@@ -59,7 +58,7 @@ public:
};
-class AttributeSearcher : public Runnable
+class AttributeSearcher
{
protected:
using AttributePtr = AttributeVector::SP;
@@ -67,17 +66,23 @@ protected:
const AttributePtr & _attrPtr;
vespalib::Timer _timer;
AttributeSearcherStatus _status;
-
+ std::thread _thread;
+
public:
- AttributeSearcher(const AttributePtr & attrPtr) :
- Runnable(), _attrPtr(attrPtr), _timer(), _status()
+ AttributeSearcher(const AttributePtr & attrPtr)
+ : _attrPtr(attrPtr), _timer(), _status(), _thread()
{
_status._numClients = 1;
}
- virtual void doRun() override = 0;
+ virtual ~AttributeSearcher();
+ virtual void doRun() = 0;
+ void start() { _thread = std::thread([this](){doRun();}); }
+ void join() { _thread.join(); }
AttributeSearcherStatus & getStatus() { return _status; }
void buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const char * term, bool prefix = false);
};
+AttributeSearcher::~AttributeSearcher() = default;
+
void
AttributeSearcher::buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const char * term, bool prefix)
diff --git a/searchlib/src/tests/attribute/benchmark/attributeupdater.h b/searchlib/src/tests/attribute/benchmark/attributeupdater.h
index 88220a8cfb8..ada9c423cd1 100644
--- a/searchlib/src/tests/attribute/benchmark/attributeupdater.h
+++ b/searchlib/src/tests/attribute/benchmark/attributeupdater.h
@@ -4,7 +4,6 @@
#include <vespa/vespalib/util/hdr_abort.h>
#include <vespa/searchlib/util/randomgenerator.h>
-#include <vespa/searchlib/util/runnable.h>
#include <vespa/searchlib/attribute/attribute.h>
#define VALIDATOR_STR(str) #str
@@ -153,26 +152,30 @@ template <typename Vector, typename T, typename BT>
AttributeUpdater<Vector, T, BT>::~AttributeUpdater() = default;
template <typename Vector, typename T, typename BT>
-class AttributeUpdaterThread : public AttributeUpdater<Vector, T, BT>, public Runnable
+class AttributeUpdaterThread : public AttributeUpdater<Vector, T, BT>
{
private:
using AttributePtr = AttributeVector::SP;
-
+ std::atomic<bool> _done;
+ std::thread _thread;
public:
AttributeUpdaterThread(const AttributePtr & attrPtr, const std::vector<T> & values,
RandomGenerator & rndGen, bool validate, uint32_t commitFreq,
uint32_t minValueCount, uint32_t maxValueCount);
~AttributeUpdaterThread();
-
- virtual void doRun() override;
+ void doRun();
+ void start() { _thread = std::thread([this](){doRun();}); }
+ void stop() { _done = true; }
+ void join() { _thread.join(); }
};
template <typename Vector, typename T, typename BT>
AttributeUpdaterThread<Vector, T, BT>::AttributeUpdaterThread(const AttributePtr & attrPtr, const std::vector<T> & values,
RandomGenerator & rndGen, bool validate, uint32_t commitFreq,
uint32_t minValueCount, uint32_t maxValueCount)
- : AttributeUpdater<Vector, T, BT>(attrPtr, values, rndGen, validate, commitFreq, minValueCount, maxValueCount),
- Runnable()
+ : AttributeUpdater<Vector, T, BT>(attrPtr, values, rndGen, validate, commitFreq, minValueCount, maxValueCount),
+ _done(false),
+ _thread()
{}
template <typename Vector, typename T, typename BT>
AttributeUpdaterThread<Vector, T, BT>::~AttributeUpdaterThread() = default;