Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
0ada3fe8
Verified
Commit
0ada3fe8
authored
May 21, 2021
by
Alex Gleason
Browse files
Gun: use runtime deps in ConnectionPool
Speed up recompilation time by breaking compile-time cycles
parent
3ebede4b
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/gun/connection_pool/reclaimer.ex
View file @
0ada3fe8
...
...
@@ -5,11 +5,11 @@
defmodule
Pleroma
.
Gun
.
ConnectionPool
.
Reclaimer
do
use
GenServer
,
restart:
:temporary
@
registry
Pleroma
.
Gun
.
ConnectionPool
defp
registry
,
do
:
Pleroma
.
Gun
.
ConnectionPool
def
start_monitor
do
pid
=
case
:gen_server
.
start
(
__MODULE__
,
[],
name:
{
:via
,
Registry
,
{
@
registry
,
"reclaimer"
}})
do
case
:gen_server
.
start
(
__MODULE__
,
[],
name:
{
:via
,
Registry
,
{
registry
()
,
"reclaimer"
}})
do
{
:ok
,
pid
}
->
pid
...
...
@@ -46,7 +46,7 @@ def handle_continue(:reclaim, _) do
# {worker_pid, crf, last_reference} end)
unused_conns
=
Registry
.
select
(
@
registry
,
registry
()
,
[
{{
:_
,
:"$1"
,
{
:_
,
:"$2"
,
:"$3"
,
:"$4"
}},
[{
:==
,
:"$2"
,
[]}],
[{{
:"$1"
,
:"$3"
,
:"$4"
}}]}
]
...
...
lib/pleroma/gun/connection_pool/worker.ex
View file @
0ada3fe8
...
...
@@ -6,10 +6,10 @@ defmodule Pleroma.Gun.ConnectionPool.Worker do
alias
Pleroma
.
Gun
use
GenServer
,
restart:
:temporary
@
registry
Pleroma
.
Gun
.
ConnectionPool
defp
registry
,
do
:
Pleroma
.
Gun
.
ConnectionPool
def
start_link
([
key
|
_
]
=
opts
)
do
GenServer
.
start_link
(
__MODULE__
,
opts
,
name:
{
:via
,
Registry
,
{
@
registry
,
key
}})
GenServer
.
start_link
(
__MODULE__
,
opts
,
name:
{
:via
,
Registry
,
{
registry
()
,
key
}})
end
@impl
true
...
...
@@ -24,7 +24,7 @@ def handle_continue({:connect, [key, uri, opts, client_pid]}, _) do
time
=
:erlang
.
monotonic_time
(
:millisecond
)
{
_
,
_
}
=
Registry
.
update_value
(
@
registry
,
key
,
fn
_
->
Registry
.
update_value
(
registry
()
,
key
,
fn
_
->
{
conn_pid
,
[
client_pid
],
1
,
time
}
end
)
...
...
@@ -65,7 +65,7 @@ def handle_call(:add_client, {client_pid, _}, %{key: key, protocol: protocol} =
time
=
:erlang
.
monotonic_time
(
:millisecond
)
{{
conn_pid
,
used_by
,
_
,
_
},
_
}
=
Registry
.
update_value
(
@
registry
,
key
,
fn
{
conn_pid
,
used_by
,
crf
,
last_reference
}
->
Registry
.
update_value
(
registry
()
,
key
,
fn
{
conn_pid
,
used_by
,
crf
,
last_reference
}
->
{
conn_pid
,
[
client_pid
|
used_by
],
crf
(
time
-
last_reference
,
crf
),
time
}
end
)
...
...
@@ -92,7 +92,7 @@ def handle_call(:add_client, {client_pid, _}, %{key: key, protocol: protocol} =
@impl
true
def
handle_call
(
:remove_client
,
{
client_pid
,
_
},
%{
key:
key
}
=
state
)
do
{{
_conn_pid
,
used_by
,
_crf
,
_last_reference
},
_
}
=
Registry
.
update_value
(
@
registry
,
key
,
fn
{
conn_pid
,
used_by
,
crf
,
last_reference
}
->
Registry
.
update_value
(
registry
()
,
key
,
fn
{
conn_pid
,
used_by
,
crf
,
last_reference
}
->
{
conn_pid
,
List
.
delete
(
used_by
,
client_pid
),
crf
,
last_reference
}
end
)
...
...
lib/pleroma/http/adapter_helper/gun.ex
View file @
0ada3fe8
...
...
@@ -54,8 +54,8 @@ def pool_timeout(pool) do
Config
.
get
([
:pools
,
pool
,
:recv_timeout
],
default
)
end
@prefix
Pleroma
.
Gun
.
ConnectionPool
def
limiter_setup
do
prefix
=
Pleroma
.
Gun
.
ConnectionPool
wait
=
Config
.
get
([
:connections_pool
,
:connection_acquisition_wait
])
retries
=
Config
.
get
([
:connections_pool
,
:connection_acquisition_retries
])
...
...
@@ -66,7 +66,7 @@ def limiter_setup do
max_waiting
=
Keyword
.
get
(
opts
,
:max_waiting
,
10
)
result
=
ConcurrentLimiter
.
new
(
:"
#{
@
prefix
}
.
#{
name
}
"
,
max_running
,
max_waiting
,
ConcurrentLimiter
.
new
(
:"
#{
prefix
}
.
#{
name
}
"
,
max_running
,
max_waiting
,
wait:
wait
,
max_retries:
retries
)
...
...
Alex Gleason
@alexgleason
mentioned in commit
2e682788
·
May 31, 2021
mentioned in commit
2e682788
mentioned in commit 2e682788a30b225b67254e92d1807b317ede57f8
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment