1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.Benchmark do
8 Benchmark tasks available:
15 MIX_ENV=benchmark mix pleroma.benchmark adapters
21 def run(["search"]) do
26 Pleroma.Activity.search(nil, "cofe")
36 %{"type" => "Create", "tag" => "cofe"}
37 |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
42 def run(["render_timeline", nickname | _] = args) do
44 user = Pleroma.User.get_by_nickname(nickname)
48 |> Map.put("type", ["Create", "Announce"])
49 |> Map.put("blocking_user", user)
50 |> Map.put("muting_user", user)
51 |> Map.put("user", user)
52 |> Map.put("limit", 4096)
53 |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
57 "1 activity" => Enum.take_random(activities, 1),
58 "10 activities" => Enum.take_random(activities, 10),
59 "20 activities" => Enum.take_random(activities, 20),
60 "40 activities" => Enum.take_random(activities, 40),
61 "80 activities" => Enum.take_random(activities, 80)
65 if Enum.at(args, 2) == "extended" do
67 "200 activities" => Enum.take_random(activities, 200),
68 "500 activities" => Enum.take_random(activities, 500),
69 "2000 activities" => Enum.take_random(activities, 2000),
70 "4096 activities" => Enum.take_random(activities, 4096)
78 "Standard rendering" => fn activities ->
79 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
80 activities: activities,
90 def run(["adapters"]) do
94 Pleroma.Gun.Conn.open(
95 "https://httpbin.org/stream-bytes/1500",
103 "Without conn and without pool" => fn ->
104 {:ok, %Tesla.Env{}} =
105 Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [],
110 "Without conn and with pool" => fn ->
111 {:ok, %Tesla.Env{}} =
112 Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [], receive_conn: false)
114 "With reused conn and without pool" => fn ->
115 {:ok, %Tesla.Env{}} =
116 Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [], pool: :no_pool)
118 "With reused conn and with pool" => fn ->
119 {:ok, %Tesla.Env{}} = Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500")