build
build copied to clipboard
Redesign Cloudflare cache purging
I believe most of the server issues we're currently having with nodejs.org stem from our rather crude "purge everything" strategy. This is currently done by ansible/www-standalone/resources/scripts/cdn-purge.sh.j2 (which runs every five minutes) if a purge has been locally queued.
Purges are queued by calling ansible/www-standalone/resources/scripts/queue-cdn-purge.sh. This is done every time:
- the website is rebuilt https://github.com/nodejs/build/blob/322121334e8344daf7520d405239597f6505662f/ansible/www-standalone/resources/scripts/build-site.sh#L61. This also includes when the website index HTML page is detected as being older than
index.jsonwhich triggers a website rebuild (I believe this is so the website picks up the most recent current and LTS releases for the download buttons/pages) https://github.com/nodejs/build/blob/322121334e8344daf7520d405239597f6505662f/ansible/www-standalone/resources/scripts/check-build-site.sh#L16 - a release is promoted (during shasum creation) https://github.com/nodejs/build/blob/322121334e8344daf7520d405239597f6505662f/ansible/www-standalone/tools/promote/resha_release.sh#L28
- a build (e.g. nightly/V8 canary/release) is promoted https://github.com/nodejs/build/blob/322121334e8344daf7520d405239597f6505662f/ansible/www-standalone/tools/promote/_promote.sh#L61. Note that nightly/V8 canary builds get promoted every 30 mins which may mean an iojs+release build can have multiple promotions depending on when the sub-builds complete and upload their assets to staging.
To give an idea of frequency, these are the cdn-purges from today (including the Node.js 20.4.0 release):
2023-07-05T06:35:01+00:00, nodejs, promote
2023-07-05T07:35:01+00:00, nodejs, promote
2023-07-05T11:05:01+00:00, nodejs, promote
2023-07-05T12:35:01+00:00, nodejs, promote
2023-07-05T13:35:02+00:00, nodejs, promote
2023-07-05T14:00:01+00:00, nodejs, promote resha_release
2023-07-05T14:55:01+00:00, nodejs, build-site
2023-07-05T16:30:01+00:00, nodejs, build-site
The first two "promote"s are from the nightly build, the next three from the V8 canary, and the last "promote" (and "resha_release") from the manual promotion of 20.4.0. The subsequent "build-sites" are from merging https://github.com/nodejs/nodejs.org/pull/5473 and https://github.com/nodejs/nodejs.org/pull/5474 respectively.
Purging everything is rather heavy handed, but our current options in Cloudflare are to either purge everything (as we are doing) or purge a list of static URLs (there are further options only available for enterprise accounts which we do not have access to). Switching to a more selective cache purge requires us to determine what URLs to purge for all of the above scenarios that we are currently purging everything.