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

    Deleted User

    04/23/2021, 1:42 AM
    i could just have one single durable object, the latency probably wouldn't be ideal though
  • b

    brett

    04/23/2021, 1:10 PM
    Not currently, for now you'd have to implement a TTL in your object (or on each key) and handle it in your app.
  • j

    Jama

    04/23/2021, 3:51 PM
    Hey folks! I want to build an API Gateway using CF Workers and Durable Objects. I'm thinking of modeling accounts as an object. The basic use case would be to increment the number of calls the account has used if the API request is successful. It seems to me that KV isn't ideal for this case due to the heavy write workload and not supporting atomic operations. Is my line of thinking correct? Is there anything else I need to know if I want to use Durable Objects (besides what's in docs)?
  • h

    haneefmubarak

    04/23/2021, 5:33 PM
    The main thing that comes to my mind is to keep in mind that while scaling horizontally (many object, each serving a few requests) is supported natively, scaling vertically (a few objects, each serving many requests) is comparatively not a performant configuration.
  • h

    haneefmubarak

    04/23/2021, 5:35 PM
    In particular, I'd say to make sure that if you expect to have some accounts with a high RPS, that you shard within those accounts across multiple Durable Object instances to ensure good performance.
  • h

    haneefmubarak

    04/23/2021, 5:35 PM
    Your application sounds like a great use of Durable Objects though and I'm excited to see what you build!!!
  • m

    Mallissin

    04/23/2021, 6:45 PM
    Hello! I have been using the workers-chat-demo as a reference and wondering if the newUniqueID() method is only available to Durable Objects or KV objects? Also, does this method have a non-zero chance of collision on the same DO or KV key set?
  • m

    Mallissin

    04/23/2021, 9:12 PM
    This sort of answered one of my questions and I assume it's only available with Durable Objects.
  • k

    kenton

    04/24/2021, 12:36 AM
    Some big DO changes in this week's release https://community.cloudflare.com/t/2021-4-23-workers-runtime-release-notes/263246
  • e

    eidam | SuperSaaS

    04/24/2021, 9:37 AM
    This is great! Thank you! 👏❤️
  • j

    john.spurlock

    04/24/2021, 5:45 PM
    Anyone notice Date.now() is no longer monotonic increasing inside DO instances? I'm seeing Date.now() after
    this.state.storage.get
    calls that are sometimes 2 or 3 ms before a Date.now() taken right before the call.
  • d

    Deleted User

    04/24/2021, 5:50 PM
    Its just that fast
  • m

    Mallissin

    04/24/2021, 6:10 PM
    I think I read in the docs that Date.now() only returns the start time of the worker or something like that?
  • m

    Mallissin

    04/24/2021, 6:11 PM
    Yeah. ``Date.now() returns the time of the last I/O; it does not advance during code execution.``
  • j

    john.spurlock

    04/24/2021, 7:04 PM
    yea that's been the case since day one - the new thing I'm seeing is after some I/O, it actually moves backward, instead of advancing
  • m

    Mallissin

    04/24/2021, 8:36 PM
    Sounds like trouble!
  • m

    Mallissin

    04/24/2021, 9:02 PM
    Kind of makes sense that not every Worker has the exact same time though? Can't expect them all to have atomic clocks?
  • d

    Deleted User

    04/25/2021, 6:46 AM
    do DO classes have to be exported fron the main file?
  • j

    jed

    04/25/2021, 7:26 AM
    > Existing WebSocket connections to Durable Objects will now be forcibly disconnected on code updates, in order to force clients to connect to the instance running the new code. Can someone confirm the granularity of "code updates" here? Given that DOs can only be updated with an underlying worker, it seems like any change to a worker will disconnect all WebSocket connections, even when the DO code itself remains the same.
  • b

    brett

    04/25/2021, 12:40 PM
    Any change to the Worker script that is used to implement the DO class will effectively restart all existing DO instances, yeah. I'm not sure whether we could detect whether a code change only effected some other bundled endpoint and not the DO class.
  • j

    jed

    04/25/2021, 12:44 PM
    I see. And there's no way to bind to a DO without including its source, right? Say, for example, I have a worker that serves an app, but wants to use a DO's
    newUniqueId
    to generate IDs (and not actually invoke the worker via
    fetch
    )... is there no way to update this worker without triggering a DO update?
  • j

    john.spurlock

    04/25/2021, 2:21 PM
    You definitely can have a worker script that is a DO client (namespace, stub object) that calls into a DO, but does not include the DO implementation source - that's what I'm doing until module workers have full parity with script workers - you can keep the DO stable, and rev the client script more frequently
  • b

    brett

    04/25/2021, 5:14 PM
    Yep, just add a binding from your client worker: https://developers.cloudflare.com/workers/learning/using-durable-objects#configuring-durable-object-bindings
  • j

    jed

    04/25/2021, 10:31 PM
    Ah, I didn’t realize the script name is optional. Thank you @john.spurlock and @brett!
  • v

    vans163

    04/26/2021, 2:32 AM
    for some reason this syntax is invalid/crashes with no error
    Copy code
    ['account', 'account_id'].forEach(e => delete job[e]);
    but works fine in browser
    Copy code
    delete job.account
    delete job.account_id
    
    works fine
  • v

    vans163

    04/26/2021, 3:40 AM
    Something nice would be being able to
    Copy code
    this.job_queue = await this.storage.list({prefix: "job_queue:"}) || new Map();
    
    but have the keys not prefixed with "job_queue:"
  • m

    matt

    04/26/2021, 2:19 PM
    Last week we changed CPU time limits on durable objects to be tracked at the object level rather than the request level. This interacted poorly with some of our spectre mitigations, with the effect being that an object's clock could become increasingly skewed over time. We pushed a fix over the weekend that corrects the clock when it drifts too far off.
  • j

    john.spurlock

    04/26/2021, 2:29 PM
    ah ok, interesting, thanks - so for DOs (only), a delta of a few negative ms is expected every once in a while going forward, especially for long-lived DO instances?
  • m

    matt

    04/26/2021, 2:36 PM
    You could occasionally see up to a second or two of drift, but shouldn’t be more than that.
  • j

    john.spurlock

    04/26/2021, 2:40 PM
    ok, it seems to be better today fwiw. Not a big deal, just looked weird in the logs - thought maybe a single DO instance might actually be running speculatively on two diff isolates or something
1...707172...567Latest