Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eviction policy for idle connection pools #23

Open
DmitryKakurin opened this issue Aug 12, 2020 · 6 comments
Open

Eviction policy for idle connection pools #23

DmitryKakurin opened this issue Aug 12, 2020 · 6 comments

Comments

@DmitryKakurin
Copy link

DmitryKakurin commented Aug 12, 2020

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?

@petrohi
Copy link
Owner

petrohi commented Aug 27, 2020

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)

@DmitryKakurin DmitryKakurin changed the title Retention policy for idle connection pools Eviction policy for idle connection pools Aug 27, 2020
@DmitryKakurin
Copy link
Author

Thank you, this is useful!
Do you have plans to implement automatic eviction policy based on pool idle time?

@petrohi
Copy link
Owner

petrohi commented Aug 28, 2020

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.

@DmitryKakurin
Copy link
Author

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)?

@petrohi
Copy link
Owner

petrohi commented Sep 10, 2020

Is there a way to detect last usage time of a pool from pool_pid or pool_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?

@DmitryKakurin
Copy link
Author

Created #24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants