akkoma/benchmarks/load_testing/fetcher.ex

261 lines
7.9 KiB
Elixir
Raw Normal View History

2019-08-02 12:33:12 -06:00
defmodule Pleroma.LoadTesting.Fetcher do
use Pleroma.LoadTesting.Helper
def fetch_user(user) do
2019-09-04 11:18:11 -06:00
Benchee.run(%{
"By id" => fn -> Repo.get_by(User, id: user.id) end,
"By ap_id" => fn -> Repo.get_by(User, ap_id: user.ap_id) end,
"By email" => fn -> Repo.get_by(User, email: user.email) end,
"By nickname" => fn -> Repo.get_by(User, nickname: user.nickname) end
})
2019-08-02 12:33:12 -06:00
end
def query_timelines(user) do
2019-09-04 11:18:11 -06:00
home_timeline_params = %{
2019-08-02 12:33:12 -06:00
"count" => 20,
"with_muted" => true,
"type" => ["Create", "Announce"],
"blocking_user" => user,
"muting_user" => user,
"user" => user
}
2019-09-04 11:18:11 -06:00
mastodon_public_timeline_params = %{
2019-08-02 12:33:12 -06:00
"count" => 20,
"local_only" => true,
"only_media" => "false",
"type" => ["Create", "Announce"],
"with_muted" => "true",
"blocking_user" => user,
"muting_user" => user
}
2019-09-04 11:18:11 -06:00
mastodon_federated_timeline_params = %{
2019-08-02 12:33:12 -06:00
"count" => 20,
"only_media" => "false",
"type" => ["Create", "Announce"],
"with_muted" => "true",
"blocking_user" => user,
"muting_user" => user
}
2019-10-21 02:55:28 -06:00
following = User.following(user)
2019-09-04 11:18:11 -06:00
Benchee.run(%{
"User home timeline" => fn ->
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
2019-10-21 02:55:28 -06:00
following,
2019-09-04 11:18:11 -06:00
home_timeline_params
)
end,
"User mastodon public timeline" => fn ->
2019-09-05 07:01:52 -06:00
Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
mastodon_public_timeline_params
)
2019-09-04 11:18:11 -06:00
end,
"User mastodon federated public timeline" => fn ->
2019-09-05 07:01:52 -06:00
Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
mastodon_federated_timeline_params
)
end
})
home_activities =
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
2019-10-21 02:55:28 -06:00
following,
2019-09-05 07:01:52 -06:00
home_timeline_params
)
public_activities =
Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(mastodon_public_timeline_params)
public_federated_activities =
Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
mastodon_federated_timeline_params
)
Benchee.run(%{
"Rendering home timeline" => fn ->
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
activities: home_activities,
for: user,
as: :activity
})
end,
"Rendering public timeline" => fn ->
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
activities: public_activities,
for: user,
as: :activity
})
end,
"Rendering public federated timeline" => fn ->
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
activities: public_federated_activities,
for: user,
as: :activity
})
2019-11-19 11:11:15 -07:00
end,
"Rendering favorites timeline" => fn ->
2019-11-22 04:17:12 -07:00
conn = Phoenix.ConnTest.build_conn(:get, "http://localhost:4001/api/v1/favourites", nil)
Pleroma.Web.MastodonAPI.StatusController.favourites(
%Plug.Conn{conn |
assigns: %{user: user},
query_params: %{"limit" => "0"},
body_params: %{},
cookies: %{},
params: %{},
path_params: %{},
private: %{
Pleroma.Web.Router => {[], %{}},
phoenix_router: Pleroma.Web.Router,
phoenix_action: :favourites,
phoenix_controller: Pleroma.Web.MastodonAPI.StatusController,
phoenix_endpoint: Pleroma.Web.Endpoint,
phoenix_format: "json",
phoenix_layout: {Pleroma.Web.LayoutView, "app.html"},
phoenix_recycled: true,
phoenix_view: Pleroma.Web.MastodonAPI.StatusView,
plug_session: %{"user_id" => user.id},
plug_session_fetch: :done,
plug_session_info: :write,
plug_skip_csrf_protection: true
}
},
%{})
2019-11-19 11:11:15 -07:00
end,
2019-09-04 11:18:11 -06:00
})
2019-08-02 12:33:12 -06:00
end
def query_notifications(user) do
2019-09-04 11:18:11 -06:00
without_muted_params = %{"count" => "20", "with_muted" => "false"}
with_muted_params = %{"count" => "20", "with_muted" => "true"}
Benchee.run(%{
"Notifications without muted" => fn ->
Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
end,
"Notifications with muted" => fn ->
Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
end
})
2019-09-05 07:01:52 -06:00
without_muted_notifications =
Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
with_muted_notifications =
Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
Benchee.run(%{
"Render notifications without muted" => fn ->
Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
notifications: without_muted_notifications,
for: user
})
end,
"Render notifications with muted" => fn ->
Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
notifications: with_muted_notifications,
for: user
})
end
})
2019-09-04 11:18:11 -06:00
end
2019-08-02 12:33:12 -06:00
2019-09-04 11:18:11 -06:00
def query_dms(user) do
params = %{
"count" => "20",
"with_muted" => "true",
"type" => "Create",
"blocking_user" => user,
"user" => user,
visibility: "direct"
}
2019-08-02 12:33:12 -06:00
2019-09-04 11:18:11 -06:00
Benchee.run(%{
"Direct messages with muted" => fn ->
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
|> Pleroma.Pagination.fetch_paginated(params)
end,
"Direct messages without muted" => fn ->
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
|> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
end
})
2019-09-05 07:01:52 -06:00
dms_with_muted =
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
|> Pleroma.Pagination.fetch_paginated(params)
dms_without_muted =
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
|> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
Benchee.run(%{
"Rendering dms with muted" => fn ->
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
activities: dms_with_muted,
for: user,
as: :activity
})
end,
"Rendering dms without muted" => fn ->
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
activities: dms_without_muted,
for: user,
as: :activity
})
end
})
2019-08-02 12:33:12 -06:00
end
def query_long_thread(user, activity) do
2019-09-04 11:18:11 -06:00
Benchee.run(%{
2019-09-05 07:01:52 -06:00
"Fetch main post" => fn ->
Pleroma.Activity.get_by_id_with_object(activity.id)
end,
2019-09-04 11:18:11 -06:00
"Fetch context of main post" => fn ->
2019-08-02 12:33:12 -06:00
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
activity.data["context"],
%{
"blocking_user" => user,
2019-09-04 11:18:11 -06:00
"user" => user,
"exclude_id" => activity.id
2019-08-02 12:33:12 -06:00
}
)
2019-09-04 11:18:11 -06:00
end
})
2019-09-05 07:01:52 -06:00
activity = Pleroma.Activity.get_by_id_with_object(activity.id)
context =
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
activity.data["context"],
%{
"blocking_user" => user,
"user" => user,
"exclude_id" => activity.id
}
)
Benchee.run(%{
"Render status" => fn ->
2019-10-15 07:26:04 -06:00
Pleroma.Web.MastodonAPI.StatusView.render("show.json", %{
2019-09-05 07:01:52 -06:00
activity: activity,
for: user
})
end,
2019-09-06 11:14:02 -06:00
"Render context" => fn ->
2019-09-05 07:01:52 -06:00
Pleroma.Web.MastodonAPI.StatusView.render(
"index.json",
for: user,
activities: context,
as: :activity
)
|> Enum.reverse()
end
})
2019-08-02 12:33:12 -06:00
end
end