Adam Roses Wight:
> I've started writing this feature to determine whether it's feasible
> with the current architecture, but no success yet, this doesn't seem
> to limit the number of jobs which are popped from the queue:

I just had to find out why it did not work (While it is possible
to implement rate delays in the SMTP client, it is nicer in the
queue manager as it avoids the need to make master.cf updates.)

The trick is to start enforcement at the *beginning* of a mail
delivery transaction, instead of the end like you did.

- Define a new flag, similar to your SUSPEND flag but called
  RATE_LOCK, because we don't suspend the transport. The flag is
  raised before the start of a delivery transaction, and is normally
  cleared at the end of a delivery transaction. While the flag is
  raised, no other delivery transaction is allowed for the transport.

- In qmgr_transport_select(), skip transports whose RATE_LOCK flag
  is raised. Normally, qmgr_transport_select() returns a transport
  handle that the caller then passes to qmgr_transport_alloc().

- In qmgr_transport_alloc(), raise the RATE_LOCK flag for the specified
  transport. Then, open a connection to a delivery agent as usual.
 
- In qmgr_transport_event(), insert the transport rate delay. Then,
  call qmgr_deliver() as usual.

- In qmgr_transport_unthrottle(), clear the RATE_LOCK flag for the
  specified transport.

- Starting with qmgr_deliver(), make sure that all code paths either
  terminate the queue manager, call qmgr_transport_unthrottle(),
  or that they call qmgr_transport_throttle() which after some delay
  calls qmgr_transport_unthrottle(). This required only one minor
  change in qmgr_deliver_update().

Proof-of-concept patch is at:
ftp://ftp.porcupine.org//mirrors/postfix-release/experimental/feature-patches/20150621-transport-rate-delay-patch
ftp://ftp.porcupine.org//mirrors/postfix-release/experimental/feature-patches/20150621-transport-rate-delay-patch.asc
ftp://ftp.porcupine.org//mirrors/postfix-release/experimental/feature-patches/20150621-transport-rate-delay-patch.sig

Most of the changes are for new parameters and documentation.  I
didn't change the names of existing identifiers to keep the patch
small. That can happen later.

        Wietse

Reply via email to