diff options
author | rinpatch <rinpatch@sdf.org> | 2020-07-02 01:53:27 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-07-15 15:26:35 +0300 |
commit | a705637dcf7ffe063c9c0f3f190f57e44aaa63f2 (patch) | |
tree | 70ef6811190c7b1496f4aa23b4cf4b6ce7745e33 /lib | |
parent | 9b73c35ca8b051316815461247b802bc8567854f (diff) | |
download | pleroma-a705637dcf7ffe063c9c0f3f190f57e44aaa63f2.tar.gz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/gun/connection_pool/worker.ex | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/pleroma/gun/connection_pool/worker.ex b/lib/pleroma/gun/connection_pool/worker.ex index 418cb18c1..ec0502621 100644 --- a/lib/pleroma/gun/connection_pool/worker.ex +++ b/lib/pleroma/gun/connection_pool/worker.ex @@ -12,7 +12,7 @@ defmodule Pleroma.Gun.ConnectionPool.Worker 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 @@ defmodule Pleroma.Gun.ConnectionPool.Worker 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 @@ defmodule Pleroma.Gun.ConnectionPool.Worker 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 |