Merge remote-tracking branch 'remotes/origin/develop' into output-of-relationships...
[akkoma] / lib / mix / tasks / pleroma / benchmark.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.Benchmark do
6 import Mix.Pleroma
7 use Mix.Task
8
9 def run(["search"]) do
10 start_pleroma()
11
12 Benchee.run(%{
13 "search" => fn ->
14 Pleroma.Activity.search(nil, "cofe")
15 end
16 })
17 end
18
19 def run(["tag"]) do
20 start_pleroma()
21
22 Benchee.run(%{
23 "tag" => fn ->
24 %{"type" => "Create", "tag" => "cofe"}
25 |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
26 end
27 })
28 end
29
30 def run(["render_timeline", nickname | _] = args) do
31 start_pleroma()
32 user = Pleroma.User.get_by_nickname(nickname)
33
34 activities =
35 %{}
36 |> Map.put("type", ["Create", "Announce"])
37 |> Map.put("blocking_user", user)
38 |> Map.put("muting_user", user)
39 |> Map.put("user", user)
40 |> Map.put("limit", 4096)
41 |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
42 |> Enum.reverse()
43
44 inputs = %{
45 "1 activity" => Enum.take_random(activities, 1),
46 "10 activities" => Enum.take_random(activities, 10),
47 "20 activities" => Enum.take_random(activities, 20),
48 "40 activities" => Enum.take_random(activities, 40),
49 "80 activities" => Enum.take_random(activities, 80)
50 }
51
52 inputs =
53 if Enum.at(args, 2) == "extended" do
54 Map.merge(inputs, %{
55 "200 activities" => Enum.take_random(activities, 200),
56 "500 activities" => Enum.take_random(activities, 500),
57 "2000 activities" => Enum.take_random(activities, 2000),
58 "4096 activities" => Enum.take_random(activities, 4096)
59 })
60 else
61 inputs
62 end
63
64 Benchee.run(
65 %{
66 "Standart rendering" => fn activities ->
67 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
68 activities: activities,
69 for: user,
70 as: :activity,
71 skip_relationships: true
72 })
73 end
74 },
75 inputs: inputs
76 )
77 end
78
79 def run(["adapters"]) do
80 start_pleroma()
81
82 :ok =
83 Pleroma.Gun.Conn.open(
84 "https://httpbin.org/stream-bytes/1500",
85 :gun_connections
86 )
87
88 Process.sleep(1_500)
89
90 Benchee.run(
91 %{
92 "Without conn and without pool" => fn ->
93 {:ok, %Tesla.Env{}} =
94 Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [],
95 adapter: [pool: :no_pool, receive_conn: false]
96 )
97 end,
98 "Without conn and with pool" => fn ->
99 {:ok, %Tesla.Env{}} =
100 Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [],
101 adapter: [receive_conn: false]
102 )
103 end,
104 "With reused conn and without pool" => fn ->
105 {:ok, %Tesla.Env{}} =
106 Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [],
107 adapter: [pool: :no_pool]
108 )
109 end,
110 "With reused conn and with pool" => fn ->
111 {:ok, %Tesla.Env{}} = Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500")
112 end
113 },
114 parallel: 10
115 )
116 end
117 end