hey all, have a q regarding DO eviction

hey all, have a q regarding DO eviction. is it true that DO lives at least 30 seconds? (I understand there could be edge cases like DO redeploy, I but I mean a normal scenarios) Basically I want to store some data, which I want to live at least 30 seconds and at maximum 90 seconds. So I’m thinking not to store it in the storage but to rely on eviction mechanics, to not bother with storage cleaning or there’s no guarantees and DO can be evicted even after 10 seconds of inactivity?
3 Replies
Milan
Milan5mo ago
DOs can be evicted at any time. Assuming normal operations, your request is given up to 30 seconds of CPU time, walltime may be significantly longer. If your DO isn't doing anything it will be evicted in 10 seconds. You can extend its lifetime by either doing work or waiting on future work (i.e. await a fetch(), setInterval/setTimeout, receiving new requests like incoming fetch/rpc/alarm/webSocketMessage etc). In this case I think you should be able to save your data in storage then set an alarm to delete it in 30+ seconds. If you keep your data in memory, there's really no guarantee it'll survive for any duration because of random events (like power loss to the machine), but if you're fine with accepting the loss of this data occasionally then you can probably keep it in memory and find a way to keep your DO alive a little longer (there's many ways)
nick
nickOP5mo ago
Thanks! makes total sense. for some reason I thought that DO lives at least 30 secs Sounds really good, I'm ok loosing this data on case of random events, so I think i'll periodically send pings to extend it's lifetime Thanks for your help, details about eviction rules are the most missing piece in the docs 🙂
Milan
Milan5mo ago
Agreed, I don't think eviction behavior will be changing any time soon, so we should make it very clear what y'all can expect from your DOs
Want results from more Discord servers?
Add your server