2020-03-23 11:56:01 -06:00
|
|
|
defmodule Mix.Tasks.Pleroma.Benchmarks.Timelines do
|
|
|
|
use Mix.Task
|
2020-03-30 02:59:14 -06:00
|
|
|
|
|
|
|
import Pleroma.LoadTesting.Helper, only: [clean_tables: 0]
|
2020-03-23 11:56:01 -06:00
|
|
|
|
|
|
|
alias Pleroma.Web.CommonAPI
|
2020-03-30 02:59:14 -06:00
|
|
|
alias Plug.Conn
|
2020-03-23 11:56:01 -06:00
|
|
|
|
|
|
|
def run(_args) do
|
|
|
|
Mix.Pleroma.start_pleroma()
|
|
|
|
|
|
|
|
# Cleaning tables
|
|
|
|
clean_tables()
|
|
|
|
|
2020-03-30 02:59:14 -06:00
|
|
|
[{:ok, user} | users] = Pleroma.LoadTesting.Users.generate_users(1000)
|
2020-03-23 11:56:01 -06:00
|
|
|
|
|
|
|
# Let the user make 100 posts
|
|
|
|
|
|
|
|
1..100
|
2021-12-08 10:54:41 -07:00
|
|
|
|> Enum.each(fn i -> CommonAPI.post(user, %{status: to_string(i)}) end)
|
2020-03-23 11:56:01 -06:00
|
|
|
|
|
|
|
# Let 10 random users post
|
|
|
|
posts =
|
|
|
|
users
|
|
|
|
|> Enum.take_random(10)
|
|
|
|
|> Enum.map(fn {:ok, random_user} ->
|
2021-12-08 10:54:41 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(random_user, %{status: "."})
|
2020-03-23 11:56:01 -06:00
|
|
|
activity
|
|
|
|
end)
|
|
|
|
|
|
|
|
# let our user repeat them
|
|
|
|
posts
|
|
|
|
|> Enum.each(fn activity ->
|
|
|
|
CommonAPI.repeat(activity.id, user)
|
|
|
|
end)
|
|
|
|
|
|
|
|
Benchee.run(
|
|
|
|
%{
|
|
|
|
"user timeline, no followers" => fn reading_user ->
|
|
|
|
conn =
|
|
|
|
Phoenix.ConnTest.build_conn()
|
2020-03-30 02:59:14 -06:00
|
|
|
|> Conn.assign(:user, reading_user)
|
|
|
|
|> Conn.assign(:skip_link_headers, true)
|
2020-03-23 11:56:01 -06:00
|
|
|
|
2021-12-08 10:54:41 -07:00
|
|
|
Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{id: user.id})
|
2020-03-23 11:56:01 -06:00
|
|
|
end
|
|
|
|
},
|
|
|
|
inputs: %{"user" => user, "no user" => nil},
|
|
|
|
time: 60
|
|
|
|
)
|
|
|
|
|
|
|
|
users
|
2021-12-08 10:54:41 -07:00
|
|
|
|> Enum.each(fn {:ok, follower} -> Pleroma.User.follow(follower, user) end)
|
2020-03-23 11:56:01 -06:00
|
|
|
|
|
|
|
Benchee.run(
|
|
|
|
%{
|
|
|
|
"user timeline, all following" => fn reading_user ->
|
|
|
|
conn =
|
|
|
|
Phoenix.ConnTest.build_conn()
|
2020-03-30 02:59:14 -06:00
|
|
|
|> Conn.assign(:user, reading_user)
|
|
|
|
|> Conn.assign(:skip_link_headers, true)
|
2020-03-23 11:56:01 -06:00
|
|
|
|
2021-12-08 10:54:41 -07:00
|
|
|
Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{id: user.id})
|
2020-03-23 11:56:01 -06:00
|
|
|
end
|
|
|
|
},
|
|
|
|
inputs: %{"user" => user, "no user" => nil},
|
|
|
|
time: 60
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|