Commit 214bc322 authored by rinpatch's avatar rinpatch

Connection Pool: fix LRFU implementation to not actually be LRU

The numbers of the native time unit were so small the CRF was always 1,
making it an LRU. This commit switches the time to miliseconds and changes
the time delta multiplier to the one yielding mostly highest hit rates according
to the paper
parent 1f34614e
Pipeline #27943 passed with stages
in 16 minutes and 40 seconds
......@@ -12,7 +12,7 @@ def start_link([key | _] = opts) do
def init([key, uri, opts, client_pid]) do
with {:ok, conn_pid} <- Gun.Conn.open(uri, opts),
Process.link(conn_pid) do
time = :erlang.monotonic_time()
time = :erlang.monotonic_time(:millisecond)
{_, _} =
Registry.update_value(@registry, key, fn _ ->
......@@ -31,7 +31,7 @@ def init([key, uri, opts, client_pid]) do
@impl true
def handle_cast({:add_client, client_pid, send_pid_back}, %{key: key} = state) do
time = :erlang.monotonic_time()
time = :erlang.monotonic_time(:millisecond)
{{conn_pid, _, _, _}, _} =
Registry.update_value(@registry, key, fn {conn_pid, used_by, crf, last_reference} ->
......@@ -116,6 +116,6 @@ def handle_info({:DOWN, _ref, :process, pid, reason}, state) do
# LRFU policy: https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.55.1478
defp crf(time_delta, prev_crf) do
1 + :math.pow(0.5, time_delta / 100) * prev_crf
1 + :math.pow(0.5, 0.0001 * time_delta) * prev_crf
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment