Is there a way to easily identify a variable as a DO id or DO name? I think I saw a snippet somewhere but can't find it. Edit: I found something in the chat example actually
ES modules can import CommonJS modules in our system, just like in Node. We felt that it would be too harsh to say that people can't use CommonJS libraries at all if they use ES modules.
but it definitely can burn you in certain scenarios if you try to keep a bunch of things cached in memory, and expect to be able to instantiate several instances of the DO all at once
Ah okay, while experimenting and working on a chat application I got intrigued by scaling and how websockets / pubsub systems (horizontally) scale to millions of connections, it's interesting that you basically need some kind of Redis or In-Memory DB instance (which doesn't really horizontally scale) to get that far. I can image that once I have millions of websocket connections open on a DO, it'll probaby hit that memory limit.
yea, you'd hit it before millions and should probably shard them across multiple DOs at that point. It would be awesome to have a runtime api for observing the current memory usage - so you could have a rough estimate of how much each additional websocket connection costs from a memory pov
I was actually about to request that today hahaha, I've been thinking about how you would scalably setup a pub/sub system on Workers / Durable Objects. Having some sort of memory indication might help to prevent it from going over and booing up more DO's to handle that scale.
E.g. you'd have a primary DO handling storage and 'children', all the children of a DO connect to it's parent through WebSockets and can individually spawn 'children' too.
haha, they've stacked 21 of my larger objects into the same isolate - which is kind of a big problem - i wish you could specify the "sharing" level or a target mem usage when making the first stub call, that would give them more info on a per-instance basis of when to share or not
it's a tough problem, because for some DOs, they could get away with tons of sharing, no way to really tell ahead of time, but they could certainly use the runtime info from prior instantiations - anyway a way for us to specify this either at the class or instance (stub call) level would be awesome
i get the sense DOs are not really meant to be large and centralized, it would be difficult to build a centralized pub/sub bus - it seems like they are going more for smaller, user-level-state mostly durable-objects
The main difference (IMHO) is that a random worker will be selected to serve any specific request, but you can control which DOs that worker will talk to. That makes the DO a single global point to do stateful computations. Storage (again, IMHO) is secondary to that idea, but it makes DOs even more powerful since you get fast persistence.
I certainly wasn't there when the decision was made to call it Durable Objects, but I vaguely remember there was some pushback from people to use the term actor because DOs don't have the concept on an inbox, which actors frequently have. (But I personally don't think is a defining trait for actions, but oh well)..
yeah, we were going to call them "actors" but we noticed that everyone who was familiar with the actor model ended up getting more confused than enlightened by it, very much like Sergey Bykov's experience (that @toinbis linked above). I don't have any problem with admitting they are in fact virtual actors, as long as people aren't going to then expect to see supervision trees or whatever.
Nobody really loves the name "durable objects", but one thing I do really like about it is that we're using "object" in the object-oriented-programming sense, which I think is the right mental model for people to have when thinking about Durable Objects.
Hah... "Agents" was a name we considered. My argument for it was that "Workers" do whatever random work comes in the door while "Agents" are assigned specific long-term workloads. But other people on the team didn't like it...
At this point in my little ChatroomDurableObject I am creating a new WebsocketPair every time a worker connects. This websocket is used to send real-time messages to the workers subscribed. Would it be possible to just create a single WebsocketPair in the constructor of my DurableObject and sent the same 'client' back to all the workers 'subscribing' to it?