def generate_users(max) do
IO.puts("Starting generating #{max} users...")
- {time, _} =
+ {time, users} =
:timer.tc(fn ->
Task.async_stream(
1..max,
max_concurrency: @max_concurrency,
timeout: 30_000
)
- |> Stream.run()
+ |> Enum.to_list()
end)
- IO.puts("Generating users take #{to_sec(time)} sec.\n")
+ IO.puts("Generating users took #{to_sec(time)} sec.\n")
+ users
end
defp generate_user(i) do
|> run_stream(main_user)
end)
- IO.puts("Making friends take #{to_sec(time)} sec.\n")
+ IO.puts("Making friends took #{to_sec(time)} sec.\n")
end
def make_friends(%User{} = main_user, %User{} = user) do
defmodule Mix.Tasks.Pleroma.Benchmarks.Timelines do
use Mix.Task
- alias Pleroma.Repo
- alias Pleroma.LoadTesting.Generator
+
+ import Pleroma.LoadTesting.Helper, only: [clean_tables: 0]
alias Pleroma.Web.CommonAPI
+ alias Plug.Conn
def run(_args) do
Mix.Pleroma.start_pleroma()
# Cleaning 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
"user timeline, no followers" => fn reading_user ->
conn =
Phoenix.ConnTest.build_conn()
- |> Plug.Conn.assign(:user, reading_user)
- |> Plug.Conn.assign(:skip_link_headers, true)
+ |> Conn.assign(:user, reading_user)
+ |> Conn.assign(:skip_link_headers, true)
Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{"id" => user.id})
end
"user timeline, all following" => fn reading_user ->
conn =
Phoenix.ConnTest.build_conn()
- |> Plug.Conn.assign(:user, reading_user)
- |> Plug.Conn.assign(:skip_link_headers, true)
+ |> Conn.assign(:user, reading_user)
+ |> Conn.assign(:skip_link_headers, true)
Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{"id" => user.id})
end
time: 60
)
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