Web server: Dynamic memory use and OOM handling

OOM policies

If OOM occurs during server start, then the server is not started. An error code is propagated from WebServer::Start() to indicate this condition, the caller must handle it further.

If OOM occurs while a request is being served, then that service is aborted, the connection is closed, and any memory used to service the request is freed. The condition is propagated to a central point within the webserver (WebServerImpl::SignalOOM), but the default action there is to drop the condition on the floor.

Who handles OOM?

The module, for the most part. See above.

Flow

The server is started and stopped from elsewhere in Opera through WebServer::Start() and WebServer::Stop(). All external api calls must only go to classes defined in the webserver directory. All calls to functions defined in webserver/src/ are prohibited. We also have entries points through the OpStocket callbacks and messageObject callbacks in ControlChannel, WebserverRendezvous, WebServerConnectionListener and WebServerConnection objects.

Heap memory usage

Heap memory is allocated to store incoming data and as data buffers for data in transit. These buffers live as long as the request does and are then immediately freed.

Static memory usage

Currently there are three global pointers defined in webserver_module.h

Caching and freeing memory

The module at present does no caching by itself.

Freeing memory on exit

All memory is freed when the webserver is stopped. Terminate should stop the server by calling WebServer::Stop().

Memory tuning

There are several tweaks to tweak buffer sizes. Take a look at module.tweaks for more information

Tests
Converage
Design choices
Improvements