Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[core, offline] Limit offline downloads to use half of maximum concurrent file requests. - #12910

Closed
ChrisLoer wants to merge 1 commit into
masterfrom
offline-concurrency
Closed

ChrisLoer wants to merge 1 commit into
masterfrom
offline-concurrency

Conversation

@ChrisLoer

Copy link
Copy Markdown
Contributor

Fixes issue #12655: don't let offline downloads starve interactive tile downloads.

I started to look at implementing a dual-priority queue in OnlineFileSource, and I don't think it would be too hard to do. But as I was looking at the code, I realized that OfflineDownload already limits the number of concurrent requests it makes. Setting that concurrent request limit to something less than the maximum number of concurrent requests in OnlineFileSource ensures that there will always be some spots open for interactive downloads. I arbitrarily chose 50% (or 10 concurrent downloads given our current implementations) and played around with browsing tiles while simultaneously doing offline downloads in the macosapp -- seemed to work fine.

The downside to this dead-simple approach is that the offline downloads are in some sense "throttled" even when there are no interactive tile requests, but I'm not sure it's a significant concern in practice: my guess would be that 10 concurrent requests is still enough to saturate most network connections.

/cc @tobrun @kkaefer @lilykaiser

…rent file requests.

Fixes issue #12655: don't let offline downloads starve interactive tile downloads.
@ChrisLoer
ChrisLoer requested a review from kkaefer September 18, 2018 22:17
@friedbunny friedbunny added performance Speed, stability, CPU usage, memory usage, or power usage Core The cross-platform C++ core, aka mbgl needs changelog Indicates PR needs a changelog entry prior to merging. labels Sep 18, 2018
@tobrun

tobrun commented Sep 19, 2018

Copy link
Copy Markdown
Member

Took this PR for a spin: for every run I did a clean install of the app:

Type run Before Now
offline download 15755 ms 19067 ms
offline download + active map 25787 ms 37964 ms

Above numbers should be taken with a grain of salt as these are singular runs but the trend is that this PR makes offline downloads significantly slower. Happy to do more thorough benchmarking if needed.

@kkaefer

kkaefer commented Sep 19, 2018

Copy link
Copy Markdown
Member

I'm not convinced that this is a correct solution for this problem. What kind of testing did you do to verify that this solves the underlying issue? Apart from manual testing, it'd also be cool to try to reproduce this with an automated test. Granted, it could be tricky since it's timing dependent, but maybe we could use a mock Online/HTTPFileSource that simulates this behavior?

@ChrisLoer

Copy link
Copy Markdown
Contributor Author

Oops! I just saw that I never submitted the comment below from two weeks ago! TLDR: yeah, let's try a different approach.

@tobrun's quick benchmarking definitely seems to contradict my "10 concurrent connections oughta be plenty" hypothesis, so yeah, this approach probably doesn't make sense (although we could try a higher number still short of 20, I get that we don't really want a solution that "doesn't slow us down that much").

Apart from manual testing, it'd also be cool to try to reproduce this with an automated test. Granted, it could be tricky since it's timing dependent, but maybe we could use a mock Online/HTTPFileSource that simulates this behavior?

Just watching what happened in the debugger, this didn't look like a super-complicated situation to me, although maybe I'm missing something? It's just that the callback that OnlineFileSource passes to HTTPFileSource can feed through to the OfflineDownload completion handler and queue more requests before it gets to the activatePendingRequests line:

auto callback = [=](Response response) {
activeRequests.erase(request);
request->request.reset();
request->completed(response);
activatePendingRequest();
};

cc @chaupow

@ChrisLoer ChrisLoer closed this Oct 4, 2018
@friedbunny friedbunny removed needs changelog Indicates PR needs a changelog entry prior to merging. labels Oct 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Core The cross-platform C++ core, aka mbgl performance Speed, stability, CPU usage, memory usage, or power usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants