Refactor gun pooling and simplify adapter option insertion
authorrinpatch <rinpatch@sdf.org>
Tue, 5 May 2020 22:51:10 +0000 (01:51 +0300)
committerrinpatch <rinpatch@sdf.org>
Wed, 15 Jul 2020 12:17:27 +0000 (15:17 +0300)
commit58a4f350a8bc361d793cb96442f856362c18f195
treee9f24116983c9c94e29010a1058f4f0c3afa4937
parent040524c09fc9b7cdf2cadc4cc2d647433715381d
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
16 files changed:
config/config.exs
lib/pleroma/application.ex
lib/pleroma/gun/conn.ex
lib/pleroma/gun/connection_pool.ex [new file with mode: 0644]
lib/pleroma/gun/connection_pool/worker.ex [new file with mode: 0644]
lib/pleroma/http/adapter_helper.ex
lib/pleroma/http/adapter_helper/default.ex [new file with mode: 0644]
lib/pleroma/http/adapter_helper/gun.ex
lib/pleroma/http/adapter_helper/hackney.ex
lib/pleroma/http/connection.ex [deleted file]
lib/pleroma/http/http.ex
lib/pleroma/pool/connections.ex [deleted file]
lib/pleroma/pool/pool.ex [deleted file]
lib/pleroma/pool/request.ex [deleted file]
lib/pleroma/pool/supervisor.ex [deleted file]
lib/pleroma/reverse_proxy/client/tesla.ex