|
|
|
@ -21,6 +21,8 @@ defmodule Indexer.Memory.Monitor do |
|
|
|
|
|
|
|
|
|
use GenServer |
|
|
|
|
|
|
|
|
|
@expandable_memory_coefficient 0.4 |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Registers caller as `Indexer.Memory.Shrinkable`. |
|
|
|
|
""" |
|
|
|
@ -70,6 +72,11 @@ defmodule Indexer.Memory.Monitor do |
|
|
|
|
shrink_or_log(state) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if total <= memory_limit() * @expandable_memory_coefficient do |
|
|
|
|
log_expandable_memory(%{limit: memory_limit(), total: total}) |
|
|
|
|
expand(state) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
flush(:check) |
|
|
|
|
|
|
|
|
|
{:noreply, state} |
|
|
|
@ -100,7 +107,20 @@ defmodule Indexer.Memory.Monitor do |
|
|
|
|
to_string(limit), |
|
|
|
|
" bytes (", |
|
|
|
|
to_string(div(100 * total, limit)), |
|
|
|
|
"%) of memory limit used." |
|
|
|
|
"%) of memory limit used, shrinking queues" |
|
|
|
|
] |
|
|
|
|
end) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp log_expandable_memory(%{total: total, limit: limit}) do |
|
|
|
|
Logger.info(fn -> |
|
|
|
|
[ |
|
|
|
|
to_string(total), |
|
|
|
|
" / ", |
|
|
|
|
to_string(limit), |
|
|
|
|
" bytes (", |
|
|
|
|
to_string(div(100 * total, limit)), |
|
|
|
|
"%) of memory limit used, expanding queues" |
|
|
|
|
] |
|
|
|
|
end) |
|
|
|
|
end |
|
|
|
@ -164,6 +184,15 @@ defmodule Indexer.Memory.Monitor do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp expand(%__MODULE__{} = state) do |
|
|
|
|
state |
|
|
|
|
|> shrinkable_memory_pairs() |
|
|
|
|
|> Enum.each(fn {pid, _memory} -> |
|
|
|
|
Logger.info(fn -> ["Expanding queue ", process(pid)] end) |
|
|
|
|
Shrinkable.expand(pid) |
|
|
|
|
end) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp shrinkable_memory_pairs(%__MODULE__{shrinkable_set: shrinkable_set}) do |
|
|
|
|
shrinkable_set |
|
|
|
|
|> Enum.map(fn pid -> {pid, memory(pid)} end) |
|
|
|
|