Use multiple hackney pools

* federation (ap, salmon)
* media (rich media, media proxy)
* upload (uploader proxy)

Each "part" will stop fighting others ones -- a huge federation outbound
could before make the media proxy fail to checkout a connection in time.

splitted media and uploaded media for the good reason than an upload
pool will have all connections to the same host (the uploader upstream).
it also has a longer default retention period for connections.
This commit is contained in:
href 2019-01-30 12:38:38 +01:00
commit 4aff4efa8d
No known key found for this signature in database
GPG key ID: EE8296C1A152C325
8 changed files with 86 additions and 12 deletions

View file

@ -101,12 +101,15 @@ defmodule Pleroma.Application do
],
id: :cachex_idem
),
worker(Pleroma.FlakeId, []),
worker(Pleroma.Web.Federator.RetryQueue, []),
worker(Pleroma.Web.Federator, []),
worker(Pleroma.Stats, []),
worker(Pleroma.Web.Push, [])
worker(Pleroma.FlakeId, [])
] ++
hackney_pool_children() ++
[
worker(Pleroma.Web.Federator.RetryQueue, []),
worker(Pleroma.Web.Federator, []),
worker(Pleroma.Stats, []),
worker(Pleroma.Web.Push, [])
] ++
streamer_child() ++
chat_child() ++
[
@ -121,6 +124,20 @@ defmodule Pleroma.Application do
Supervisor.start_link(children, opts)
end
def enabled_hackney_pools() do
[:media] ++
if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
[:federation]
else
[]
end ++
if Pleroma.Config.get([Pleroma.Uploader, :proxy_remote]) do
[:uploadproxy]
else
[]
end
end
if Mix.env() == :test do
defp streamer_child(), do: []
defp chat_child(), do: []
@ -137,4 +154,11 @@ defmodule Pleroma.Application do
end
end
end
defp hackney_pool_children() do
for pool <- enabled_hackney_pools() do
options = Pleroma.Config.get([:hackney_pools, pool])
:hackney_pool.child_spec(pool, options)
end
end
end

View file

@ -10,7 +10,8 @@ defmodule Pleroma.HTTP.Connection do
@hackney_options [
timeout: 10000,
recv_timeout: 20000,
follow_redirect: true
follow_redirect: true,
pool: :federation
]
@adapter Application.get_env(:tesla, :adapter)

View file

@ -24,7 +24,8 @@ defmodule Pleroma.Uploaders.MDII do
extension = String.split(upload.name, ".") |> List.last()
query = "#{cgi}?#{extension}"
with {:ok, %{status: 200, body: body}} <- @httpoison.post(query, file_data) do
with {:ok, %{status: 200, body: body}} <-
@httpoison.post(query, file_data, adapter: [pool: :default]) do
remote_file_name = String.split(body) |> List.first()
public_url = "#{files}/#{remote_file_name}.#{extension}"
{:ok, {:url, public_url}}

View file

@ -1311,7 +1311,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
[],
adapter: [
timeout: timeout,
recv_timeout: timeout
recv_timeout: timeout,
pool: :default
]
),
{:ok, data} <- Jason.decode(body) do

View file

@ -28,7 +28,7 @@ defmodule Pleroma.Web.RichMedia.Parser do
defp parse_url(url) do
try do
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url)
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], pool: :media)
html |> maybe_parse() |> get_parsed_data()
rescue

View file

@ -20,7 +20,7 @@ defmodule Pleroma.Web.RichMedia.Parsers.OEmbed do
end
defp get_oembed_data(url) do
{:ok, %Tesla.Env{body: json}} = Pleroma.HTTP.get(url)
{:ok, %Tesla.Env{body: json}} = Pleroma.HTTP.get(url, [], pool: :media)
{:ok, data} = Jason.decode(json)