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

    Brizy

    08/20/2021, 3:22 AM
    Yes it will, at around 1k websockets, the connections start to "break" randomly closing with 1006 close codes. And imagine you had a million websockets, the array would have a million elements and iterating over an array of a million elements takes a loooong time so this single durable object approach isn't scalable at all
  • d

    davidbarratt

    08/20/2021, 3:33 AM
    sounds like a network connection limit.... can you shard them in some way maybe? or could you perhaps access a durable object from within a durable object?
  • b

    Brizy

    08/20/2021, 3:36 AM
    That's what I want to do, shard the connections across multiple durable objects so those limits aren't hit but then doing things like broadcasting something to all connections would become impossible since there is no way to do this currently with durable objects afaik
  • d

    davidbarratt

    08/20/2021, 3:37 AM
    I wonder if you can access a durable object from within a durable object?
  • b

    Brizy

    08/20/2021, 3:37 AM
    Yes you can
  • b

    Brizy

    08/20/2021, 3:38 AM
    How would that help solve this though?
  • d

    davidbarratt

    08/20/2021, 3:45 AM
    you could drop your websockets into buckets so they are handled by separate threads
  • d

    davidbarratt

    08/20/2021, 3:45 AM
    so you could shard them into buckets of 100 (or whatever)
  • d

    davidbarratt

    08/20/2021, 3:46 AM
    and then just iterate through the buckets from the parent
  • d

    davidbarratt

    08/20/2021, 3:47 AM
    Master DO -> Bucket DO (1-X) -> Connections if someone posts a message it would get passed up to the master and spread out
  • d

    davidbarratt

    08/20/2021, 3:48 AM
    the connects between Master DO and Bucket DO's can just use the standard connections, I don't think they would need to use websockets...
  • d

    davidbarratt

    08/20/2021, 3:49 AM
    then each Bucket DO is only iterating over 100 (or whatever number you choose) connections
  • b

    Brizy

    08/20/2021, 3:51 AM
    That sounds great, I'm worried this will hit the subrequests hard limit of 50 since you'd be sending a request to all the bucket DO's
  • d

    davidbarratt

    08/20/2021, 3:51 AM
    instead of mainting a number you could use some systematic way of bucketing connections (i.e. hasing the usernames and using the first two letter of the hash, or whatever)
  • d

    davidbarratt

    08/20/2021, 3:51 AM
    oh right... didn't they just increase that limit though?
  • d

    davidbarratt

    08/20/2021, 3:51 AM
    but yeah you might be stuck at 50 buckets for now
  • b

    Brizy

    08/20/2021, 3:53 AM
    The website https://developers.cloudflare.com/workers/platform/limits says 50, hopefully it will be increased in the future or maybe they can provide some way of doing all this without having to make subrequests
  • d

    davidbarratt

    08/20/2021, 3:53 AM
    yeah totes
  • a

    albert

    08/20/2021, 4:34 AM
    That limit is for outbound HTTP requests. Durable Object stub requests have a different limit.
  • a

    albert

    08/20/2021, 4:34 AM
    it's 1000 iirc
  • m

    Murray

    08/20/2021, 5:37 AM
    The limit increase from 50 subrequests to 1000 can be found in the release notes: https://community.cloudflare.com/t/2021-7-16-workers-runtime-release-notes/287327
  • i

    ItsWendell

    08/20/2021, 7:03 AM
    @Brizy super interesting stuff. Thanks for sharing your issues! Please keep us posted about your progress on this, I'm also working on solving a similar issue of scaling wbesockets. Knowing these limits that you posted is super useful, if you have more details on this would love to hear about them too!
  • m

    mikeysee

    08/20/2021, 8:06 AM
    DurableObjectState.id.name
    from within the durable object's fetch doesnt seem to return the name that was used to create the durable object, is this intentional?
  • a

    albert

    08/20/2021, 9:43 AM
    idFromName()
    is actually just a hashing function, so the DO has no way of knowing the name used. You'd have to pass it to the DO in a request.
  • a

    albert

    08/20/2021, 9:46 AM
    You can do this with a parameter or a header, or you could set it as the hostname if it does not include invalid characters.
  • i

    ItsWendell

    08/20/2021, 10:03 AM
    hostname is actually a nice one, haven't thought about that.
  • a

    albert

    08/20/2021, 10:56 AM
    It also makes it easy to see which DO the request is going to when using
    wrangler tail -f pretty
    😛
  • a

    albert

    08/20/2021, 11:07 AM
    speaking of URLs in DO requests, you can modify pretty much every part of it as long as it conforms to the URI spec
  • a

    albert

    08/20/2021, 11:10 AM
    so something like
    GET user://username/posts/1
    is possible, if you want
  • b

    Brizy

    08/20/2021, 11:33 AM
    For sure, I'll keep you posted
1...158159160...567Latest