summaryrefslogtreecommitdiff
path: root/benchmarks/load_testing
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2020-02-18 12:19:10 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2020-03-30 11:42:25 +0300
commit1f29ecdcd7ecdc4ad8d6bc8fc4c34efbc9b7fe1d (patch)
treefbf9755e8d2a060205ef21511f8d1dc9fe4694b3 /benchmarks/load_testing
parenteb9744cadea7191b088ddaadfbd5fa4d4fd45090 (diff)
downloadpleroma-1f29ecdcd7ecdc4ad8d6bc8fc4c34efbc9b7fe1d.tar.gz
pleroma-1f29ecdcd7ecdc4ad8d6bc8fc4c34efbc9b7fe1d.zip
sync with develop
Diffstat (limited to 'benchmarks/load_testing')
-rw-r--r--benchmarks/load_testing/activities.ex42
-rw-r--r--benchmarks/load_testing/helper.ex11
-rw-r--r--benchmarks/load_testing/users.ex61
3 files changed, 87 insertions, 27 deletions
diff --git a/benchmarks/load_testing/activities.ex b/benchmarks/load_testing/activities.ex
index db0e5a66f..121d5c500 100644
--- a/benchmarks/load_testing/activities.ex
+++ b/benchmarks/load_testing/activities.ex
@@ -85,6 +85,48 @@ defmodule Pleroma.LoadTesting.Activities do
:ok
end
+ def generate_power_intervals(opts \\ []) do
+ count = Keyword.get(opts, :count, 20)
+ power = Keyword.get(opts, :power, 2)
+ IO.puts("Generating #{count} intervals for a power #{power} series...")
+ counts = Enum.map(1..count, fn n -> :math.pow(n, power) end)
+ sum = Enum.sum(counts)
+
+ densities =
+ Enum.map(counts, fn c ->
+ c / sum
+ end)
+
+ densities
+ |> Enum.reduce(0, fn density, acc ->
+ if acc == 0 do
+ [{0, density}]
+ else
+ [{_, lower} | _] = acc
+ [{lower, lower + density} | acc]
+ end
+ end)
+ |> Enum.reverse()
+ end
+
+ def generate_tagged_activities(opts \\ []) do
+ tag_count = Keyword.get(opts, :tag_count, 20)
+ users = Keyword.get(opts, :users, Repo.all(Pleroma.User))
+ activity_count = Keyword.get(opts, :count, 200_000)
+
+ intervals = generate_power_intervals(count: tag_count)
+
+ IO.puts(
+ "Generating #{activity_count} activities using #{tag_count} different tags of format `tag_n`, starting at tag_0"
+ )
+
+ Enum.each(1..activity_count, fn _ ->
+ random = :rand.uniform()
+ i = Enum.find_index(intervals, fn {lower, upper} -> lower <= random && upper > random end)
+ CommonAPI.post(Enum.random(users), %{"status" => "a post with the tag #tag_#{i}"})
+ end)
+ end
+
defp generate_long_thread(visibility, user, friends, non_friends, _opts) do
group =
if visibility == "public",
diff --git a/benchmarks/load_testing/helper.ex b/benchmarks/load_testing/helper.ex
index 23bbb1cec..cab60acb4 100644
--- a/benchmarks/load_testing/helper.ex
+++ b/benchmarks/load_testing/helper.ex
@@ -1,3 +1,14 @@
defmodule Pleroma.LoadTesting.Helper do
+ alias Ecto.Adapters.SQL
+ alias Pleroma.Repo
+
def to_sec(microseconds), do: microseconds / 1_000_000
+
+ def clean_tables do
+ IO.puts("Deleting old data...\n")
+ SQL.query!(Repo, "TRUNCATE users CASCADE;")
+ SQL.query!(Repo, "TRUNCATE activities CASCADE;")
+ SQL.query!(Repo, "TRUNCATE objects CASCADE;")
+ SQL.query!(Repo, "TRUNCATE oban_jobs CASCADE;")
+ end
end
diff --git a/benchmarks/load_testing/users.ex b/benchmarks/load_testing/users.ex
index 951b30d91..bc31dc08b 100644
--- a/benchmarks/load_testing/users.ex
+++ b/benchmarks/load_testing/users.ex
@@ -20,31 +20,31 @@ defmodule Pleroma.LoadTesting.Users do
def generate(opts \\ []) do
opts = Keyword.merge(@defaults, opts)
- IO.puts("Starting generating #{opts[:users]} users...")
-
- {time, _} = :timer.tc(fn -> generate_users(opts[:users]) end)
-
- IO.puts("Generating users take #{to_sec(time)} sec.\n")
+ generate_users(opts[:users])
main_user =
Repo.one(from(u in User, where: u.local == true, order_by: fragment("RANDOM()"), limit: 1))
- IO.puts("Starting making friends for #{opts[:friends]} users...")
- {time, _} = :timer.tc(fn -> make_friends(main_user, opts[:friends]) end)
-
- IO.puts("Making friends take #{to_sec(time)} sec.\n")
+ make_friends(main_user, opts[:friends])
Repo.get(User, main_user.id)
end
- defp generate_users(max) do
- Task.async_stream(
- 1..max,
- &generate_user(&1),
- max_concurrency: @max_concurrency,
- timeout: 30_000
- )
- |> Stream.run()
+ def generate_users(max) do
+ IO.puts("Starting generating #{opts[:users]} users...")
+
+ {time, _} =
+ :timer.tc(fn ->
+ Task.async_stream(
+ 1..max,
+ &generate_user(&1),
+ max_concurrency: @max_concurrency,
+ timeout: 30_000
+ )
+ |> Stream.run()
+ end)
+
+ IO.puts("Generating users take #{to_sec(time)} sec.\n")
end
defp generate_user(i) do
@@ -86,18 +86,25 @@ defmodule Pleroma.LoadTesting.Users do
Map.merge(user, urls)
end
- defp make_friends(main_user, max) when is_integer(max) do
- number_of_users =
- (max / 2)
- |> Kernel.trunc()
+ def make_friends(main_user, max) when is_integer(max) do
+ IO.puts("Starting making friends for #{opts[:friends]} users...")
+
+ {time, _} =
+ :timer.tc(fn ->
+ number_of_users =
+ (max / 2)
+ |> Kernel.trunc()
- main_user
- |> get_users(%{limit: number_of_users, local: :local})
- |> run_stream(main_user)
+ main_user
+ |> get_users(%{limit: number_of_users, local: :local})
+ |> run_stream(main_user)
- main_user
- |> get_users(%{limit: number_of_users, local: :external})
- |> run_stream(main_user)
+ main_user
+ |> get_users(%{limit: number_of_users, local: :external})
+ |> run_stream(main_user)
+ end)
+
+ IO.puts("Making friends take #{to_sec(time)} sec.\n")
end
defp make_friends(%User{} = main_user, %User{} = user) do