Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simultaneous HTTP downloads #121

Merged
merged 57 commits into from
Jan 19, 2024
Merged

Simultaneous HTTP downloads #121

merged 57 commits into from
Jan 19, 2024

Conversation

podusowski
Copy link
Owner

@podusowski podusowski commented Jan 14, 2024

It's a quite big PR, because I really wanted to test simultaneous downloads, especially that we don't start more than two. Unfortunately, neither mockito, nor any other HTTP mocking library seems to have an option to deffer responding to incoming HTTP request. So I've written a new one. :)

@podusowski podusowski changed the title Simultaneous HTTP downloads Draft: Simultaneous HTTP downloads Jan 14, 2024
@podusowski podusowski marked this pull request as draft January 14, 2024 11:50
@podusowski podusowski changed the title Draft: Simultaneous HTTP downloads Simultaneous HTTP downloads Jan 14, 2024
let request = request_rx.next().await.ok_or(())?;
let url = source.tile_url(request);
let request = request_rx.next();
let below_concurrent_downloads_limit = ongoing_downloads.len() < 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really limit the connections?
In my world, one Client == one connection.
For http2 (tile.openstreetmaps.org supports multiplexing) this looks like obstacle.

Maybe better to have two client workers (to restrict number of connections) and limit download queue by any reasonable value (like a half of number of tiles on display)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my world, one Client == one connection.

Well, this does make sense, and initially I started with two clients, but then I noticed that with one it works too. And if test test is correct, this indeed creates two connections.

I did not consider HTTP/2 (test uses HTTP/1). OSM says:

Maximum of 2 download connections.

and I do not know if this translates to 2 HTTP/2 streams or not. I have a gut feeling that it does though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a gut feeling that it does though.

I think different because http/2 streams not require system resources (like port), and they not leave many zombie-connections (in state CLOSE_WAIT).

I think we can forget about http/1 because osm.org uses http2. This can be checked using this site: https://tools.keycdn.com/http2-test or curl:

curl -v -v -v https://tile.openstreetmap.org/18/187598/121559.png -o /dev/null 2>&1 | grep -i http2
* Using HTTP2, server supports multiplexing

About testing many connections in current way:
TCP sockets take to change status: so far first client will idle in state CLOSING/FIN_WAIT/CLOSE_WAIT, next client will download the tile. Next, the roles will change and server always assume that more are connected to him if I understand correctly how TCP works.

Copy link
Contributor

@noktoborus noktoborus Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
watch -n 1 "bash -c 'netstat -aptun| grep target'"
says what only one stable connection is used in multi-download branch

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I guess I need to do more thinking on this. In the meanwhile, I have checked how Leaflet does this. I've disabled both HTTP/2 and HTTP/3.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like 6 connections in parallel

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems consistent with the statement over here: seanmonstar/reqwest#1517 (comment)

Well then, the approach I've taken is completely wrong. This limit needs to be enforced by reqwest/hyper, not here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar result: 6 permanent connections to tile.osm.org (151.101.*.*) and 6 parallel downloads

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the limit to 6 seems to give pretty pleasing experience. If reqwest can do http/2 (which I believe it can), it should use a single connection anyway, so it should meet the OSM rules.

@@ -0,0 +1,17 @@
[package]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to get rid of Mockito, and use this crate instead. Once it can handle all Walkers' use cases, I will create a new repo for it.

@podusowski podusowski marked this pull request as ready for review January 19, 2024 21:10
@podusowski podusowski merged commit 039b52f into main Jan 19, 2024
1 check passed
@podusowski podusowski deleted the multi-download branch January 19, 2024 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants