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

    thestatsguy

    03/14/2023, 3:44 PM
    If I want to use websockets in cloudflare just to post updates to clients with no need to track any history etc, just all connected clients do I need durable objects? And anyone know the pricing, say I have one instance of an object with 10-10000 connections over a month period. Not storing any data just occasionally broadcasting to clients
  • j

    Jacob Wright

    03/14/2023, 3:46 PM
    If you have 2+ clients that need to get messages from each other, you need durable objects, simply because you need to have each connection in memory so that when one message comes in, you can reference each other client and send the message along.
  • t

    thestatsguy

    03/14/2023, 3:46 PM
    they don't need to get messages from each other, just the server would need to broadcast to every client
  • t

    thestatsguy

    03/14/2023, 3:47 PM
    the same message
  • t

    thestatsguy

    03/14/2023, 3:47 PM
    ideally i would use pub sub but has a 1000 connection limit to 1 topic
  • j

    Jacob Wright

    03/14/2023, 3:51 PM
    "the server" would need to have that list of connected clients. Do you have your own backend server, or are you referring to what you are building on the Workers platform? If the former, workers can proxy websocket connections to an origin server. If the latter, the durable object would need to be the server so that some process somewhere can know the clients to send them data.
  • t

    thestatsguy

    03/14/2023, 3:52 PM
    ok yeah that is basically what I thought, I have the do as a server was just wondering if there was a way with just workers for cheaper but I don't know exactly what I'll be paying monthly. Is it the price of having the do basically running all the time if I have constant connections?
  • j

    Jacob Wright

    03/14/2023, 3:54 PM
    The price of a single DO for a month is about $4.15 to run it constantly, plus the cost of any messages received (sending out does not cost)
  • j

    Jacob Wright

    03/14/2023, 3:56 PM
    There are services like https://ably.com/ but they're more expensive.
  • j

    Jacob Wright

    03/14/2023, 3:57 PM
    Remember that DOs are single-threaded, so while you could have more than 1k connections to one, if there is a lot of messages being sent, it could struggle.
  • t

    thestatsguy

    03/14/2023, 3:58 PM
    total messages will be low
  • t

    thestatsguy

    03/14/2023, 3:58 PM
    like 50k a month
  • t

    thestatsguy

    03/14/2023, 3:58 PM
    but sent to each connection
  • j

    Jacob Wright

    03/14/2023, 3:58 PM
    Sounds like it would work.
  • j

    Jacob Wright

    03/14/2023, 3:58 PM
    You'd want to test it, of course, to ensure it can handle it.
  • t

    thestatsguy

    03/14/2023, 4:01 PM
    lets says 50,000 messages a month sent to 1000 connections so 50 million requests and it was 1 do active the whole time The docs say 50 million requests - included 1 million requests x $0.15 / 1,000,000 =7$ Then you say that would cost roughly $4.15 to run constantly? so like lets say $15 max? Or am I missing something here
  • c

    ckoeninger

    03/14/2023, 4:53 PM
    If you're talking about eyeball worker to DO connections, you don't need the cdn-cgi hack, the incoming CF object has the location of the eyeball request, and if you use that location in a naming convention for the DO, you're going to end up in a DO near there
  • c

    ckoeninger

    03/14/2023, 4:54 PM
    if you want something where arbitrary DOs are talking to arbitrary DOs in other arbitrary regions, pre-creating known names with corresponding location hints is as good as you can get currently
  • d

    Dani Foldi

    03/14/2023, 5:30 PM
    even with that we'd need https://where.durableobjects.live to figure out where the DO could be, or is there another hack for that?
  • c

    ckoeninger

    03/14/2023, 5:35 PM
    if you're e.g. making a DO named based on request.cf.country, why do you need to know where the DO could be? or you're saying you want to build a mapping from country to a fewer number of regions?
  • d

    Dani Foldi

    03/14/2023, 5:38 PM
    sort of, different mapping pair thought - to minimize (websocket) latency I'm looking for the colo where the DO would be created, and have one global coordinator DO group connections per target colo, up to N connections, after which I let it create itself a new group DO, and assign another N-1 connections to it
  • c

    ckoeninger

    03/14/2023, 5:44 PM
    I would not bet on cloudflare exposing DO creation preferences at the colo level.
  • c

    ckoeninger

    03/14/2023, 5:45 PM
    grouping websocket connections here is strictly for pricing reasons, there's no other relationship between websockets attached to the same DO?
  • d

    Dani Foldi

    03/14/2023, 5:46 PM
    correct, $4-5/connection/month seems wasteful for a connection that sends at most a few messages per minute
  • r

    rennokki

    03/14/2023, 6:26 PM
    There is still this problem going on: https://discord.com/channels/595317990191398933/773219443911819284/1045371388179005460
  • c

    ckoeninger

    03/14/2023, 6:36 PM
    are you referring to this repro https://github.com/rennokki/webocket-workers-bug or something else?
  • c

    ckoeninger

    03/14/2023, 6:55 PM
    Regarding potential improvements to websocket duration costs, open to feedback on this work in progress documentation PR for websocket hibernation: https://github.com/cloudflare/cloudflare-docs/pull/7872
  • r

    rennokki

    03/14/2023, 6:57 PM
    @ckoeninger Yes, that repo
  • r

    rennokki

    03/14/2023, 6:58 PM
    @ckoeninger @kenton There is a discussion on Soketi: https://github.com/soketi/soketi/discussions/733
  • c

    ckoeninger

    03/14/2023, 7:43 PM
    @rennokki I've had that repro open with the websocket client connected for over 10 minutes, an http request is still returning {"sockets":1} and our internal metrics still show that DO as being alive for the duration
1...519520521...567Latest