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

server: gzip encoding of tiles #438

Closed
mojodna opened this issue Jun 26, 2018 · 4 comments
Closed

server: gzip encoding of tiles #438

mojodna opened this issue Jun 26, 2018 · 4 comments
Assignees
Milestone

Comments

@mojodna
Copy link
Contributor

mojodna commented Jun 26, 2018

When requesting tiles with an Accept-Encoding: gzip header, I would expect Tegola to respond with gzipped tiles (and a Content-Encoding: gzip header) to reduce the amount of data transferred.

However, they don't appear to be gzipped:

$ curl -H "Accept-Encoding: gzip" -O http://localhost:8080/maps/borders/11/328/792.pbf
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9785    0  9785    0     0  10526      0 --:--:-- --:--:-- --:--:-- 10521
$ file 792.pbf
792.pbf: data

Is the intent for Tegola to run behind a reverse proxy that handles gzipping?

@ARolek
Copy link
Member

ARolek commented Jun 28, 2018

@mojodna the pbf files are already zig zag encoded so I don't know how much of a win gzipping will add, but we can easily add support for handling the Accept-Encoding header appropriately. Have you tried gzipping a pbf tile from tegola by chance?

@mojodna
Copy link
Contributor Author

mojodna commented Jun 28, 2018

Gzipping makes a pretty big difference. This tile went from 512K to 125K:

5_4_11.pbf.gz

@ARolek
Copy link
Member

ARolek commented Jun 28, 2018

Well that's pretty significant. I will work on getting it implemented.

@ARolek ARolek self-assigned this Jun 28, 2018
@ARolek ARolek changed the title Gzip encoding of tiles? server: gzip encoding of tiles Jul 28, 2018
@pnorman
Copy link
Contributor

pnorman commented Aug 7, 2018

I wrote this up as a new issue, but found this issue already about it.

When MVTs were designed, gzipping was intended. This allows use of gzip's property that gzip(file 1 + file 2) = gzip(file 1) + gzip(file 2), and the ability to concatanate multiple layers with MVTs.

Mapbox's implementations of consumers and servers assumed that browsers would always request compressed data, server-side software would always process compressed data, and servers would always send compressed data. This assumption was so strong their servers sent compressed data to clients which explicitly said only identity compression was acceptable.

Tegola should

  1. Compress data before saving it to the cache. The compression level should be adjustable.

  2. Send the compressed data directly from cache to clients that send an Accept-Encoding accepting gzip, *, or no Accept-Encoding header. Content-Encoding: gzip should also be set.

  3. For Accept-Encoding headers which have gzip;q=0 or *;q=0 without gzip appearing elsewhere or an Accept-Encoding header that is empty, either decompress on the fly to send an identity encoded response, with no Accept-Encoding; or return a 406 error. If on-demand decompression is allowed, there should be a way to disable this in configuration or an environment variable for those who don't want to support it.

I'm not sure what this means for setting the Vary header.


Looking at the tiles I'm generating, this would reduce the size from 36MB to 7.6MB of what I get with tegola cache seed --map bolder --min-zoom 0 --max-zoom 14 --bounds "-123.41,49.03,-122.47,49.83". It takes about 4m to generate the tiles, and under 1.2s to compress them with gzip -k -3 -S .3.gz -r. The on-disk savings are less significant because of minimum block sizes, but the data transferred to the

@ARolek ARolek added this to the v0.8.0 milestone Sep 7, 2018
ARolek added a commit that referenced this issue Sep 8, 2018
implements gzip compression on successful responses
when the Accept-Encoding header is properly set.

When leveraging a cache back end for caching tiles
the tile data will be compressed prior to writing
to the cache.

If an incoming request does not support gzip compression
the response data will be decompressed prior to responding.

NOTE: this commit will break all current caches! It's critical
that all caches be purged and rebuilt!
ARolek added a commit that referenced this issue Sep 12, 2018
- updated cache/s3 tests
- fixed issue with tiles being decompressed
when fetched from s3.
ARolek added a commit that referenced this issue Sep 13, 2018
ARolek added a commit that referenced this issue Sep 15, 2018
gzip compression support #438

implements gzip compression on successful responses
when the Accept-Encoding header is properly set.

When leveraging a cache back end for caching tiles
the tile data will be compressed prior to writing
to the cache.

If an incoming request does not support gzip compression
the response data will be decompressed prior to responding.

NOTE: this commit will break all current caches! It's critical
that all caches be purged and rebuilt!
@ARolek ARolek closed this as completed Sep 15, 2018
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

No branches or pull requests

3 participants