9.4 LRU
"managers/lru.ss" defines a manager constructor:
| ||||||||||||||||||||||||||||||||||||||||||
instance-expiration-handler : expiration-handler/c | ||||||||||||||||||||||||||||||||||||||||||
check-interval : integer? | ||||||||||||||||||||||||||||||||||||||||||
collect-interval : integer? | ||||||||||||||||||||||||||||||||||||||||||
initial-count : integer? = 1 | ||||||||||||||||||||||||||||||||||||||||||
Instances managed by this manager will be expired if there are no continuations associated with them, after the instance is unlocked. If an expired instance is looked up, the exn:fail:servlet-manager:no-instance exception is thrown with instance-exp-handler as the expiration handler.
Continuations managed by this manager are given a "Life Count" of initial-count initially. If an expired continuation is looked up, the exn:fail:servlet-manager:no-continuation exception is thrown with instance-exp-handler as the expiration handler, if no expiration-handler was passed to continuation-store!.
Every check-interval seconds collect? is called to determine if the collection routine should be run. Every collect-interval seconds the collection routine is run.
Every time the collection routine runs, the "Life Count" of every continuation is decremented by 1. If a continuation’s count reaches 0, it is expired. The inform-p function is called if any continuations are expired, with the number of continuations expired.
The recommended usage of this manager is codified as the following function:
| ||||||||
→ manager? | ||||||||
instance-expiration-handler : expiration-handler/c | ||||||||
memory-threshold : number? |
This creates an LRU manager with the following behavior: The memory limit is set to memory-threshold. Continuations start with 24 life points. Life points are deducted at the rate of one every 10 minutes, or one every 5 seconds when the memory limit is exceeded. Hence the maximum life time for a continuation is 4 hours, and the minimum is 2 minutes.
If the load on the server spikes – as indicated by memory usage – the server will quickly expire continuations, until the memory is back under control. If the load stays low, it will still efficiently expire old continuations.