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

    johtso

    03/11/2023, 2:10 PM
    I guess that's true as long as my rate limiting only cares about a window of 10 seconds or less
  • d

    Dani Foldi

    03/11/2023, 2:12 PM
    *30, DOs stick around for 30 seconds after a request
  • j

    johtso

    03/11/2023, 2:13 PM
    good to know, I think the docs say a minimum of 10s
  • j

    johtso

    03/11/2023, 2:13 PM
    "In the absence of failures, in-memory state should not be reset after less than 10 seconds of inactivity."
  • j

    johtso

    03/11/2023, 2:14 PM
    but I guess that's the pessimistic number
  • j

    johtso

    03/11/2023, 2:15 PM
    I wonder if it's better to implement a rate limiter as a proxy or just as an api that returns whether a request should be allowed..
  • j

    johtso

    03/11/2023, 2:15 PM
    I guess a proxy would be more efficient
  • j

    johtso

    03/11/2023, 2:16 PM
    but probably only very marginally?
  • j

    johtso

    03/11/2023, 2:25 PM
    @Skye hold on a minute, if I hosted my website in a DO wouldn't everyone's requests block every time I made a fetch to another DO / worker?
  • j

    johtso

    03/11/2023, 2:25 PM
    or is that input output gate stuff only for storage operations?
  • j

    johtso

    03/11/2023, 2:26 PM
    which I guess I can turn off with
    allowConcurrency
    and
    allowUnconfirmed
  • s

    Skye

    03/11/2023, 2:26 PM
    I don't know enough about DO's input output gates to answer that
  • j

    johtso

    03/11/2023, 2:26 PM
    no worries
  • d

    Dani Foldi

    03/11/2023, 2:30 PM
    You're correct in that if the input gate is closed, no new requests will come in. The input gate is opened whenever you make an external async request, such as fetch another DO/worker - so that should open the input gate and allow other requests to be processed in the meantime.
  • j

    johtso

    03/11/2023, 2:42 PM
    just trying to get my head around what the deal is if every request needed to increment a value in storage, and making the get and then put atomic
  • j

    johtso

    03/11/2023, 2:44 PM
    I feel like it just works, but I'd love to understand why
  • j

    johtso

    03/11/2023, 2:44 PM
    I think I just need to read the blog post 10 more times until it all clicks
  • j

    johtso

    03/11/2023, 2:47 PM
    and probably do some more reading on how javascript concurrency works 😂
  • j

    johtso

    03/11/2023, 2:51 PM
    "Any other events will be deferred until such a time as the object is no longer executing JavaScript code and is no longer waiting for any storage operations"
  • j

    johtso

    03/11/2023, 2:51 PM
    I think this is the bit I was missing!
  • j

    johtso

    03/11/2023, 2:53 PM
    new events wont be delivered while code is executing, only when the event loop is idle
  • j

    johtso

    03/11/2023, 3:03 PM
    @Skye another potential issue. say my DO needed to calculate some expensive hashing function when a user logs in, that would block all other requests
  • j

    johtso

    03/11/2023, 3:03 PM
    where as with a worker the other requests would get handled by another instance?
  • s

    Skye

    03/11/2023, 3:25 PM
    That sounds correct, yes
  • j

    johtso

    03/11/2023, 4:09 PM
    so I guess you'd just have to be extra careful to have short execution time, and defer anything that might be cpu intensive to another worker/do
  • s

    Skye

    03/11/2023, 4:16 PM
    I wouldn't really design all of it in DOs unless you had a specific reason for it
  • s

    Skye

    03/11/2023, 4:16 PM
    It sounds like a lot of the work you want to do could be done in workers, with just specific parts being a DO
  • j

    johtso

    03/11/2023, 4:23 PM
    @Skye I guess I just liked the idea that my entry point would be colocated with my other DOs so communicating between them would be faster, and things like a rate limit check could even be stored locally to avoid an extra request for each user request
  • j

    johtso

    03/11/2023, 4:24 PM
    but yeah, premature optimisation
  • s

    Skye

    03/11/2023, 4:25 PM
    You can generally make a good start on ratelimiting with just the WAF too
1...515516517...567Latest