summaryrefslogtreecommitdiff
path: root/benchmarks/load_testing/fetcher.ex
diff options
context:
space:
mode:
authorAlex S <alex.strizhakov@gmail.com>2019-09-19 14:02:27 +0300
committerAlex S <alex.strizhakov@gmail.com>2019-09-19 14:02:27 +0300
commit1d285e6fada841b6959b6516aca1c84d1a2c9b93 (patch)
tree3ec8c8df19fd8f21047cb55051c03da6d6de1980 /benchmarks/load_testing/fetcher.ex
parent924d7e6aa60095e27c15b4a5f473a192ab2b42ef (diff)
downloadpleroma-1d285e6fada841b6959b6516aca1c84d1a2c9b93.tar.gz
pleroma-1d285e6fada841b6959b6516aca1c84d1a2c9b93.zip
moving to separate dir
Diffstat (limited to 'benchmarks/load_testing/fetcher.ex')
-rw-r--r--benchmarks/load_testing/fetcher.ex229
1 files changed, 229 insertions, 0 deletions
diff --git a/benchmarks/load_testing/fetcher.ex b/benchmarks/load_testing/fetcher.ex
new file mode 100644
index 000000000..0ff2f28c0
--- /dev/null
+++ b/benchmarks/load_testing/fetcher.ex
@@ -0,0 +1,229 @@
+defmodule Pleroma.LoadTesting.Fetcher do
+ use Pleroma.LoadTesting.Helper
+
+ def fetch_user(user) do
+ 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
+ })
+ end
+
+ def query_timelines(user) do
+ home_timeline_params = %{
+ "count" => 20,
+ "with_muted" => true,
+ "type" => ["Create", "Announce"],
+ "blocking_user" => user,
+ "muting_user" => user,
+ "user" => user
+ }
+
+ mastodon_public_timeline_params = %{
+ "count" => 20,
+ "local_only" => true,
+ "only_media" => "false",
+ "type" => ["Create", "Announce"],
+ "with_muted" => "true",
+ "blocking_user" => user,
+ "muting_user" => user
+ }
+
+ mastodon_federated_timeline_params = %{
+ "count" => 20,
+ "only_media" => "false",
+ "type" => ["Create", "Announce"],
+ "with_muted" => "true",
+ "blocking_user" => user,
+ "muting_user" => user
+ }
+
+ Benchee.run(%{
+ "User home timeline" => fn ->
+ Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
+ [user.ap_id | user.following],
+ home_timeline_params
+ )
+ end,
+ "User mastodon public timeline" => fn ->
+ Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
+ mastodon_public_timeline_params
+ )
+ end,
+ "User mastodon federated public timeline" => fn ->
+ Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
+ mastodon_federated_timeline_params
+ )
+ end
+ })
+
+ home_activities =
+ Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
+ [user.ap_id | user.following],
+ 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
+ })
+ end
+ })
+ end
+
+ def query_notifications(user) do
+ 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
+ })
+
+ 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
+ })
+ end
+
+ def query_dms(user) do
+ params = %{
+ "count" => "20",
+ "with_muted" => "true",
+ "type" => "Create",
+ "blocking_user" => user,
+ "user" => user,
+ visibility: "direct"
+ }
+
+ 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
+ })
+
+ 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
+ })
+ end
+
+ def query_long_thread(user, activity) do
+ Benchee.run(%{
+ "Fetch main post" => fn ->
+ Pleroma.Activity.get_by_id_with_object(activity.id)
+ end,
+ "Fetch context of main post" => fn ->
+ Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
+ activity.data["context"],
+ %{
+ "blocking_user" => user,
+ "user" => user,
+ "exclude_id" => activity.id
+ }
+ )
+ end
+ })
+
+ 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 ->
+ Pleroma.Web.MastodonAPI.StatusView.render("status.json", %{
+ activity: activity,
+ for: user
+ })
+ end,
+ "Render context" => fn ->
+ Pleroma.Web.MastodonAPI.StatusView.render(
+ "index.json",
+ for: user,
+ activities: context,
+ as: :activity
+ )
+ |> Enum.reverse()
+ end
+ })
+ end
+end