-
-
Save michalmuskala/e503d650718d122fbdb478372b83c46a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule BenchConnection do | |
| def start_link(opts), do: DBConnection.start_link(__MODULE__, opts) | |
| def connect(opts) do | |
| {:ok, opts} | |
| end | |
| def disconnect(_err, _state) do | |
| :ok | |
| end | |
| def checkout(state) do | |
| {:ok, state} | |
| end | |
| def checkin(state) do | |
| {:ok, state} | |
| end | |
| def ping(state) do | |
| {:ok, state} | |
| end | |
| end | |
| Application.ensure_all_started(:sbroker) | |
| {:ok, single_pid} = BenchConnection.start_link(pool: DBConnection.Connection) | |
| {:ok, poolboy_pid} = BenchConnection.start_link(pool: DBConnection.Poolboy) | |
| {:ok, pool_pid} = BenchConnection.start_link(pool: DBConnection.ConnectionPool) | |
| {:ok, sojurn_pid} = BenchConnection.start_link(pool: DBConnection.Sojourn) | |
| jobs = %{ | |
| "connection" => fn flow -> flow.(single_pid, DBConnection.Connection) end, | |
| "poolboy" => fn flow -> flow.(poolboy_pid, DBConnection.Poolboy) end, | |
| "pool" => fn flow -> flow.(pool_pid, DBConnection.ConnectionPool) end, | |
| "sojurn" => fn flow -> flow.(sojurn_pid, DBConnection.Sojourn) end | |
| } | |
| inputs = %{ | |
| "single_run" => fn pid, pool -> | |
| DBConnection.run(pid, fn _ -> nil end, pool: pool) | |
| end, | |
| "parallel_run" => fn pid, pool -> | |
| 1..5 | |
| |> Enum.map(fn _ -> Task.async(fn -> DBConnection.run(pid, fn _ -> Process.sleep(10) end, pool: pool) end) end) | |
| |> Enum.reverse() | |
| |> Enum.map(&Task.await/1) | |
| end, | |
| "overload_run" => fn pid, pool -> | |
| 1..100 | |
| |> Enum.map(fn _ -> Task.async(fn -> DBConnection.run(pid, fn _ -> Process.sleep(10) end, pool: pool) end) end) | |
| |> Enum.reverse() | |
| |> Enum.map(&Task.await/1) | |
| end | |
| } | |
| Benchee.run( | |
| jobs, | |
| inputs: inputs, | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Operating System: macOS | |
| CPU Information: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz | |
| Number of Available Cores: 8 | |
| Available memory: 16 GB | |
| Elixir 1.7.0-dev | |
| Erlang 20.1 | |
| Benchmark suite executing with the following configuration: | |
| warmup: 2 s | |
| time: 5 s | |
| parallel: 1 | |
| inputs: overload_run, parallel_run, single_run | |
| Estimated total run time: 1.40 min | |
| Benchmarking connection with input overload_run... | |
| Benchmarking connection with input parallel_run... | |
| Benchmarking connection with input single_run... | |
| Benchmarking pool with input overload_run... | |
| Benchmarking pool with input parallel_run... | |
| Benchmarking pool with input single_run... | |
| Benchmarking poolboy with input overload_run... | |
| Benchmarking poolboy with input parallel_run... | |
| Benchmarking poolboy with input single_run... | |
| Benchmarking sojurn with input overload_run... | |
| Benchmarking sojurn with input parallel_run... | |
| Benchmarking sojurn with input single_run... | |
| ##### With input overload_run ##### | |
| Name ips average deviation median 99th % | |
| pool 17.78 56.26 ms ±1.03% 56.08 ms 58.39 ms | |
| sojurn 8.95 111.73 ms ±0.61% 111.78 ms 113.23 ms | |
| poolboy 8.93 111.93 ms ±0.69% 111.84 ms 113.81 ms | |
| connection 0.91 1102.18 ms ±0.02% 1102.27 ms 1102.41 ms | |
| Comparison: | |
| pool 17.78 | |
| sojurn 8.95 - 1.99x slower | |
| poolboy 8.93 - 1.99x slower | |
| connection 0.91 - 19.59x slower | |
| ##### With input parallel_run ##### | |
| Name ips average deviation median 99th % | |
| poolboy 90.89 11.00 ms ±1.76% 10.99 ms 11.69 ms | |
| sojurn 90.87 11.00 ms ±1.74% 10.99 ms 11.54 ms | |
| pool 90.66 11.03 ms ±2.15% 10.99 ms 11.71 ms | |
| connection 18.18 55.01 ms ±0.49% 54.99 ms 55.83 ms | |
| Comparison: | |
| poolboy 90.89 | |
| sojurn 90.87 - 1.00x slower | |
| pool 90.66 - 1.00x slower | |
| connection 18.18 - 5.00x slower | |
| ##### With input single_run ##### | |
| Name ips average deviation median 99th % | |
| connection 201.73 K 4.96 μs ±682.68% 5 μs 8 μs | |
| pool 163.88 K 6.10 μs ±598.75% 6 μs 10 μs | |
| poolboy 82.07 K 12.19 μs ±187.54% 11 μs 28 μs | |
| sojurn 64.27 K 15.56 μs ±99.96% 15 μs 30 μs | |
| Comparison: | |
| connection 201.73 K | |
| pool 163.88 K - 1.23x slower | |
| poolboy 82.07 K - 2.46x slower | |
| sojurn 64.27 K - 3.14x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment