Skip to content

Commit

Permalink
Increase benchmark scale and add performant index example
Browse files Browse the repository at this point in the history
  • Loading branch information
bnauta committed Sep 13, 2018
1 parent 1f94229 commit 1f4338d
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions benchmarks/jobs_table_indexing.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
defmodule Rihanna.JobsTableIndexing do
@moduledoc """
Benchmark to compare the affect of an index applied to the Rihanna jobs table.
Benchmark to compare the affect of indexes applied to the Rihanna jobs table.
Note that indexes introduce a performance overhead on table write - for truly
high-scale performance it may be necessary to further tune the job fetching SQL.
To run this benchmark:
Expand All @@ -10,10 +13,26 @@ defmodule Rihanna.JobsTableIndexing do
def benchmark do
Benchee.run(
%{
"with index" => {
"with poll index" => {
&lock_job/1,
before_scenario: fn %{pg: pg} = input ->
create_poll_index(pg)
input
end
},
"with comparison/sort index" => {
&lock_job/1,
before_scenario: fn %{pg: pg} = input ->
create_index(pg)
create_comparison_and_sort_index(pg)
input
end
},
# not advisable to create two indexes, introducing two performance hits
"with poll and comparison/sort indexes" => {
&lock_job/1,
before_scenario: fn %{pg: pg} = input ->
create_poll_index(pg)
create_comparison_and_sort_index(pg)
input
end
},
Expand All @@ -28,7 +47,8 @@ defmodule Rihanna.JobsTableIndexing do
"10 x ready, scheduled, due, and failed jobs" => 10,
"100 x ready, scheduled, due, and failed jobs" => 100,
"1,000 x ready, scheduled, due, and failed jobs" => 1_000,
"10,000 x ready, scheduled, due, and failed jobs" => 10_000
"10,000 x ready, scheduled, due, and failed jobs" => 10_000,
"100,000 x ready, scheduled, due, and failed jobs" => 100_000
},
time: 5,

Expand Down Expand Up @@ -73,7 +93,7 @@ defmodule Rihanna.JobsTableIndexing do
end
end

defp create_index(pg) do
defp create_poll_index(pg) do
Postgrex.query!(
pg,
"""
Expand All @@ -84,6 +104,16 @@ defmodule Rihanna.JobsTableIndexing do
)
end

defp create_comparison_and_sort_index(pg) do
Postgrex.query!(
pg,
"""
CREATE INDEX rihanna_comparison_and_sort_idx ON rihanna_jobs (enqueued_at ASC, id ASC);
""",
[]
)
end

defp recreate_jobs_table do
{:ok, %{pg: pg}} = TestHelper.create_jobs_table([])

Expand Down

0 comments on commit 1f4338d

Please sign in to comment.