benchmarks/ added favourites timeline
authorMaksim Pechnikov <parallel588@gmail.com>
Tue, 19 Nov 2019 18:11:15 +0000 (21:11 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Tue, 19 Nov 2019 18:11:15 +0000 (21:11 +0300)
benchmarks/load_testing/fetcher.ex
benchmarks/load_testing/generator.ex
benchmarks/mix/tasks/pleroma/load_testing.ex

index cdc073b2ebea0f64f704c44a620f0f3e67c4398a..776105d34c186eea784b42137a4474e28c1e2bfb 100644 (file)
@@ -57,6 +57,9 @@ defmodule Pleroma.LoadTesting.Fetcher 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 @@ defmodule Pleroma.LoadTesting.Fetcher 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 @@ defmodule Pleroma.LoadTesting.Fetcher 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
 
index b4432bdb7313621dc92c5d97583cdc00082864c7..f42fd363ea385306ad8bd316c5a60f991cae2557 100644 (file)
@@ -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)
index 4fa3eec493014d8f4dbf7fb2676a05f120785f50..0a751adac02ab3a9088382ca6f8d7c899208ae50 100644 (file)
@@ -100,6 +100,10 @@ defmodule Mix.Tasks.Pleroma.LoadTesting 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)