> JavaScript is inherently single-threaded, so an isolate can only be executing code on behalf of one request at a time. That said, it is already the case that multiple concurrent requests may be handled by the same isolate (one request may be executing while another is e.g. waiting for a response from a remote server). But today you can't really take advantage of that, because you have no control over exactly which isolate receives any particular request, no any way to communicate between neighboring isolates. This is definitely something we're working on but nothing to announce at this time.
Is this generally seen as ok? I'm planning on building similar things for sending page metrics in parallel to serving traffic.
> > Inability to rate limit Workers in a cost effective way gives me sleepless nights
Agreed, there is something very challenging with the current design of how requests flow through cloudflare.
I have played around with dynamic rules in firewall by manually handling "firewall rules" in a worker as part of a request flow and using KV to share this state. I would then update the cloudflare firewall with api. I had to create a separate service to poll both API and KV to maintain them though.
Can you drop me an email with some more details about what you're trying to do with Rate Limiting? I want to understand your use case/challenge a bit better: pat at cloudflare dot com.
We use a variation of this technique, and it works.
> I have played around with dynamic rules in firewall by manually handling "firewall rules" in a worker as part of a request flow and using KV to share this state.
You and I have pretty much the same problem then. Beware though of race conditions.
Also, a still cheaper way to keep a counter would be to use CountMinSketch and related probabilistic datastructures, but as before, data-race needs to be handled.
> Is this generally seen as ok? I'm planning on building similar things for sending page metrics in parallel to serving traffic.
It's OK, but you won't see a ton of benefit unless you have a very large amount of traffic -- enough that you're commonly seeing single isolates handling concurrent requests.
We're working on something that should be a lot better for this.
> It's OK, but you won't see a ton of benefit unless you have a very large amount of traffic
Our traffic patterns are such that per active-user we would add 100K requests per month when we go live. We send metrics out batched every 10s or so, but stumbled upon this post that warns of internal limit on total number of requests originating from Workers per second set at 2000, account-wide [0].
Is there a way to discuss our usecase and get whitelisted for limits as our traffic isn't malicious, hopefully without having to subscribe to the enterprise plan? I raised a support-ticket but a bot replied that since we are "free customers" it hasn't be been looked at.
> limit on total number of requests originating from Workers per second set at 2000, account-wide [0].
Oh, there is no such limit.
The post you link to is quoting another poster who is quoting something they heard from someone else. It sounds like something that may have originated with someone hearing about a particular implementation detail of our anti-abuse systems but the game of telephone has transformed it into something that's just not true at all.
As described in my comment on that thread, we do have certain anti-abuse heuristics which might result in a 1015 error. It's very unusual for people to hit these in legitimate use. Have you seen such an error? 100k requests per user per month doesn't sound like it would come anywhere near being an issue (even with 10M users).
FWIW the heuristics are designed such that simply adding more users (who behave the same as existing users) shouldn't ever cause a problem.
> 100k requests per user per month doesn't sound like it would come anywhere near being an issue (even with 10M users).
Nice. Thanks! That's re-assuring.
> It sounds like something that may have originated with someone hearing about a particular implementation detail of our anti-abuse systems but the game of telephone has transformed it into something that's just not true at all.
A Cloudflare employee engaged in this thread [0] confirmed existence of this internal limit: "...basically 2k subrequests _per minute_ per colo / zone / IP. Once you hit that you start serving 429s.", which another customer hit with ~5M requests per day (per a screenshot shared later in the thread) and had to get whitelisted for.
I've seen this used in a few contexts, for instance batching requests to a origin (logflare: https://github.com/Logflare/cloudflare-app/blob/master/worke...).
Is this generally seen as ok? I'm planning on building similar things for sending page metrics in parallel to serving traffic.
> > Inability to rate limit Workers in a cost effective way gives me sleepless nights
Agreed, there is something very challenging with the current design of how requests flow through cloudflare.
I have played around with dynamic rules in firewall by manually handling "firewall rules" in a worker as part of a request flow and using KV to share this state. I would then update the cloudflare firewall with api. I had to create a separate service to poll both API and KV to maintain them though.