► |  | Web Server: PLT HTTP Server

1 | Running the Web Server
2 | Writing Servlets
3 | Extending the Web Server
4 | Troubleshooting and Tips
5 | Acknowledgements
| Index

► | 2 | Writing Servlets

2.1 | Defining a Servlet
2.2 | APIs
2.3 | Common Contracts
2.4 | HTTP
2.5 | Web Interaction
2.6 | Stateless Web Interaction
2.7 | Web Cells
2.8 | File Boxes
2.9 | Stateless Web Parameters
2.10 | Formlets
2.11 | Templates
2.12 | Continuation Managers

▼ | 2.12 | Continuation Managers

2.12.1 | General
2.12.2 | No Continuations
2.12.3 | Timeouts
2.12.4 | LRU

On this page:

create-LRU-manager
make-threshold-LRU-manager

Version: 4.1.4
top← prev up next →

##### 2.12.4`` LRU

(require web-server/managers/lru)

"managers/lru.ss" defines a manager constructor:

(create-LRU-manager |  | instance-expiration-handler |  |  |  |
|  | check-interval |  |  |  |
|  | collect-interval |  |  |  |
|  | collect? |  |  |  |
| [ | #:initial-count initial-count |  |  |  |
|  | #:inform-p inform-p]) |  | → |  | manager?

instance-expiration-handler : expiration-handler/c
check-interval : integer?
collect-interval : integer?
collect? : (-> boolean?)
initial-count : integer? = 1
inform-p : (integer? . -> . void) = (lambda _ (void))

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:

(make-threshold-LRU-manager |  | instance-expiration-handler |
|  | memory-threshold) |

→ 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 bytes. 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.

top← prev up next →