Question about Cloudflare Worker usage #299
Replies: 1 comment 1 reply
-
So yes, multiple users requesting the same coordinates will always invoke a Worker, but not necessarily cause a cache miss (that hits R2). R2 is quite slow compared to competing storage systems, and the Cloudflare team is working on improving this. If your PMTiles changes infrequently you could set a more aggressive TTL via
It shouldn't be necessary, and may not work correctly because of how the Cloudflare "cache everything" rule mishandles Range 206 responses. 1 request = 1 worker invocation is the preferred deployment model and should have good unit costs. |
Beta Was this translation helpful? Give feedback.
-
I've been running a PMTiles setup using Cloudflare as the CDN as described in the documents. I do not really understand how the number of Worker requests and R2 requests correlates with users and wondered if someone had some insight.
For example, I've had about 112,000 users in the last 48 hours or so. This has translated into 7.5 million Cloudshare requests in total, which includes both my PMTiles setup and a number of static files which should mostly be cached (I checked and saw that most of them were, but I needed to set up a Page Rule to make sure some file types — JSON and PBF in particular — were also cached).
Of that 7.5 million requests, 5.6 million were Worker invocations, and the only Worker I have in place is the one serving the .pmtiles file. However, the R2 bucket with the .pmtiles file only says it has had 2.5 M Class B (read) operations.
My interpretation of the above numbers is that on average, users are using about 50 tiles. That seems a little high but is not implausible given the nature of the site (a lot of users move things around, and the site necessarily involves going between different zoom levels; tracking .mvt calls on my own machine when I use the map as I imagine a hypothetical user might gets me up to 30-40 requests pretty frequently, and I can imagine heavier users adding a lot to that). Each of those requests for a .mvt tile goes to a Worker and counts as a Worker request. On average, the Worker triggers a cache hit about 50% of the time (not implausible given the nature of the site that 50% of the usage would be the same few places and the other 50% would be random places that might not be reused by others). So that means it is only reading the R2 file (the Class B operation) that number.
Is this right? And can I confirm that even if multiple users request the same .mvt file coordinates, that triggers a Worker invocation no matter what? If I tell Cloudflare to cache all URL requests for my domain with a Page Rule, will that decrease the number of Worker being requested? (I have just tried this, but don't have enough data to know the answer yet, but thought I would ask...)
Beta Was this translation helpful? Give feedback.
All reactions