When do new workers instances get created?
Some questions:
A. For example, if one of my workers is overloaded/blocked with requests, will Cloudflare start new workers instances instead of queuing the requests somewhere?
B. When a worker has a durable object, is that durable object in another instance separate from the worker?
E.g. is this call sending data to another thread, or the same thread: await env.DURABLE_OBJECT.fetch(request)
C. Is every durable object with a unique ID another thread?
D. I am trying to understand when it is OK to block the JS event loop, and if this has an effect on the latency of other requests that are incoming. And in general, how I should split up my app into workers for maximum scalability.
The general advice is, don’t worry about trying to scale. Workers already handles it.
Yes, a new instance will be spun up if needed. Note that it isn’t likely to have requests hitting the same instance anyway, Cloudflare has over 285 locations globally, most with multiple colos. If a Worker is warm, it’ll try and re-use it before it shuts down (make sure to use module format to take full advantage of that) but the request won’t route to another location as that’d take longer than just spinning up a new instance.
Yes, a Durable Object is basically it’s own Worker instance running in a static location.
A durable object instance may share resources (most noticeably JS global memory) with other instances defined in the same script in the case they are running on the same physical server. They’re not guaranteed to be completely separate.