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

    Greylock

    06/17/2021, 8:05 PM
    Which brings back the stuff I discussed about the 32kb value limit
  • b

    brett

    06/17/2021, 8:33 PM
    If your docs get that big you might have to write some code to split them into multiple keys (there isn't a limit of total storage in the object), or you could in theory persist them to KV and use the DO for websocket coordination
  • m

    maxastuart

    06/17/2021, 10:16 PM
    Anyone got Typescript types for
    new WebSocketPair();
    in durable objects?
  • j

    jamis0n

    06/17/2021, 10:22 PM
    To be clear, I do not need to persist the YJS Document (binary) data to a KV. I just need it to be active in memory on the worker as long as there is at least 1 active websocket connection to the worker. Once the last connection drops, I will be writing the doc to Postgres via my own API. Can the durable object store ~10MB in state while 1 websocket is active?
  • g

    Greylock

    06/17/2021, 10:22 PM
    oh I see
  • g

    Greylock

    06/17/2021, 10:22 PM
    just some info on the latest state?
  • g

    Greylock

    06/17/2021, 10:23 PM
    they can store 10MB in state but it has to be spread across hundreds of values
  • g

    Greylock

    06/17/2021, 10:23 PM
    oh sorry
  • g

    Greylock

    06/17/2021, 10:23 PM
    yes
  • j

    jamis0n

    06/17/2021, 10:23 PM
    I just got the chat application deployed, so Im gonna try changing it out to my YJS server now!
  • g

    Greylock

    06/17/2021, 10:23 PM
    I think they are regular workers in terms of their limit of memory (512MB afaik)
  • j

    jamis0n

    06/17/2021, 10:24 PM
    thats great!
  • g

    Greylock

    06/17/2021, 10:24 PM
    but the persistent storage is a key/value store with a maximum of 32KB per value
  • j

    jamis0n

    06/17/2021, 10:25 PM
    yup that makes sense. We may leverage a KV store for other stuff, but its not necessary for the primary use case: When 1 or more document editors have an open websocket connection, they are all guaranteed to connect to the same durable object instance which has a YJS doc (a
    new Y.Doc()
    ) in memory
  • v

    Vanessa🦩

    06/17/2021, 10:26 PM
    where do you see 512 MB RAM? The limits page lists 128 MB.
  • g

    Greylock

    06/17/2021, 10:26 PM
    ah my bad
  • g

    Greylock

    06/17/2021, 10:26 PM
    I guess its 128MB
  • j

    jamis0n

    06/17/2021, 10:30 PM
    We could certainly shard our docs in a way that limits each durable object to a max of 10 docs - 12.8MB per doc with some wiggle room is plenty
  • j

    jamis0n

    06/17/2021, 10:30 PM
    good use case for the KV store 🙂
  • j

    jamis0n

    06/17/2021, 10:31 PM
    Any idea how we could estimate pricing for that use case?
  • g

    Greylock

    06/17/2021, 11:54 PM
    well
  • g

    Greylock

    06/17/2021, 11:54 PM
    its $0.20/GB
  • g

    Greylock

    06/17/2021, 11:55 PM
  • g

    Greylock

    06/17/2021, 11:55 PM
    but id say... it depends?
  • j

    jamis0n

    06/18/2021, 12:23 AM
    OK I've hit a roadblock as the framework I'm working with expects a
    ws
    websocket object and I'm not sure how to create that based on the
    WebSocket
    instance available in the worker
  • d

    Deebster

    06/18/2021, 11:13 AM
    https://github.com/cloudflare/workers-types/issues/84 It's helpful to also add your bindings:
    Copy code
    type WorkerEnv = {
            foo: DurableObjectNamespace;
            bar: KVNamespace;
        }
  • m

    maxastuart

    06/18/2021, 4:03 PM
    that did the trick! did you find/make a base DO class, such as
    Copy code
    // types DurableObject & DurableObjectState are from '@cloudflare/workers-types'
    
    class BaseDurableObject extends DurableObject {
      constructor(controller: DurableObjectState, env: WorkerEnv) {}
    }
  • d

    Deebster

    06/18/2021, 4:13 PM
    yes, like that, although you'd have to do
    implements DurableObject
    since it's an interface, not a class
  • v

    Vanessa🦩

    06/18/2021, 10:17 PM
    Are binary messages in DO websockets really unsupported? Or is it just the docs that are wrong?
  • m

    maxastuart

    06/18/2021, 10:18 PM
    Is it possible in your setup to encode it as a string and decode it on the other end?
1...104105106...567Latest