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

Review cache headers served by render servers #959

Open
tomhughes opened this issue Sep 22, 2023 · 5 comments
Open

Review cache headers served by render servers #959

tomhughes opened this issue Sep 22, 2023 · 5 comments
Labels
service:tiles The raster map on tile.openstreetmap.org

Comments

@tomhughes
Copy link
Member

We want to review the cache related headers served by the render servers to make sure we're getting the best out of our frontend caches.

Currently the only such headers mod_tile adds are Expires and Cache-Control: max-age both of which report the same expiry time though in different way.

The core of it's algorithm is to take the current age of the tile and multiple that by ModTileCacheLastModifiedFactor which we have configured as 0.2 currently, so a tile that is five days old will have an expiry of one day and a tile that is thirty days old will have an expiry of six days.

It does also clamp the expiry to be no more that ModTileCacheDurationMax which is seven days in our configuration, and clamps the minimum expiry in three buckets:

  • A low zoom bucket configured using ModTileCacheDurationLowZoom which is 6 days for us and covers zoom 0 to 9
  • A medium zoom bucket configured using ModTileCacheDurationMediumZoom which is 1 day for us and covers zoom 10 to 13
  • A high zoom bucket configured using ModTileCacheDurationMinimum which is 3 hours for us and covers zoom 14 to 19

Some random jitter (up to 3 hours) is also added.

Tiles which are known to be dirty when served are given a randomised expiry up to ModTileCacheDurationDirty which we have as 15 minutes.

@tomhughes tomhughes added the service:tiles The raster map on tile.openstreetmap.org label Sep 22, 2023
@pnorman
Copy link
Collaborator

pnorman commented Sep 23, 2023

Because we know when low zoom tiles will be next rerendered, we should override z0-12 to be a couple hours after the weekly rerender completes.

@Firefishy
Copy link
Member

Header Value TBC 1 TBC 2 TBC 3
etag "d4ffa790e405f161c794639c86f84e7f"
cache-control max-age=17265, stale-while-revalidate=604800, stale-if-error=604800
expires Fri, 29 Dec 2023 20:35:47 GMT
x-tilerender nidhogg.openstreetmap.org
content-type image/png
accept-ranges bytes
date Fri, 29 Dec 2023 15:48:45 GMT
age 44
x-served-by cache-lcy-eglc8600053-LCY
x-cache HIT
x-cache-hits 1
content-length 19647

@tomhughes
Copy link
Member Author

Unfortunately mod_tile doesn't provide a way to set a fixed expiry and as it also doesn't set the Last-Modified header there's no way to have apache override it to last modified + one day for low zoom tiles :-(

@pnorman
Copy link
Collaborator

pnorman commented Dec 29, 2023

Last-Modified is probably the first thing to get working, so we need mod_tile changes.

@hummeltech
Copy link

hummeltech commented Feb 19, 2024

It appears that Last-Modified headers were removed here when the ETag header was "fixed" to be the md5sum of the tile rather than the metatile.

I can't think of any reason not to re-enable these two lines:
https://github.com/openstreetmap/mod_tile/blob/007fee044cffbbe35fdeac4167f8c5bd4379596e/mod_tile.c#L521-L522

Of course, it will only provide useful information for storage backends which support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service:tiles The raster map on tile.openstreetmap.org
Projects
None yet
Development

No branches or pull requests

4 participants