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

    Unsmart | Tech debt

    01/27/2023, 8:37 PM
    Like I said though I would highly recommend you use alarms that you increment anytime an object is active if you want to delete them once they become inactive
  • f

    frankichiro

    01/27/2023, 8:37 PM
    Ok, fair enough. Then I know what's necessary. Thanks!
  • a

    aa

    01/27/2023, 9:43 PM
    > I assume storage.put returns once a write is committed to the local disk and writes are replicated asynchronously. This is not correct. Writes are replicated ~synchronously. The ~ is because of output gates (https://blog.cloudflare.com/durable-objects-easy-fast-correct-choose-three/), the synchronous replication is hidden from you but it's still there in a distributed systems sense. We have observed that the output gate takes ~30ms to open which is consistent with replicating to other DCs.
  • s

    SZAGLAM

    01/27/2023, 9:58 PM
    Is a DO guaranteed to be on a separate thread than the main Worker (even if the external request hits the same POP where the DO is located)?
  • j

    john.spurlock

    01/27/2023, 10:33 PM
    definitely different event loop, they are instantiated in completely different V8 isolates, iirc
  • s

    SZAGLAM

    01/27/2023, 10:44 PM
    That's great, thank you. Is it possible to do load balancing with multiple DO instances? Say we have a worker, which delegates the work to one of 10 DO instances (something like
    env.DO.get(env.DO.idFromName("" + rand() % 10))
    ). All 10 instances may end up sharing the same thread, right?
  • s

    Skye

    01/27/2023, 10:46 PM
    No, durable objects are always unique
  • s

    Skye

    01/27/2023, 10:46 PM
    However 1 DO will always run in 1 thread
  • s

    SZAGLAM

    01/27/2023, 10:48 PM
    Thank you. I'm not familiar with the underlying architecture. Does unique imply they are allocated to separate isolates or threads?
  • s

    Skye

    01/27/2023, 10:55 PM
    The point of a DO is it's one threaded
  • s

    SZAGLAM

    01/27/2023, 10:55 PM
    Sure,
    env.DO.get(env.DO.idFromName("1"))
    will run in one thread. How about
    env.DO.get(env.DO.idFromName("1"))
    and
    env.DO.get(env.DO.idFromName("2"))
    ?
  • s

    Skye

    01/27/2023, 11:00 PM
    Those are 2 separate DOs
  • s

    SZAGLAM

    01/27/2023, 11:01 PM
    Oh I am using the wrong terminology. The question is can two separate DOs from the same namespace be assumed to be on separate threads?
  • s

    Skye

    01/27/2023, 11:02 PM
    One do = 1 thread
  • s

    Skye

    01/27/2023, 11:02 PM
    2 dos are different threads
  • s

    Skye

    01/27/2023, 11:02 PM
    because they're entirely different workers
  • p

    phritz

    01/27/2023, 11:07 PM
    be aware that AIUI they can share the same global javascript context if they are defined in the same script. same with workers. and a context can be used more than once (eg, a DO that was previously instantiated can be instantiated in the same context again at a later point). careful. (more: https://discord.com/channels/595317990191398933/1042891744225796176/1061448114801741834)
  • s

    SZAGLAM

    01/27/2023, 11:09 PM
    Awesome, thanks all. This is actually exactly what I was worrying about. We have a request that requires two computations, each of which takes 5 secs. If a workers responds to this, it will take 10 seconds. To parallelize the worker will use two durable objects named A and B and a single request will take ~5 seconds. The problem is workers were infinitely scalable and DOs can potentially be scaled by manual load balancing (consider the 10 instances example above). But this load balancing idea may be bogus if there are no guarantees on separate threads
  • c

    ckoeninger

    01/27/2023, 11:12 PM
    writes need a quorum of replicas, typically in other nearby pops. failover is automatic. "ever be lost" is strong language, but writes shouldn't be lost.
  • c

    ckoeninger

    01/27/2023, 11:19 PM
    yes "If your account creates many instances of a single Durable Object class, Durable Objects may run in the same isolate on the same physical machine " https://developers.cloudflare.com/workers/platform/pricing/#durable-objects how likely that is depends on how many instances you make and how many machines are in the pop you're hitting. If your use case is completely parallelizable, do you need DOs for coordination? or are you just using them for storage?
  • s

    SZAGLAM

    01/27/2023, 11:21 PM
    Thank you. We use DO for the simple fact that Worker <> Worker service bindings are guaranteed to be on the same thread, so do not help with parallelization and DO bindings appear to work differently. We don't even touch the
    state
    passed to the DO constructor, so not using it for storage
  • c

    ckoeninger

    01/27/2023, 11:23 PM
    perhaps it's getting too into specifics of your use case, but if you have 2 different computations that each take 5 seconds that you want to run in parallel, what's stopping you from making 2 different http requests to 2 different stateless workers?
  • s

    SZAGLAM

    01/27/2023, 11:25 PM
    Are you suggesting not using Service binding and instead deploy Worker-Workers to a separate zone? AFAIK, same zone worker <> worker http requests were not allowed
  • s

    SZAGLAM

    01/27/2023, 11:26 PM
    So to answer your question, what's stopping us from doing that was the restriction on same zone worker to worker communication.
  • c

    ckoeninger

    01/27/2023, 11:26 PM
    yeah that's unfortunate
  • c

    ckoeninger

    01/27/2023, 11:27 PM
    I don't think you should have to use DO as a workaround for that when you don't care about durable state and don't care about coordination
  • c

    ckoeninger

    01/27/2023, 11:28 PM
    in practice, what you're describing using DOs will probably work most of the time, in that you'll get parallelism, but maybe 1/6 as much as is theoretically possible with a stateless worker
  • c

    ckoeninger

    01/27/2023, 11:28 PM
    stateless workers don't get a thread per request either
  • s

    SZAGLAM

    01/27/2023, 11:32 PM
    Thanks a lot. Maybe we should look into 2 zone deployment for now. It's ok if some queries take longer. It just feels like a missed opportunity to do 1 zone 1 worker deployment which is guaranteed to take >10seconds per request.
  • c

    ckoeninger

    01/27/2023, 11:33 PM
    yeah this is good feedback
1...484485486...567Latest