https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • g

    Greg Brimble | Cloudflare Pages

    08/10/2021, 8:49 AM
    https://discord.com/channels/595317990191398933/802187271067140107/869307059466797066 Should be now, I think!
  • i

    ItsWendell

    08/10/2021, 8:54 AM
    Oh awesome! I should follow these community posts more closely!
  • i

    ItsWendell

    08/10/2021, 10:39 AM
    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 😅
  • k

    kenton

    08/10/2021, 2:25 PM
    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.
  • a

    Adam!!!

    08/10/2021, 2:33 PM
    Is it possible to change a durable object's id without making a new object? I've not tried yet, just curious
  • g

    Greg-McKeon

    08/10/2021, 3:29 PM
    No, a given id always routes to the same object. I'm assuming you're using named ids and want to migrate DOs?
  • a

    Adam!!!

    08/10/2021, 4:42 PM
    yeah, is there any way about that?
  • a

    Adam!!!

    08/10/2021, 4:47 PM
    say I store a users account with their email for the ID and their password persisted (I don't think this is a fit use for durable objects, but correct me if I'm wrong), how would I go about updating the ID when the user changes their email?
  • i

    ItsWendell

    08/10/2021, 5:04 PM
    Is there a in-memory limit to Durable Objects?
  • j

    john.spurlock

    08/10/2021, 5:06 PM
    hehe, there is indeed
  • j

    john.spurlock

    08/10/2021, 5:07 PM
    standard limit for workers is 128MB
  • j

    john.spurlock

    08/10/2021, 5:08 PM
    however, more than one instance of your DO may instantiated in the same isolate - in this case, they all compete for the same 128MB
  • j

    john.spurlock

    08/10/2021, 5:09 PM
    in practice, you shouldn't have to think about it, especially if you keep your state small and mostly just make
    .storage
    calls
  • j

    john.spurlock

    08/10/2021, 5:10 PM
    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
  • i

    ItsWendell

    08/10/2021, 5:18 PM
    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. Edit: Should have been horizontally*
  • j

    john.spurlock

    08/10/2021, 5:21 PM
    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

    ItsWendell

    08/10/2021, 5:22 PM
    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.
  • j

    john.spurlock

    08/10/2021, 5:23 PM
    yes! as long as you don't get unlucky: the runtime might decide to instantiate the other DO in the same isolate! then you're screwed : )
  • i

    ItsWendell

    08/10/2021, 5:24 PM
    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.
  • i

    ItsWendell

    08/10/2021, 5:24 PM
    Ah yes that's a problem.
  • i

    ItsWendell

    08/10/2021, 5:25 PM
    You'd just spawn 10 just to be sure 😅
  • i

    ItsWendell

    08/10/2021, 5:25 PM
    Like a spider laying it's eggs, many will die, but many will survive
  • j

    john.spurlock

    08/10/2021, 5:28 PM
    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
  • j

    john.spurlock

    08/10/2021, 5:29 PM
    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
  • j

    john.spurlock

    08/10/2021, 5:32 PM
    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 https://discord.com/channels/595317990191398933/773219443911819284/869608842789552228
  • j

    john.spurlock

    08/10/2021, 5:33 PM
    which is too bad imo, can think of lots of cool stuff you might be able to build with DOs if they were a bit more predictable in the memory department
  • b

    brett

    08/10/2021, 5:37 PM
    I almost had a fix for this in on Friday but I need to do more testing, and I'm out this week. Soon!
  • g

    Greg-McKeon

    08/10/2021, 6:07 PM
    either 1) migrate the data in their durable object to the new id or 2) use an id that's decoupled from the email, like a system-generated id. We have some ideas for how to ease migrations in the future.
  • h

    HardAtWork

    08/10/2021, 6:11 PM
    Anyone know if there is a way to delete a Worker with an attached DO namespace if I do not have access to the script anymore?
  • b

    brett

    08/10/2021, 6:39 PM
    As other have noted, there is an HTTP List API that you can use to paginate all objects in a namespace. DM me for details. But I would say that API is more for "administrative" tasks, like maybe to periodically crawl all objects to do some task or sync to some other DB. If you want to list objects quickly from inside a Worker/DO I would definitely make your own object and store the inside of a DO. Hopefully people will find useful patterns/abstractions and share their code, I think this will be generally useful.
1...146147148...567Latest