summaryrefslogtreecommitdiff
path: root/lib/pleroma/application.ex
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-05-06 01:51:10 +0300
committerrinpatch <rinpatch@sdf.org>2020-07-15 15:17:27 +0300
commit58a4f350a8bc361d793cb96442f856362c18f195 (patch)
treee9f24116983c9c94e29010a1058f4f0c3afa4937 /lib/pleroma/application.ex
parent040524c09fc9b7cdf2cadc4cc2d647433715381d (diff)
Refactor gun pooling and simplify adapter option insertion
This patch refactors gun pooling to use Elixir process registry and simplifies adapter option insertion. Having the pool use process registry instead of a GenServer has a number of advantages: - Simpler code: the initial implementation adds about half the lines of code it deletes - Concurrency: unlike a GenServer, ETS-based registry can handle multiple checkout/checkin requests at the same time - Precise and easy idle connection clousure: current proposal for closing idle connections in the GenServer-based pool needs to filter through all connections once a minute and compare their last active time with closing time. With Elixir process registry this can be done by just using `Process.send_after`/`Process.cancel_timer` in the worker process. - Lower memory footprint: In my tests `gun-memory-leak` branch uses about 290mb on peak load (250 connections) and 235mb on idle (5-10 connections). Registry-based pool uses 210mb on idle and 240mb on peak load
Diffstat (limited to 'lib/pleroma/application.ex')
-rw-r--r--lib/pleroma/application.ex8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index 3282c6882..be14c1f9f 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -223,9 +223,7 @@ defmodule Pleroma.Application do
# start hackney and gun pools in tests
defp http_children(_, :test) do
- hackney_options = Config.get([:hackney_pools, :federation])
- hackney_pool = :hackney_pool.child_spec(:federation, hackney_options)
- [hackney_pool, Pleroma.Pool.Supervisor]
+ http_children(Tesla.Adapter.Hackney, nil) ++ http_children(Tesla.Adapter.Gun, nil)
end
defp http_children(Tesla.Adapter.Hackney, _) do
@@ -244,7 +242,9 @@ defmodule Pleroma.Application do
end
end
- defp http_children(Tesla.Adapter.Gun, _), do: [Pleroma.Pool.Supervisor]
+ defp http_children(Tesla.Adapter.Gun, _) do
+ [{Registry, keys: :unique, name: Pleroma.Gun.ConnectionPool}]
+ end
defp http_children(_, _), do: []
end