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

Enhance valhalla_build_elevation with LZ4 recompression support #3607

Merged
merged 6 commits into from
May 2, 2022

Conversation

ianthetechie
Copy link
Contributor

@ianthetechie ianthetechie commented Apr 30, 2022

Issue

Closes #3606.

Tasklist

  • Add tests - I don't see applicable tests for similar download portions of the script; let me know if you want a test
  • Add #fixes with the issue number that this PR addresses
  • Update the docs with any new request parameters or changes to behavior described
  • Update the changelog
  • If you made changes to the lua files, update the taginfo too. - N/A

Requirements / Relations

Complementary to #3401.

Commentary

The main goal of this PR is to add support for re-compressing downloaded elevation tiles as LZ4. LZ4 comes at a slight space cost (roughly 12% larger than gzip for the planet) and of course the upfront CPU cost of recompressing. In real-world request loads, we have observed significant reductions in p95 and higher response times after switching from gzip to LZ4 elevation tiles.

Secondarily, this PR makes a subtle type change from a boolean decompress flag to explicitly supporting multiple compression types in case something better comes along later. This also ensures the added cases are cleanly handled. It also removes the requirement for a JSON config file. While a JSON config file is probably the more typical usage pattern, it's also useful to be able to specify a bbox and output directory on the command line directly when downloading the whole world to a local file server or similar applications (and it technically doesn't even have to be Valhalla-specific).

Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

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

thanks, makes sense! just a few minor things.

scripts/valhalla_build_elevation Outdated Show resolved Hide resolved
scripts/valhalla_build_elevation Show resolved Hide resolved
scripts/valhalla_build_elevation Outdated Show resolved Hide resolved
Comment on lines +304 to +305
elif config is not None:
elevation_fp = Path(config["additional_data"]["elevation"] or "elevation")
Copy link
Member

Choose a reason for hiding this comment

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

this is not quite enough to make config optional as it's also used further down when the user wants to get tiles covering the graph (often the most sensible option IMO in case elevation is only used to enrich the graph, not the /height service). admittedly there was no exception handling in place before either, config wasn't even required.

guess it's enough to protect line 315 from missing config path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I should point out the motivation for touching this as well. While the normal case would have a Valhalla JSON config, I think it's generally useful to have an option to run this script without that context, such as to download the whole planet elevation data to an internal file server. This is probably a minority use case, but I think it's useful to be able to operate as the previous shell script without a JSON config.

That said, good call. I neglected the possible code path on line 315. Any objection to checking that config is not none, exiting if it's not, and updating docs? This might be possible in argparse, but I don't know a great way off the top of my head.

Copy link
Member

Choose a reason for hiding this comment

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

yeah I figured so, should've commented that I thought it's a valid use case, now the script can be used independently of valhalla. just get it from github's raw endpoint and execute it to get some bbox's tilezen tiles, that's great. would you mind adding some notes about that to the PR description for future reference?

Any objection to checking that config is not none, exiting if it's not, and updating docs

that's what I had in mind too:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing; I'll update the PR description.

@nilsnolde nilsnolde self-requested a review April 30, 2022 13:14
nilsnolde
nilsnolde previously approved these changes Apr 30, 2022
@nilsnolde nilsnolde self-requested a review April 30, 2022 13:32
Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

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

thanks for the time and effort @ianthetechie !

@nilsnolde nilsnolde merged commit 1cb73d4 into valhalla:master May 2, 2022
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.

Add support for LZ4 recompression in valhalla_build_elevation
2 participants