Caching DB requests with ETS

This episode is part 6 in a Phoenix CMS series:

  • Series Overview - Planning
  • Part 1 - Setting up schemas, contexts and ecto relations
  • Part 2 - Editing multiple tags at once as a list
  • Part 3 - Listing mixed forms of content together for topics
  • Part 4 - Setting up meta tags for SEO
  • Part 5 - Making content-specific markdown extensions
  • Part 6 - Using ETS to cache information and speed up the site <hr />

Last time we did some simple Phoenix performance tweaks to make the homepage performant enough to handle over a thousand requests per second.

But on pages that do significant numbers of database queries, we need something more.

An OTP in-memory data store (6:02)

The greatest thing about Elixir is all the Erlang and OTP tools we get automatically. Here's a look at how to use Erlang Term Storage to cache database requests and improve Phoenix's already impressive performance.

Final result

The Episodes page is now sped up to 275 requests a second on a $5/month server.

Note that this app is compiling Markdown inline and has some other CMS-like features. With just standard EEx templates, performance is around 1k requests per second. Instead of demoing something built specifically to win on a benchmark, the goal here was to show a real-world app with shortcuts taken for the sake of productivity and see how it could do on a bottom-tier VPS offering.

Update: There was a thread about this video on elixirforum.com, so I made another video as a response to community feedback.

Back to index

No Comments