Stampede - load testing Phoenix Channels and LiveView from Elixir

Hi everyone,

I’ve been building Stampede, a load testing library for Phoenix apps. Load tests are plain Elixir modules, and it speaks the Channels and LiveView protocols itself, so you don’t have to rebuild joins, refs, heartbeats or the LiveView CSRF dance by hand like you do with k6 or Tsung.

A LiveView test looks like this:

defmodule MyApp.Load.Counter do
  use Stampede.Scenario

  @impl true
  def options do
    [vus: 500, duration: [minute: 1], thresholds: [{"live.event", p95: 100}]]
  end

  @impl true
  def run(_vu) do
    {:ok, view} = Stampede.LiveView.connect("http://localhost:4000/counter")
    {:ok, _reply} = Stampede.LiveView.click(view, "inc")
    Process.sleep(1_000)
  end
end
$ mix stampede.run loadtest/counter.exs --html report.html

connect/2 loads the page like a browser, keeps cookies, follows redirects and joins with the page’s tokens. From there you can click, change, submit, patch and navigate.

What else is in there:

  • Phoenix Channels: join, push, cast, await broadcasts, both serializers
  • HTTP with keep-alive, and plain WebSockets
  • VUs with stages, or a fixed arrival rate
  • checks and thresholds, so mix stampede.run can fail CI
  • percentiles within 1%, a per-second timeline, JSON and HTML reports
  • mix stampede.compare to catch regressions between two runs
  • splitting one test across several nodes

On my laptop, with the server on the same machine, it held 3,000 LiveView users, and 6,000 channel users split over 3 nodes, without errors.

the API can still change, which is why I’m posting now. If you try it against your app, I’d really like to hear what breaks or what’s missing.

Hex: stampede | Hex
Docs: https://stampede.hexdocs.pm
GitHub:

1 Like

I’ve been load testing a single Phoenix server on AWS with Stampede, and it just held 2,000,000 users with 0 errors on one 16-core machine.

The setup

  • Server: one r7g.4xlarge (16 Graviton cores, 128 GB) running a fresh mix phx.new app on Bandit. The only changes were Bandit’s connection limit and listen backlog, plus OS limits like open files.
  • Load: eight r7g.xlarge machines running Stampede over Erlang distribution, each connecting from 14 extra private addresses to get past the ~64k ports per address.
  • Users: each one behaves like the Phoenix JS client. It joins room:lobby, sends a heartbeat every 30 seconds and a message every 30 to 60, and stays.
  • Steps: --find-limit, starting at 1M and adding 250k per step, ramping over 250 seconds and holding for 60. A step passes only with joins and messages under 1s at p95 and 0 errors.

Results

Users Server CPU Server memory
1,000,000 37–48% 52 GB held
1,250,000 47–52% 64 GB held
1,500,000 54–60% 77 GB held
1,750,000 67–71% 90 GB held
2,000,000 78–84% 103 GB held
2,250,000 out of CPU failed

The first error came at 2,067,672 users, while ramping to the next step, so 2,000,000 is the number. The kernel’s own count peaked at 2.1 million established connections, and AWS’s connection tracking limit was never hit.

Memory came to about 51 KB per user, everything included, so 128 GB would have room for more. CPU was the limit: at 2 million users the heartbeats and messages alone are well over 100,000 a second.

Compared to 2015

The well-known Phoenix result is the core team’s 2 million connections in 2015, on a 40-core, 128 GB machine. Those connections joined a channel and then sat idle. This run used 16 cores, and every user was sending heartbeats and messages, so it’s a harder test on less than half the cores. It isn’t a strict apples-to-apples comparison, since the hardware and the Erlang and Phoenix versions are all a decade apart, but it’s nice to see how far the BEAM has come.

Everything to rerun it is in bench/million in the repo, with the logs and numbers from this run: GitHub - mandar1045/stampede: Load testing for Phoenix: Channels, LiveView, HTTP and WebSockets, in plain Elixir · GitHub

I’d love to hear what you’d measure next. I’m thinking LiveView at this scale.

2 Likes