Utilizing Presence and ETS to make our app more robust

As we start scaling our application, we'll very quickly find that in Phoenix applications, the bottleneck moves away from what our connections are doing and how long they're sitting around for and moves toward the database. In addition, the concept of determining the state of connections (when they are established, how long they've been active, what their current state is, and so on) becomes a more important question to answer. The good news is that Elixir and Phoenix both have built-in tools that you get for free that allow you to solve these problems!

Elixir provides access to ETS through the :ets namespace. This allows you to create tables, insert/retrieve/delete data, and so on. ETS specifically stores any information you enter into it in memory, which means any access to it is incredibly fast!

In addition, Phoenix provides access to Presence, which allows you to track and update the existence of connections. You can think of this as a list of users in a chat application—you'll want to store who is online, who is not, and what the status is for each of those users. That's the kind of feature that is almost just assumed at this point, so we'll want to include it as part of our application's chat system.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset