From 1fcd579b6d8c26557dcc6f9d3c9f247d03e7b5a4 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Tue, 19 Nov 2019 21:11:15 +0300 Subject: [PATCH 1/2] benchmarks/ added favourites timeline --- benchmarks/load_testing/fetcher.ex | 13 ++++++++++++- benchmarks/load_testing/generator.ex | 18 ++++++++++++++++++ benchmarks/mix/tasks/pleroma/load_testing.ex | 4 ++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/benchmarks/load_testing/fetcher.ex b/benchmarks/load_testing/fetcher.ex index cdc073b2e..776105d34 100644 --- a/benchmarks/load_testing/fetcher.ex +++ b/benchmarks/load_testing/fetcher.ex @@ -57,6 +57,9 @@ def query_timelines(user) do Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities( mastodon_federated_timeline_params ) + end, + "User favourites timeline" => fn -> + Pleroma.Web.ActivityPub.ActivityPub.fetch_favourites(user) end }) @@ -74,6 +77,8 @@ def query_timelines(user) do mastodon_federated_timeline_params ) + user_favourites = Pleroma.Web.ActivityPub.ActivityPub.fetch_favourites(user) + Benchee.run(%{ "Rendering home timeline" => fn -> Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{ @@ -95,7 +100,13 @@ def query_timelines(user) do for: user, as: :activity }) - end + end, + "Rendering favorites timeline" => fn -> + Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{ + activities: user_favourites, + for: user, + as: :activity}) + end, }) end diff --git a/benchmarks/load_testing/generator.ex b/benchmarks/load_testing/generator.ex index b4432bdb7..f42fd363e 100644 --- a/benchmarks/load_testing/generator.ex +++ b/benchmarks/load_testing/generator.ex @@ -2,6 +2,24 @@ defmodule Pleroma.LoadTesting.Generator do use Pleroma.LoadTesting.Helper alias Pleroma.Web.CommonAPI + def generate_like_activities(user, posts) do + count_likes = Kernel.trunc(length(posts) / 4) + IO.puts("Starting generating #{count_likes} like activities...") + + {time, _} = + :timer.tc(fn -> + Task.async_stream( + Enum.take_random(posts, count_likes), + fn post -> {:ok, _, _} = CommonAPI.favorite(post.id, user) end, + max_concurrency: 10, + timeout: 30_000 + ) + |> Stream.run() + end) + + IO.puts("Inserting like activities take #{to_sec(time)} sec.\n") + end + def generate_users(opts) do IO.puts("Starting generating #{opts[:users_max]} users...") {time, _} = :timer.tc(fn -> do_generate_users(opts) end) diff --git a/benchmarks/mix/tasks/pleroma/load_testing.ex b/benchmarks/mix/tasks/pleroma/load_testing.ex index 4fa3eec49..0a751adac 100644 --- a/benchmarks/mix/tasks/pleroma/load_testing.ex +++ b/benchmarks/mix/tasks/pleroma/load_testing.ex @@ -100,6 +100,10 @@ def run(args) do generate_remote_activities(user, remote_users) + generate_like_activities( + user, Pleroma.Repo.all(Pleroma.Activity.Queries.by_type("Create")) + ) + generate_dms(user, users, opts) {:ok, activity} = generate_long_thread(user, users, opts) From 1d6970baf1fd09c357740a380351adf44f247279 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 22 Nov 2019 14:17:12 +0300 Subject: [PATCH 2/2] fix --- benchmarks/load_testing/fetcher.ex | 36 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/benchmarks/load_testing/fetcher.ex b/benchmarks/load_testing/fetcher.ex index 776105d34..a45a71d4a 100644 --- a/benchmarks/load_testing/fetcher.ex +++ b/benchmarks/load_testing/fetcher.ex @@ -57,9 +57,6 @@ def query_timelines(user) do Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities( mastodon_federated_timeline_params ) - end, - "User favourites timeline" => fn -> - Pleroma.Web.ActivityPub.ActivityPub.fetch_favourites(user) end }) @@ -77,8 +74,6 @@ def query_timelines(user) do mastodon_federated_timeline_params ) - user_favourites = Pleroma.Web.ActivityPub.ActivityPub.fetch_favourites(user) - Benchee.run(%{ "Rendering home timeline" => fn -> Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{ @@ -102,10 +97,33 @@ def query_timelines(user) do }) end, "Rendering favorites timeline" => fn -> - Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{ - activities: user_favourites, - for: user, - as: :activity}) + 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 + } + }, + %{}) end, }) end