summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2018-09-18 15:06:40 -0700
committerChris Loer <chris.loer@gmail.com>2018-09-18 15:06:40 -0700
commitaaf73b44f13b3b50ccd1c7779ca3cc64b80fcbf4 (patch)
treed9e65bb806bf8041714e82e7f62dee89ff616dac
parenta938c3ef68af249bb3199bde2818436a0bff0952 (diff)
downloadqtlocation-mapboxgl-upstream/offline-concurrency.tar.gz
[core, offline] Limit offline downloads to use half of maximum concurrent file requests.upstream/offline-concurrency
Fixes issue #12655: don't let offline downloads starve interactive tile downloads.
-rw-r--r--platform/default/mbgl/storage/offline_download.cpp5
-rw-r--r--platform/default/mbgl/storage/offline_download.hpp2
-rw-r--r--test/storage/offline_download.test.cpp2
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 118f3aad88..da53271bd4 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<uint32_t>(HTTPFileSource::maximumConcurrentRequests() / 2, 1)) {
setObserver(nullptr);
}
@@ -338,7 +339,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 492e68e869..f0df5db32c 100644
--- a/test/storage/offline_download.test.cpp
+++ b/test/storage/offline_download.test.cpp
@@ -295,7 +295,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<uint32_t>(HTTPFileSource::maximumConcurrentRequests() / 2, 1), fileSource.requests.size());
}
TEST(OfflineDownload, GetStatusNoResources) {