logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

benchmark.ex (3283B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.Benchmark do
  5. @shortdoc "Benchmarks"
  6. @moduledoc """
  7. Benchmark tasks available:
  8. adapters
  9. render_timeline
  10. search
  11. tag
  12. MIX_ENV=benchmark mix pleroma.benchmark adapters
  13. """
  14. use Mix.Task
  15. import Mix.Pleroma
  16. def run(["search"]) do
  17. start_pleroma()
  18. Benchee.run(%{
  19. "search" => fn ->
  20. Pleroma.Activity.search(nil, "cofe")
  21. end
  22. })
  23. end
  24. def run(["tag"]) do
  25. start_pleroma()
  26. Benchee.run(%{
  27. "tag" => fn ->
  28. %{"type" => "Create", "tag" => "cofe"}
  29. |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
  30. end
  31. })
  32. end
  33. def run(["render_timeline", nickname | _] = args) do
  34. start_pleroma()
  35. user = Pleroma.User.get_by_nickname(nickname)
  36. activities =
  37. %{}
  38. |> Map.put("type", ["Create", "Announce"])
  39. |> Map.put("blocking_user", user)
  40. |> Map.put("muting_user", user)
  41. |> Map.put("user", user)
  42. |> Map.put("limit", 4096)
  43. |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
  44. |> Enum.reverse()
  45. inputs = %{
  46. "1 activity" => Enum.take_random(activities, 1),
  47. "10 activities" => Enum.take_random(activities, 10),
  48. "20 activities" => Enum.take_random(activities, 20),
  49. "40 activities" => Enum.take_random(activities, 40),
  50. "80 activities" => Enum.take_random(activities, 80)
  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. Benchee.run(
  64. %{
  65. "Standard rendering" => fn activities ->
  66. Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
  67. activities: activities,
  68. for: user,
  69. as: :activity
  70. })
  71. end
  72. },
  73. inputs: inputs
  74. )
  75. end
  76. def run(["adapters"]) do
  77. start_pleroma()
  78. :ok =
  79. Pleroma.Gun.Conn.open(
  80. "https://httpbin.org/stream-bytes/1500",
  81. :gun_connections
  82. )
  83. Process.sleep(1_500)
  84. Benchee.run(
  85. %{
  86. "Without conn and without pool" => fn ->
  87. {:ok, %Tesla.Env{}} =
  88. Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [],
  89. pool: :no_pool,
  90. receive_conn: false
  91. )
  92. end,
  93. "Without conn and with pool" => fn ->
  94. {:ok, %Tesla.Env{}} =
  95. Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [], receive_conn: false)
  96. end,
  97. "With reused conn and without pool" => fn ->
  98. {:ok, %Tesla.Env{}} =
  99. Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [], pool: :no_pool)
  100. end,
  101. "With reused conn and with pool" => fn ->
  102. {:ok, %Tesla.Env{}} = Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500")
  103. end
  104. },
  105. parallel: 10
  106. )
  107. end
  108. end