machine_gun
machine_gun copied to clipboard
Eviction policy for idle connection pools
At what point connection pool pool_group:host:port
is stopped if there is no activity?
We have a server application where connection targets keep changing. I.e. we would make a lot of calls to host1:port1
(with pool size configured to 1000 connections) and then we will never call it again. Then we'll call host2:port2
a lot, and will not call it ever anymore too, etc.
I suspect in the current implementation these connection pools will just keep running forever until Erlang reaches max number of processes and starts throwing system_limit
errors.
Is this correct or maybe I just cannot find the logic that stops these pools in the code?
You can get all current pools by calling DynamicSupervisor.which_children
, get pool's name such as :"group@host:port"
using Process.info
and then terminate a specific pool with DynamicSupervisor.terminate_child
.
For example:
[{_, pool_pid, _, _} | _] = DynamicSupervisor.which_children(MachineGun.Supervisor)
{_, pool_name} = Process.info(pool_pid, :registered_name)
DynamicSupervisor.terminate_child(MachineGun.Supervisor, pool_pid)
Thank you, this is useful! Do you have plans to implement automatic eviction policy based on pool idle time?
This is definitely a good idea and a requirement for your use case. Currently I don't have the bandwidth to work on it, but the PR is always welcome.
Is there a way to detect last usage time of a pool from pool_pid
or pool_name
?
Also can the pool names be made into strings (so we don't have to worry about overflowing atoms table)?
Is there a way to detect last usage time of a pool from
pool_pid
orpool_name
?
None at the moment.
Also can the pool names be made into strings (so we don't have to worry about overflowing atoms table)?
This is good point and needs to be fixed for the general use case. Can you create separate issue for this?
Created #24