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

Set etag on pmtiles serve responses #137

Merged
merged 9 commits into from
Feb 13, 2024
Merged

Conversation

msbarry
Copy link
Contributor

@msbarry msbarry commented Feb 10, 2024

Set etag on tile, metadata, and tilejson responses. By default it uses the etag from the archive but you can opt into computing an etag per-resource with --tile-etag flag. The default archive etag behavior minimizes runtime overhead and is guaranteed to return a new etag when tile contents changes, but also ends up changing the etag (and purging intermediate caches) when the archive changes but an individual tile is the same between old and new archive.

This also implements If-Match and If-None-Match header handling by using go's built-in http.ServeContent utility. As a side effect this also means that pmtiles serve now supports range requests within individual tiles.

main.go Outdated
@@ -88,6 +89,7 @@ var cli struct {
CacheSize int `default:"64" help:"Size of cache in Megabytes."`
Bucket string `help:"Remote bucket"`
PublicURL string `help:"Public base URL of tile endpoint for TileJSON e.g. https://example.com/tiles/"`
TileEtag bool `help:"Generate etag for each tile instead of using archive etag"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I implemented this it also applies to metadata json and tilejson responses. Should I remove those? Or make this --resource-etag? or just leave it as-is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also in my tests on a 32-core machine enabling this reduces throughput from 40k tiles per second to 36k tiles per second.

Copy link
Member

Choose a reason for hiding this comment

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

maybe --unique-etags instead, to make it clearer the effect?

caddy/pmtiles_proxy.go Outdated Show resolved Hide resolved
@@ -294,6 +296,7 @@ func (server *Server) getTileJSON(ctx context.Context, httpHeaders map[string]st
}

httpHeaders["Content-Type"] = "application/json"
httpHeaders["Etag"] = generateEtag(tilejsonBytes)
Copy link
Member

Choose a reason for hiding this comment

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

I think the end result is case-insensitive but the capitalization convention seems to be ETag with a capital T, any objections to changing it to that?

@bdon bdon merged commit 800168b into protomaps:main Feb 13, 2024
4 of 5 checks passed
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