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

Fastly soft purge tiles based on diff updates #947

Open
Firefishy opened this issue Sep 1, 2023 · 7 comments
Open

Fastly soft purge tiles based on diff updates #947

Firefishy opened this issue Sep 1, 2023 · 7 comments
Labels
service:tiles The raster map on tile.openstreetmap.org

Comments

@Firefishy
Copy link
Member

Fastly supports soft purging which can be used to tell Fastly that a URL is stale and should be refreshed. The stale cache will still be used if the upstream is unavailable.

As part of the osm2pgsql diff import step a list of tiles to invalidate should be created. osm2pgsql has a native implementation of generating the list of tiles to expire.

Potentially the list of expired files should be added to a queue which is then asynchronously soft purged at fastly.

@Firefishy Firefishy added service:tiles The raster map on tile.openstreetmap.org help-wanted Issues where help is needed to implement them labels Sep 1, 2023
@Firefishy
Copy link
Member Author

If the soft purging could be implemented then we could allow fastly to cache tiles for significantly longer eg:

Cache-Control: public, max-age=86400 # 1 hour - browsers
Surrogate-Control: max-age=2592000 # 30 days - fastly, header dropped to client

@tomhughes
Copy link
Member

Note that we don't use osm2pgql's expiry list but instead our own simpler one.

@Firefishy
Copy link
Member Author

A quick hacky of a script to submit URLs into a redis queue: https://gist.github.com/Firefishy/58a250759b29638d3c2e6842fb2ea5aa

and a hacky script to submit the purge requests from queue (likely should be async submit): https://gist.github.com/Firefishy/c890afbbb2bd67649f7ab244880dbf07

@Firefishy
Copy link
Member Author

Note that we don't use osm2pgql's expiry list but instead our own simpler one.

Here is the current expiry implementation which is focused at metatile expiry: https://github.com/openstreetmap/chef/blob/master/cookbooks/tile/files/default/bin/expire-tiles-single

@Firefishy
Copy link
Member Author

The Fastly API rate limit documentation:

Single-URL and surrogate key purges: limited to an average of 100,000 purges per customer per hour. https://developer.fastly.com/reference/api/#rate-limiting

Purging purely based on metatiles is within the realms of possibility at 1666 metatiles per minute.

@pnorman
Copy link
Collaborator

pnorman commented Sep 1, 2023

We need to identify how many purge requests per second we'll be sending, as Fastly rate limits it to 1666/minute per customer, and we should be well below that.

Frequent purges are generally a design flaw when using a CDN.

@Firefishy
Copy link
Member Author

I am proposing we use a queue (redis?), we can define the rate at which we process the queue. We could monitor queue length / queue time.

Since openstreetmap/chef@edb9dbc we now collect the data to inform the estimation.

@pnorman pnorman removed the help-wanted Issues where help is needed to implement them label Oct 6, 2023
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

3 participants