configurable limits for ConcurrentLimiter
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Sat, 9 Jan 2021 15:52:40 +0000 (18:52 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Thu, 21 Jan 2021 06:47:21 +0000 (09:47 +0300)
Pleroma.Web.RichMedia.Helpers & Pleroma.Web.MediaProxy

config/config.exs
config/description.exs
docs/configuration/cheatsheet.md
lib/pleroma/application.ex

index 70d0c2c2ba0734ea283cd8341e582d6ae948f428..e07e67de941a97eceeeeafa99713965b2199bac1 100644 (file)
@@ -832,6 +832,11 @@ config :pleroma, Pleroma.User.Backup,
   limit_days: 7,
   dir: nil
 
+config :pleroma, ConcurrentLimiter, [
+  {Pleroma.Web.RichMedia.Helpers, [max_running: 5, max_waiting: 5]},
+  {Pleroma.Web.MediaProxy, [max_running: 5, max_waiting: 5]}
+]
+
 # Import environment specific config. This must remain at the bottom
 # of this file so it overrides the configuration defined above.
 import_config "#{Mix.env()}.exs"
index 493d362d3b5407359cb44b786fb2b0d5dbc54b90..49fea4234ed9fb9e48b1b7303a4c4b9385f8d553 100644 (file)
@@ -3330,5 +3330,53 @@ config :pleroma, :config_description, [
         suggestions: [:text, :protobuf]
       }
     ]
+  },
+  %{
+    group: :pleroma,
+    key: ConcurrentLimiter,
+    type: :group,
+    description: "Limits configuration for background tasks.",
+    children: [
+      %{
+        key: Pleroma.Web.RichMedia.Helpers,
+        type: :keyword,
+        description: "Concurrent limits configuration for getting RichMedia for activities.",
+        suggestions: [max_running: 5, max_waiting: 5],
+        children: [
+          %{
+            key: :max_running,
+            type: :integer,
+            description: "Max running concurrently jobs.",
+            suggestion: [5]
+          },
+          %{
+            key: :max_waiting,
+            type: :integer,
+            description: "Max waiting jobs.",
+            suggestion: [5]
+          }
+        ]
+      },
+      %{
+        key: Pleroma.Web.MediaProxy,
+        type: :keyword,
+        description: "Concurrent limits configuration for MediaProxyWarmingPolicy.",
+        suggestions: [max_running: 5, max_waiting: 5],
+        children: [
+          %{
+            key: :max_running,
+            type: :integer,
+            description: "Max running concurrently jobs.",
+            suggestion: [5]
+          },
+          %{
+            key: :max_waiting,
+            type: :integer,
+            description: "Max waiting jobs.",
+            suggestion: [5]
+          }
+        ]
+      }
+    ]
   }
 ]
index c7d8a2dae8345814ae3618a94bcda67e49755707..c7ff8687e09c461cce895bbbfe18e175808e7fd4 100644 (file)
@@ -1110,3 +1110,15 @@ Settings to enable and configure expiration for ephemeral activities
 
 * `:enabled` - enables ephemeral activities creation
 * `:min_lifetime` - minimum lifetime for ephemeral activities (in seconds). Default: 10 minutes.
+
+## ConcurrentLimiter
+
+Settings allow configuring restrictions for concurrently running jobs. Jobs, which can be configured:
+
+* `Pleroma.Web.RichMedia.Helpers` - configuration for getting RichMedia for activities.
+* `Pleroma.Web.MediaProxy` - configuration for MediaProxyWarmingPolicy.
+
+Each job has these settings:
+
+* `:max_running` - max concurrently runnings jobs
+* `:max_waiting` - max waiting jobs
index 203a9500495db6224c637d1c98a510f81d5505c9..4742a3ecb72a7f4e102823042702d75b053c0e85 100644 (file)
@@ -297,7 +297,16 @@ defmodule Pleroma.Application do
 
   @spec limiters_setup() :: :ok
   def limiters_setup do
+    config = Config.get(ConcurrentLimiter, [])
+
     [Pleroma.Web.RichMedia.Helpers, Pleroma.Web.MediaProxy]
-    |> Enum.each(&ConcurrentLimiter.new(&1, 1, 0))
+    |> Enum.each(fn module ->
+      mod_config = Keyword.get(config, module, [])
+
+      max_running = Keyword.get(mod_config, :max_running, 5)
+      max_waiting = Keyword.get(mod_config, :max_waiting, 5)
+
+      ConcurrentLimiter.new(module, max_running, max_waiting)
+    end)
   end
 end