Improve handling of idle resources in the resource pool
This commit is contained in:
parent
893299ba24
commit
aadbee0d0e
1 changed files with 23 additions and 11 deletions
|
@ -79,7 +79,7 @@
|
|||
port)))
|
||||
|
||||
(define* (make-resource-pool return-new-resource max-size
|
||||
#:key (min-size max-size)
|
||||
#:key (min-size 0)
|
||||
(idle-seconds #f)
|
||||
(delay-logger (const #f))
|
||||
(duration-logger (const #f))
|
||||
|
@ -375,7 +375,7 @@
|
|||
(/ (- (get-internal-real-time) internal-time)
|
||||
internal-time-units-per-second))
|
||||
resources-last-used))
|
||||
(resources-to-destroy
|
||||
(candidate-resources-to-destroy
|
||||
(filter-map
|
||||
(lambda (resource last-used-seconds)
|
||||
(if (and (member resource available)
|
||||
|
@ -385,6 +385,18 @@
|
|||
resources
|
||||
resources-last-used-seconds)))
|
||||
|
||||
(let* ((available-resources-to-destroy
|
||||
(lset-intersection eq?
|
||||
available
|
||||
candidate-resources-to-destroy))
|
||||
(max-resources-to-destroy
|
||||
(max 0
|
||||
(- (length resources)
|
||||
min-size)))
|
||||
(resources-to-destroy
|
||||
(take available-resources-to-destroy
|
||||
(min max-resources-to-destroy
|
||||
(length available-resources-to-destroy)))))
|
||||
(when destructor
|
||||
(for-each
|
||||
(lambda (resource)
|
||||
|
@ -394,7 +406,7 @@
|
|||
(loop resources
|
||||
(lset-difference eq? available resources-to-destroy)
|
||||
waiters
|
||||
resources-last-used)))
|
||||
resources-last-used))))
|
||||
|
||||
(('destroy reply)
|
||||
(if (null? resources)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue