From baf95da93aa895d60325b49fb8860f0b4615fcee Mon Sep 17 00:00:00 2001 From: Automatic Release Builder Date: Wed, 7 Oct 2020 12:23:33 +0100 Subject: [PATCH] TerraSync: Rate-limit hash-cache writes This helps with IO-limited performance on Windows --- simgear/io/HTTPRepository.cxx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/simgear/io/HTTPRepository.cxx b/simgear/io/HTTPRepository.cxx index 0b3781a9..757e6578 100644 --- a/simgear/io/HTTPRepository.cxx +++ b/simgear/io/HTTPRepository.cxx @@ -111,7 +111,7 @@ public: typedef std::vector HashCache; HashCache hashes; - bool hashCacheDirty; + int hashCacheDirty = 0; struct Failure { @@ -123,7 +123,6 @@ public: FailureList failures; HTTPRepoPrivate(HTTPRepository* parent) : - hashCacheDirty(false), p(parent), isUpdating(false), status(HTTPRepository::REPO_NO_ERROR), @@ -1084,10 +1083,10 @@ HTTPRepository::failure() const void HTTPRepoPrivate::updatedFileContents(const SGPath& p, const std::string& newHash) { // remove the existing entry - HashCache::iterator it = std::find_if(hashes.begin(), hashes.end(), HashEntryWithPath(p)); + auto it = std::find_if(hashes.begin(), hashes.end(), HashEntryWithPath(p)); if (it != hashes.end()) { hashes.erase(it); - hashCacheDirty = true; + ++hashCacheDirty; } if (newHash.empty()) { @@ -1106,12 +1105,12 @@ HTTPRepository::failure() const entry.lengthBytes = p2.sizeInBytes(); hashes.push_back(entry); - hashCacheDirty = true; + ++hashCacheDirty ; } void HTTPRepoPrivate::writeHashCache() { - if (!hashCacheDirty) { + if (hashCacheDirty == 0) { return; } @@ -1124,7 +1123,7 @@ HTTPRepository::failure() const << it->lengthBytes << "*" << it->hashHex << "\n"; } stream.close(); - hashCacheDirty = false; + hashCacheDirty = 0; } void HTTPRepoPrivate::parseHashCache() @@ -1238,10 +1237,16 @@ HTTPRepository::failure() const http->makeRequest(rr); } - writeHashCache(); + // rate limit how often we write this, since otherwise + // it dominates the time on Windows. 256 seems about right, + // causes a write a few times a minute. + if (hashCacheDirty > 256) { + writeHashCache(); + } if (activeRequests.empty() && queuedRequests.empty()) { isUpdating = false; + writeHashCache(); } }