use in timelines benchmark new user generator

This commit is contained in:
Alexander Strizhakov 2020-03-30 11:59:14 +03:00
parent 56503c385e
commit 96e2796557
No known key found for this signature in database
GPG Key ID: 022896A53AEF1381
3 changed files with 14 additions and 19 deletions

View File

@ -81,7 +81,7 @@ def generate(user, opts \\ []) do
) )
end) end)
IO.puts("Generating iterations of activities take #{to_sec(time)} sec.\n") IO.puts("Generating iterations of activities took #{to_sec(time)} sec.\n")
:ok :ok
end end

View File

@ -33,7 +33,7 @@ def generate(opts \\ []) do
def generate_users(max) do def generate_users(max) do
IO.puts("Starting generating #{max} users...") IO.puts("Starting generating #{max} users...")
{time, _} = {time, users} =
:timer.tc(fn -> :timer.tc(fn ->
Task.async_stream( Task.async_stream(
1..max, 1..max,
@ -41,10 +41,11 @@ def generate_users(max) do
max_concurrency: @max_concurrency, max_concurrency: @max_concurrency,
timeout: 30_000 timeout: 30_000
) )
|> Stream.run() |> Enum.to_list()
end) end)
IO.puts("Generating users take #{to_sec(time)} sec.\n") IO.puts("Generating users took #{to_sec(time)} sec.\n")
users
end end
defp generate_user(i) do defp generate_user(i) do
@ -104,7 +105,7 @@ def make_friends(main_user, max) when is_integer(max) do
|> run_stream(main_user) |> run_stream(main_user)
end) end)
IO.puts("Making friends take #{to_sec(time)} sec.\n") IO.puts("Making friends took #{to_sec(time)} sec.\n")
end end
def make_friends(%User{} = main_user, %User{} = user) do def make_friends(%User{} = main_user, %User{} = user) do

View File

@ -1,9 +1,10 @@
defmodule Mix.Tasks.Pleroma.Benchmarks.Timelines do defmodule Mix.Tasks.Pleroma.Benchmarks.Timelines do
use Mix.Task use Mix.Task
alias Pleroma.Repo
alias Pleroma.LoadTesting.Generator import Pleroma.LoadTesting.Helper, only: [clean_tables: 0]
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Plug.Conn
def run(_args) do def run(_args) do
Mix.Pleroma.start_pleroma() Mix.Pleroma.start_pleroma()
@ -11,7 +12,7 @@ def run(_args) do
# Cleaning tables # Cleaning tables
clean_tables() clean_tables()
[{:ok, user} | users] = Generator.generate_users(users_max: 1000) [{:ok, user} | users] = Pleroma.LoadTesting.Users.generate_users(1000)
# Let the user make 100 posts # Let the user make 100 posts
@ -38,8 +39,8 @@ def run(_args) do
"user timeline, no followers" => fn reading_user -> "user timeline, no followers" => fn reading_user ->
conn = conn =
Phoenix.ConnTest.build_conn() Phoenix.ConnTest.build_conn()
|> Plug.Conn.assign(:user, reading_user) |> Conn.assign(:user, reading_user)
|> Plug.Conn.assign(:skip_link_headers, true) |> Conn.assign(:skip_link_headers, true)
Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{"id" => user.id}) Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{"id" => user.id})
end end
@ -56,8 +57,8 @@ def run(_args) do
"user timeline, all following" => fn reading_user -> "user timeline, all following" => fn reading_user ->
conn = conn =
Phoenix.ConnTest.build_conn() Phoenix.ConnTest.build_conn()
|> Plug.Conn.assign(:user, reading_user) |> Conn.assign(:user, reading_user)
|> Plug.Conn.assign(:skip_link_headers, true) |> Conn.assign(:skip_link_headers, true)
Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{"id" => user.id}) Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{"id" => user.id})
end end
@ -66,11 +67,4 @@ def run(_args) do
time: 60 time: 60
) )
end end
defp clean_tables do
IO.puts("Deleting old data...\n")
Ecto.Adapters.SQL.query!(Repo, "TRUNCATE users CASCADE;")
Ecto.Adapters.SQL.query!(Repo, "TRUNCATE activities CASCADE;")
Ecto.Adapters.SQL.query!(Repo, "TRUNCATE objects CASCADE;")
end
end end