File size: 728 Bytes
8da2481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
defmodule Plausible.Session.BalancerSupervisor do
  @moduledoc "Serialize session processing to avoid explicit locks"
  use Supervisor

  if Mix.env() in [:test, :ce_test, :e2e_test] do
    def size(),
      do: 10
  else
    def size(), do: 100
  end

  def start_link(_) do
    Supervisor.start_link(__MODULE__, size(), name: __MODULE__)
  end

  def init(size) do
    children =
      for id <- 1..size do
        %{
          id: id,
          start: {Plausible.Session.Balancer, :start_link, [id]},
          restart: :permanent
        }
      end

    Supervisor.init(
      [
        {Registry, [keys: :unique, name: Plausible.Session.Balancer.Registry]} | children
      ],
      strategy: :one_for_one
    )
  end
end