diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-24 18:10:14 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-24 18:10:14 +0000 |
commit | 17b3e101697673cf814f20103064f295c440bcaf (patch) | |
tree | 4cbb174f032387f248ba9c50ef46ed824089568d | |
parent | 25f41d6c5fd105b47d9f0d0c1642f25fd9ac8795 (diff) |
Allow faster shutdown by using more threads.
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/server/proton.cpp | 23 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/server/proton.h | 1 |
2 files changed, 20 insertions, 4 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index 09e5a64185a..2f3fe34873e 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -29,6 +29,7 @@ #include <vespa/document/repo/documenttyperepo.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <vespa/vespalib/util/host_name.h> #include <vespa/vespalib/util/random.h> #include <vespa/searchlib/engine/transportserver.h> @@ -44,6 +45,7 @@ using document::DocumentTypeRepo; using vespalib::FileHeader; using vespalib::IllegalStateException; using vespalib::Slime; +using vespalib::makeLambdaTask; using vespalib::slime::ArrayInserter; using vespalib::slime::Cursor; @@ -432,10 +434,9 @@ Proton::~Proton() if (_fs4Server) { _fs4Server->shutDown(); } - while (!_documentDBMap.empty()) { - const DocTypeName docTypeName(_documentDBMap.begin()->first); - removeDocumentDB(docTypeName); - } + size_t numCores = std::max(1u, std::thread::hardware_concurrency()); + vespalib::ThreadStackExecutor closePool(std::min(_documentDBMap.size(), numCores), 0x20000); + closeDocumentDBs(closePool); _documentDBMap.clear(); _persistenceEngine.reset(); _tls.reset(); @@ -445,6 +446,20 @@ Proton::~Proton() LOG(debug, "Explicit destructor done"); } +void +Proton::closeDocumentDBs(vespalib::ThreadStackExecutorBase & executor) { + // Need to extract names first as _documentDBMap is modified while removing. + std::vector<DocTypeName> docTypes; + docTypes.reserve(_documentDBMap.size()); + for (const auto & entry : _documentDBMap) { + docTypes.push_back(entry.first); + } + for (const auto & docTypeName : docTypes) { + executor.execute(makeLambdaTask([this, docTypeName]() { removeDocumentDB(docTypeName); })); + } + executor.sync(); +} + size_t Proton::getNumDocs() const { size_t numDocs(0); diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.h b/searchcore/src/vespa/searchcore/proton/server/proton.h index 7dd4630360a..39e32c7f504 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.h +++ b/searchcore/src/vespa/searchcore/proton/server/proton.h @@ -154,6 +154,7 @@ private: BootstrapConfig::SP getActiveConfigSnapshot() const; std::shared_ptr<IDocumentDBReferenceRegistry> getDocumentDBReferenceRegistry() const override; bool updateNodeUp(BucketSpace bucketSpace, bool nodeUpInBucketSpace); + void closeDocumentDBs(vespalib::ThreadStackExecutorBase & executor); public: typedef std::unique_ptr<Proton> UP; typedef std::shared_ptr<Proton> SP; |