Skip to content

Commit

Permalink
chore: benchmark rules routing (#2095)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziinc authored Jun 18, 2024
1 parent 0584778 commit 967399b
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/logflare/backends_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ defmodule Logflare.BackendsTest do
alias Logflare.Backends.Backend
alias Logflare.Backends.SourceSup
alias Logflare.Source
alias Logflare.Sources
alias Logflare.Source.RecentLogsServer
alias Logflare.SystemMetrics.AllLogsLogged
alias Logflare.Source.ChannelTopics
alias Logflare.Lql
alias Logflare.Logs
alias Logflare.Source.V1SourceSup
alias Logflare.PubSubRates
alias Logflare.Logs.SourceRouting

setup do
start_supervised!(AllLogsLogged)
Expand Down Expand Up @@ -376,5 +378,50 @@ defmodule Logflare.BackendsTest do
formatters: [{Benchee.Formatters.Console, extended_statistics: true}]
)
end

# This benchmarks two areas:
# - rules dispatching, with and without any rules
@tag :benchmark
test "backend rules routing benchmarking", %{user: user} do
backend = insert(:backend, user: user)
[source1, source2] = insert_pair(:source, user: user, rules: [])

rules =
for _ <- 1..250 do
insert(:rule, source: source2, backend: backend, lql_string: "message")
end

source2 = Sources.preload_defaults(source2)

# start_supervised!({Pipeline, [rls, name: @pipeline_name]})
start_supervised!({SourceSup, source1}, id: :no_rules)
start_supervised!({SourceSup, source2}, id: :with_rules)

batch1 =
for _i <- 1..250 do
build(:log_event, source: source1, message: "some message")
end

batch2 =
for _i <- 1..250 do
build(:log_event, source: source2, message: "some message")
end

Benchee.run(
%{
"with rules" => fn ->
SourceRouting.route_to_sinks_and_ingest(batch1)
end,
"100 rules" => fn ->
SourceRouting.route_to_sinks_and_ingest(batch2)
end
},
time: 3,
warmup: 1,
print: [configuration: false],
# use extended_statistics to view units of work done
formatters: [{Benchee.Formatters.Console, extended_statistics: true}]
)
end
end
end

0 comments on commit 967399b

Please sign in to comment.