Add optional pool utilization stats #141
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I added a way to monitor approximate pool utilization.
TL;DR: When stats collection is enabled, pool manager will collect stats regarding workers utilization. It will report utilization in percentage. Stats reported will show pool utilization in between
poolboy:stats/1
calls.New configuration option added:
{stats, boolean()}
. Default value:false
.When option set to true, pool manager process will collect time duration workers being checked out. This is done by simply adding yet another duration to a total time worker was busy doing stuff.
When
poolboy:stats/1
is called, manager will report collected values (observed period, total workers busy time, original pool size); it will reset observing period time and total workers busy time. Approximate pool utilization calculations are done on caller side: utilization is a float0.0..1.0
when no overflow allowed, and0.0..N
if overflow is allowed.NB: when pool is configured with overflow allowed, pool utilization may go over
1.0
. This will, obviously, indicate that pool is overflown.I consider this code to be quite cheap to use in heavily loaded pools. It will allow to monitor pool utilization in more precise manner; pool utilization then may be reported to some monitoring system (e.g. prometheus/grafana, etc.).
Let me know if you like the idea or if this code is good enough to be merged.