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

    617a7a

    12/06/2022, 9:01 PM
    so we're thinking of implementing finance accounts in durable objects, but since people move around the world to make their payments we don't want to increase latency when they make a payment. for example, if i create my account (as a DO) in london and go to japan to make a payment with that account, i don't want it to go all the way to london to make the payment if it doesn't need to
  • i

    ItsWendell

    12/06/2022, 9:03 PM
    Aahhhh okay, time to rethink my strategy here, thanks 😄
  • j

    john.spurlock

    12/06/2022, 9:13 PM
    Does anyone know of a way to delete more than 128 keys in a single DO in a single transaction? ie guaranteed all deleted or none
  • u

    Unsmart | Tech debt

    12/06/2022, 9:15 PM
    pretty sure calling it with 128 keys multiple times over will still be single transaction as long as you dont await, otherwise its probably not possible
    p
    b
    j
    • 4
    • 8
  • e

    Erwin

    12/06/2022, 11:23 PM
    This was changed recently.. I believe the smallest increment is now $1.25
  • w

    Wallacy

    12/07/2022, 12:19 AM
    That’s good! For personal projects is very good smaller increments. That’s more inline with other solutions.
  • e

    Erwin

    12/07/2022, 12:24 AM
    Yeah.. it doesn't really matter all that much for the $0.50 bundled requests.. but with $12.50 per unit, that was a bit much 😄
  • h

    HardAtWork

    12/07/2022, 9:28 AM
    Anyone have a good Regex for DO IDs? They are hex(I think), but is there a certain length they always have?
  • h

    HardAtWork

    12/07/2022, 9:34 AM
    NVM, here's one:
    Copy code
    regex
    /[a-f0-9]{64}\.search\.docs\.cloudflare\.community/g
  • e

    Evorage

    12/07/2022, 11:05 AM
    Is there any way I can pass a WebSocket object from one DO to another? I create a DO for every WS connection to manage it but I'm also trying to implement a room system which stores a group of WS connections.
  • h

    HardAtWork

    12/07/2022, 11:06 AM
    No. Connections are tied to the isolate that creates them at the moment, and cannot be transferred.
  • e

    Evorage

    12/07/2022, 11:07 AM
    oh, is there anything you can suggest to get around that?
  • h

    HardAtWork

    12/07/2022, 11:08 AM
    Create a DO that stores the WebSockets, and then forward messages to it?
  • e

    Evorage

    12/07/2022, 11:09 AM
    I'll try implementing that, thanks!
  • h

    HardAtWork

    12/07/2022, 11:10 AM
    No problem!
  • a

    aranchelk

    12/07/2022, 6:35 PM
    I'm trying to identify the cause of a performance issue, it may be tied to the code I run to initialize DO instances. Some questions, thank you in advance: Is there any way to force a DO instance to be evicted in production (for testing purposes)? Are there any known performance issues using the list method? If I use the list method to find the last key ( lexicographic order) by using limit and reverse options, behind the scenes, does that require iterating through all stored elements?
  • b

    brett

    12/07/2022, 8:02 PM
    List shouldn't need to scan everything, no. To reset an object (as a hack) you can throw from inside
    blockConcurrencyWhile
    , see: https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
  • a

    aranchelk

    12/07/2022, 8:19 PM
    Awesome! Thank you!
  • a

    aranchelk

    12/07/2022, 10:24 PM
    I can't seem to trigger an eviction, I've tried throwing errors from both sync and async functions within a blockConcurrencyWhile, in dev mode I can see from the console output that my instance variables are still populated (my code never has to go back to storage to repopulate those values). I wonder if the documented behavior is limited to code running in the constructor function.
  • b

    brett

    12/07/2022, 11:06 PM
    Hmm, it shouldn't be, how are you testing for eviction? Another way to do it would be a code deploy, or even (for now) activating logs (which is effectively a code deploy for now)
  • a

    aranchelk

    12/07/2022, 11:40 PM
    I take that back, I cannot evict when throwing an exception from an async function. From a synchronous function I can successfully evict the object. Thanks again!
  • p

    phritz

    12/07/2022, 11:59 PM
    Can you share with us how you evaluate whether an eviction was successful? Sounds like set an instance variable on the DO instance and then check it on the next request after eviction was supposed to have occurred?
  • a

    aranchelk

    12/08/2022, 12:10 AM
    Yes, and I log to console when the constructor runs. As long as I use a synchronous function to throw the exception, I do see the constructor running again, so that does work. I’m having a separate issue now that I’m troubleshooting.
  • j

    Jacob Wright

    12/08/2022, 12:31 AM
    Is there a way in code to tell what environment you're in? I'd like to not save something to KV when using
    wrangler dev
    so if I can use
    env.isDev
    or something, that would be nice.
  • j

    Jacob Wright

    12/08/2022, 12:54 AM
    I'm looking for the Node equivalent of
    process.env
    I guess.
  • a

    aranchelk

    12/08/2022, 1:48 AM
    You can bind whatever environment variables you want in wrangler.toml, then access them in DOs via the env argument passed into the constructor function. https://developers.cloudflare.com/workers/platform/environment-variables/ https://developers.cloudflare.com/workers/learning/using-durable-objects/
  • a

    aranchelk

    12/08/2022, 10:20 PM
    Implementation question for the Durable Objects team: how is automatic write coalescing implemented under the hood? Did you modify how await works in your JS engine, modify the promise that DO write functions return, or something else? The reason I'm asking is I want to know if it's required to use "await" or if it's enough to just try to consume the result of the returned promise (e.g. using .then()). I'm using a compile-to-JavaScript language and I want to make sure I trigger writes at the correct time. Also, beyond losing the correctness guarantees, are there any performance implications when not coalescing writes, i.e. firing off each write operation as it's created (with await or sync())?
  • b

    brett

    12/08/2022, 10:38 PM
    Hmm, I'm not sure I follow the bit about using
    then
    vs
    await
    , why would it matter here? But to answer your question, I think, you can think of it like putting your changes into a big map, and those changes are flushed before your response is allowed to return. If you set the same value of a single key multiple times, only the last version needs to be flushed.
  • a

    aranchelk

    12/08/2022, 10:45 PM
    I understand what you're saying regarding duplicate operations to the same key. Regarding then vs await. The docs all say "await" is what triggers the flush of operations, but await is AFAIK just syntactic sugar that calls .then() on promises. For anyone using compile to JS languages, bundlers, etc. it's certainly easier to trust that however the promise is consumed, the flush will be triggered, but if it's tied to the interpreter and specifically the await statement, then we've got to make sure that whatever code gets outputted by our toolchains definitely has "await" in there.
  • b

    brett

    12/08/2022, 10:53 PM
    Nope, no magic here, then is fine too. It's the act of yielding that matters.
1...453454455...567Latest