Repository navigation
Replies: 2 comments
|
For a self-hosted workaround while the threading contract is clarified, I’d shard on the object’s stable identity (tenant, namespace, object ID) at the process boundary. Route all requests for a given object to the same owner and make reassignment explicit. For a SQLite-backed DO, keep one active owner of its data across restarts or scaling, since round-robin routing can create conflicting owners. This reduces the number of tenants delayed by one synchronous The workerd README’s sandbox warning also matters here: if tenants can submit untrusted code, run these shards in an appropriate secure sandbox in addition to addressing event-loop blocking. |
|
There is work underway. @ry or @piscisaureus might be able to expand on the plans here but the best suggestion is to follow the PRs/commits they are working on in this repo. |
Uh oh!
There was an error while loading. Please reload this page.
We run workerd as the runtime of a self-hosted platform where one process hosts many Workers from tenants that do not trust each other.
Reading the source, the library layer (
io/,jsg/) is clearly built for threads: an isolate is entered throughWorker::takeAsyncLock(), aThreadContextis meant to exist per request-handling thread, and anIoContextis tied to one thread. The open-source server, on the other hand, creates one event loop per process, and its own notes describe it as one thread with one loop.With one loop, every synchronous stretch (CPU-bound JavaScript, a long
sql.exec(), a burst of cold starts) delays all Workers in the process, so CPU and SQL limits have to be set by what neighbours can tolerate rather than by what a tenant needs. We want to move to the model the production runtime uses, as far as it is public (a thread per connection, isolates moving between threads), and we would like to avoid building something that conflicts with where workerd is going. Four questions:1. Plans for multi-threaded execution. When #6780 was closed, the closing comment said that a much simpler multi-threaded design needing no separate configuration should be possible. Is that planned or in progress, and what shape would it take: a thread per connection as in production, or a fixed number of loops?
2. A different server on the same library.
server/AGENTS.mdcallsworkerd-serverthe single-tenant server and says the production runtime supplies its own policy objects. If a self-hoster writes a multi-threaded server directly onio/,jsg/andapi/(reusingWorkerdApi, implementingIoChannelFactory,LimitEnforcer, the actor hooks and so on), is that a use you would expect to keep working? Are there known places where the open-source library, as opposed to the server, still assumes a single thread?3. Durable Objects and threads. A
Worker::Actormay only be used from the thread that created it. In a thread-per-connection server, how does a request that arrives on another thread reach the object: is it handed to the object's thread, and how are objects assigned to threads? Even a rough description of the approach would help.4. Long SQL in SQLite-backed objects and D1.
sql.exec()runs synchronously on the thread that holds the isolate lock. In production, is the only thing that keeps one object's long query from delaying other objects the fact that they run on other threads (so that objects sharing an isolate do wait for each other), or is there an additional mechanism, for D1 databases in particular?A smaller related point: in #351 you described the single 4 GB pointer cage shared by all isolates of a process, and that production uses a cage per isolate. The tree now has isolate groups. Is building workerd with one group per isolate (or per tenant) something you would recommend for processes that hold thousands of isolates, and are there caveats?
Thanks. Any pointers are useful, including "not decided yet".
All reactions