From 368ee1bdfb315b1ec47a7123618a9074f6865b7b Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Tue, 18 Sep 2018 15:06:40 -0700 Subject: [core, offline] Limit offline downloads to use half of maximum concurrent file requests. Fixes issue #12655: don't let offline downloads starve interactive tile downloads. --- platform/default/mbgl/storage/offline_download.cpp | 5 +++-- platform/default/mbgl/storage/offline_download.hpp | 2 ++ test/storage/offline_download.test.cpp | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp index 17af0abf3c..db2ea7122f 100644 --- a/platform/default/mbgl/storage/offline_download.cpp +++ b/platform/default/mbgl/storage/offline_download.cpp @@ -88,7 +88,8 @@ OfflineDownload::OfflineDownload(int64_t id_, : id(id_), definition(definition_), offlineDatabase(offlineDatabase_), - onlineFileSource(onlineFileSource_) { + onlineFileSource(onlineFileSource_), + maximumConcurrentRequests(std::max(HTTPFileSource::maximumConcurrentRequests() / 2, 1)) { setObserver(nullptr); } @@ -340,7 +341,7 @@ void OfflineDownload::continueDownload() { return; } - while (!resourcesRemaining.empty() && requests.size() < HTTPFileSource::maximumConcurrentRequests()) { + while (!resourcesRemaining.empty() && requests.size() < maximumConcurrentRequests) { ensureResource(resourcesRemaining.front()); resourcesRemaining.pop_front(); } diff --git a/platform/default/mbgl/storage/offline_download.hpp b/platform/default/mbgl/storage/offline_download.hpp index cffac1665b..eec48dd985 100644 --- a/platform/default/mbgl/storage/offline_download.hpp +++ b/platform/default/mbgl/storage/offline_download.hpp @@ -63,6 +63,8 @@ private: void queueResource(Resource); void queueTiles(style::SourceType, uint16_t tileSize, const Tileset&); + + uint32_t maximumConcurrentRequests; }; } // namespace mbgl diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp index 5fc0e752df..677cb3acfc 100644 --- a/test/storage/offline_download.test.cpp +++ b/test/storage/offline_download.test.cpp @@ -297,7 +297,7 @@ TEST(OfflineDownload, DoesNotFloodTheFileSourceWithRequests) { fileSource.respond(Resource::Kind::Style, test.response("style.json")); test.loop.runOnce(); - EXPECT_EQ(HTTPFileSource::maximumConcurrentRequests(), fileSource.requests.size()); + EXPECT_EQ(std::max(HTTPFileSource::maximumConcurrentRequests() / 2, 1), fileSource.requests.size()); } TEST(OfflineDownload, GetStatusNoResources) { -- cgit v1.2.1