Coder Social home page Coder Social logo

State is persistent ? about triotp HOT 1 CLOSED

jbjuin avatar jbjuin commented on August 29, 2024
State is persistent ?

from triotp.

Comments (1)

linkdd avatar linkdd commented on August 29, 2024

Hello @jbjuin

Thanks for the feedback 😄

I think you're talking about the state of a gen_server. In that case, no the state is not restored (same for the real OTP).

The state of a gen_server is temporary and lives only in memory. It's very common to have a connection handle to a database as state for example. If a temporary network failure occurs, the gen_server will crash and be restarted by the parent supervisor, creating a new connection (successfully once the temporary network failure is resolved).

If you need persistance, the real OTP gives you:

  • ETS (Erlang Term Storage), an in-memory key/value store that runs in its own process (or task)
  • DETS (Distributed ETS), which is replicated/balanced over the cluster. We can't do that here, this library does not support clustering (yet???)
  • Mnesia, which is based on DETS and allows on-disk persistance (if you know RabbitMQ, that's what they use to store the messages)

Yes, in the Erlang/Elixir world you don't need Redis 😉

TL;DR: If you need persistance over restarts, you should rely on an external service like Redis, Memcached, or a database, and hold the connection to this service in the gen_server's state

from triotp.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.