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

    hanpolo

    04/05/2023, 10:00 PM
    Does anyone know answers to these questions: 1. It states that DOs can be evicted from memory at any time. Can they be evicted while they are still active?(https://developers.cloudflare.com/workers/runtime-apis/durable-objects/#durable-object-lifespan) 2. Does a DO remain active if an alarm is set on it?
  • h

    HardAtWork

    04/05/2023, 10:06 PM
    Generally, DOs are not evicted for 30 seconds after they start processing a request, same for alarms
  • h

    HardAtWork

    04/05/2023, 10:07 PM
    But having an alarm set does not prevent a DO from being evicted
  • u

    Unsmart | Tech debt

    04/05/2023, 10:07 PM
    The answer is yes they can get evicted while active. And a DO is only active when actually processing the alarm (or other requests)
  • h

    hanpolo

    04/05/2023, 10:09 PM
    So what happens when they have Websockets. Do they suddenly go inactive and lose all memory state while websockets are active?
  • u

    Unsmart | Tech debt

    04/05/2023, 10:09 PM
    They can yes, most notably for runtime updates or code updates
  • h

    hanpolo

    04/05/2023, 10:18 PM
    One other question. Can a durable object call a pages-function or worker? I'm guessing this should be no different from an external call.
  • u

    Unsmart | Tech debt

    04/05/2023, 10:22 PM
    You can do a fetch yes but with workers you can also just use service bindings which will be faster
  • h

    hanpolo

    04/05/2023, 10:25 PM
    ok .. so presumably pages-functions can also have service bindings?
  • u

    Unsmart | Tech debt

    04/05/2023, 10:27 PM
    you cant bind to a pages function but you can bind a worker and call it in a pages function
  • h

    hanpolo

    04/05/2023, 10:28 PM
    ok .. thx much for your help @Unsmart | Tech debt & @HardAtWork
  • a

    Arun_Venkat

    04/06/2023, 5:17 AM
    hi @Larry , I have a router in my worker to handle GET, POST, PUT and DELETE http requests. All the http methods are accessing the DO. The GET method will load the data from db and put into state storage. And the state data is available in POST and PUT methods, but it is empty in DELETE method. Any help?
  • j

    Jacob Wright

    04/06/2023, 3:33 PM
    They didn't see any errors on their end, but a community ticket (https://community.cloudflare.com/t/worker-code-1104-script-not-found/219556) had a wasm that ran out of memory, so my guess is I am taking up too much memory? I'm not using wasm, but I did work on optimizations and a bug fix and I'm not seeing any issues for a few hours now, so 🤞 hoping it is resolved. Well, I get an occasional
    getaddrinfo ENOTFOUND
    but I believe that is a DNS issue. 🤷‍♂️ Thank you!
  • j

    Jacob Wright

    04/06/2023, 3:35 PM
    I'd like to request (again) for insight into how much memory/CPU a DO is using up from its maximum allotted. It would help with issues like mine and load planning.
  • c

    ckoeninger

    04/06/2023, 3:49 PM
    That community post is several years old. I do not see any evidence of exceeding memory or cpu on 2023-04-04 for the account corresponding to those rayIds you posted.
  • j

    Jacob Wright

    04/06/2023, 5:17 PM
    The bug I fixed was one with js Proxy that would occasionally create
    Maximum call stack size exceeded
    errors. I still don't understand why it occasionally did but not often. Perhaps that had something to do with it? From my position, I really can't guess what it was.
  • l

    Larry

    04/07/2023, 2:03 AM
    A DELETE method should see the same state.storage as any other method. I strongly suspect there is some other bug. Maybe you have a code path that creates a new instance rather than reusing one you've already hydrated from you db?
  • r

    rizrmd

    04/07/2023, 6:46 AM
    Hi, I am creating session storage in DO, as I understand there are two ways to store session id. First is in DO Stub, by creating different stub id for each different session, and the second one is, using same stub, e.g. "SESSION" as an ID, and store it inside DO className. My question is, is there any limitation or gotchas between those two ?
  • g

    geg

    04/07/2023, 9:43 AM
    If an inactive DO has a sudden 10k requests coming in, does it start up and instantly crash or would it actually accept what it can handle and drop the rest with an overloaded error?
  • s

    sathoro

    04/08/2023, 10:07 AM
    anyone have some code they can point to for a simple cache using DO?
  • h

    HardAtWork

    04/08/2023, 10:34 AM
    What are you caching?
  • s

    sathoro

    04/08/2023, 10:36 AM
    two main use cases right now. the first is JWTs that need to be validated with a third party server and the second is API responses
  • s

    sathoro

    04/08/2023, 10:36 AM
    right now the JWT cache never expires
  • s

    sathoro

    04/08/2023, 10:36 AM
    so I wanted to see some code for an easy way to evict them after some time
  • s

    sathoro

    04/08/2023, 10:37 AM
    basically just need to delete the object after X time
  • s

    sathoro

    04/08/2023, 10:38 AM
    Copy code
    js
    
    import { createDurable } from "itty-durable";
    
    export class JWTCache extends createDurable({ autoPersist: true }) {
      constructor(state, env) {
        super(state, env);
      }
    
      create(user) {
        this.user = user;
      }
    }
    pretty simple right now lol. never used the alarms before
  • m

    missphyr

    04/08/2023, 3:34 PM
    Hey, I was reading the docs for durable objects but am still unsure if it fits my use case? Can I use it to store user data?
  • u

    Unsmart | Tech debt

    04/08/2023, 3:48 PM
    You can store anything you want there isn't really any restriction other than if it can fit within the size limit.
  • m

    missphyr

    04/08/2023, 3:48 PM
    Oh okay, so it's like a database?
  • u

    Unsmart | Tech debt

    04/08/2023, 3:49 PM
    Yes it's a NoSQL DB. Most similar to DynamoDB
1...535536537...567Latest