logo

pleroma

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

benchmark.ex (3105B)


  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. import Mix.Pleroma
  6. use Mix.Task
  7. def run(["search"]) do
  8. start_pleroma()
  9. Benchee.run(%{
  10. "search" => fn ->
  11. Pleroma.Activity.search(nil, "cofe")
  12. end
  13. })
  14. end
  15. def run(["tag"]) do
  16. start_pleroma()
  17. Benchee.run(%{
  18. "tag" => fn ->
  19. %{"type" => "Create", "tag" => "cofe"}
  20. |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
  21. end
  22. })
  23. end
  24. def run(["render_timeline", nickname | _] = args) do
  25. start_pleroma()
  26. user = Pleroma.User.get_by_nickname(nickname)
  27. activities =
  28. %{}
  29. |> Map.put("type", ["Create", "Announce"])
  30. |> Map.put("blocking_user", user)
  31. |> Map.put("muting_user", user)
  32. |> Map.put("user", user)
  33. |> Map.put("limit", 4096)
  34. |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
  35. |> Enum.reverse()
  36. inputs = %{
  37. "1 activity" => Enum.take_random(activities, 1),
  38. "10 activities" => Enum.take_random(activities, 10),
  39. "20 activities" => Enum.take_random(activities, 20),
  40. "40 activities" => Enum.take_random(activities, 40),
  41. "80 activities" => Enum.take_random(activities, 80)
  42. }
  43. inputs =
  44. if Enum.at(args, 2) == "extended" do
  45. Map.merge(inputs, %{
  46. "200 activities" => Enum.take_random(activities, 200),
  47. "500 activities" => Enum.take_random(activities, 500),
  48. "2000 activities" => Enum.take_random(activities, 2000),
  49. "4096 activities" => Enum.take_random(activities, 4096)
  50. })
  51. else
  52. inputs
  53. end
  54. Benchee.run(
  55. %{
  56. "Standart rendering" => fn activities ->
  57. Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
  58. activities: activities,
  59. for: user,
  60. as: :activity
  61. })
  62. end
  63. },
  64. inputs: inputs
  65. )
  66. end
  67. def run(["adapters"]) do
  68. start_pleroma()
  69. :ok =
  70. Pleroma.Gun.Conn.open(
  71. "https://httpbin.org/stream-bytes/1500",
  72. :gun_connections
  73. )
  74. Process.sleep(1_500)
  75. Benchee.run(
  76. %{
  77. "Without conn and without pool" => fn ->
  78. {:ok, %Tesla.Env{}} =
  79. Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [],
  80. pool: :no_pool,
  81. receive_conn: false
  82. )
  83. end,
  84. "Without conn and with pool" => fn ->
  85. {:ok, %Tesla.Env{}} =
  86. Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [], receive_conn: false)
  87. end,
  88. "With reused conn and without pool" => fn ->
  89. {:ok, %Tesla.Env{}} =
  90. Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500", [], pool: :no_pool)
  91. end,
  92. "With reused conn and with pool" => fn ->
  93. {:ok, %Tesla.Env{}} = Pleroma.HTTP.get("https://httpbin.org/stream-bytes/1500")
  94. end
  95. },
  96. parallel: 10
  97. )
  98. end
  99. end