On-Demand Delivery Manager

Deliver messages in the background with immediate thread creation.

Using multiple threads to deliver mail this manager is both better for user interaction and more efficient for delivery of large numbers of messages than the Immediate Delivery Manager. This manager creates new threads on demand (when a message is enqueued for delivery) based on a fairly simple formula:

min(maximum, len(queue) / divisor)

That is, this manager spawns a number of threads relative to the number of messages in the queue.

Installation

This manager is included in the base TurboMail installation.

Usage

Use this as your application-wide manager by setting the following configuration directive:

mail.manager = "demand"

Calls to turbomail.send will enqueue a deep copy of the message and return True. As this manager always declares success when enqueueing a message, it can not be used for debugging. Exceptions encountered when a worker thread attempts to deliver a message will be logged.

Configuration

There are three configuration directives related to this plug-in:

mail.demand.threadsDefaults to 4.
The maximum number of threads to maintain.
mail.demand.divisorDefaults to 10.
For optimum performance, this value should be set to the estimated number of requests a single Provider instance of your chosen type can handle. For example, if using the SMTP Provider, this should match the mail.smtp.count configuration directive.
mail.demand.timeoutDefaults to 60.
This defines how long an idle thread will wait for a new message in the queue before dying of starvation or old age.