On Sat, Jun 20, 2015 at 07:18:34PM +0000, Viktor Dukhovni wrote:
> If there is to be a global rate delay, the transport process limit
> might as well be equal to 1. At which point to implement a rate
> delay, it suffices for each delivery to take a minimum amount of
> time, so an option along the lines of:
>
> smtp_minimum_delay = 0s
>
> would do the trick, by having the smtp_delivery_agent sleep if
> necessary to ensure that deliveries take at least that amount of
> time.
>
> This would require no changes to the queue manager, which is a
> rather complex program that is best left as-is.
>
> --
> Viktor.
Thanks for the feedback! Slowing down the SMTP delivery agent sure was easy...
there are a few things to clean up, but the patch below seems to be giving the
behavior I need.
-Adam
==========================
WIP minimum delay implemented in smtp delivery agent
FIXME:
* Document config parameter.
* Consider renaming to "smtp_rate_delay".
* Do LMTP as well.
* Test and assert process concurrency == 1 when using a rate delay.
* Conflicts with connection timeout < rate delay.
diff --git a/postfix/src/global/mail_params.h b/postfix/src/global/mail_params.h
index 823fc0c..d3ac1c0 100644
--- a/postfix/src/global/mail_params.h
+++ b/postfix/src/global/mail_params.h
@@ -1025,6 +1025,10 @@ extern char *var_smtp_cache_dest;
#endif
extern bool var_smtp_cache_demand;
+#define VAR_SMTP_MINIMUM_DELAY "smtp_minimum_delay"
+#define DEF_SMTP_MINIMUM_DELAY "0s"
+extern int var_smtp_minimum_delay;
+
#define VAR_SMTP_CONN_TMOUT "smtp_connect_timeout"
#define DEF_SMTP_CONN_TMOUT "30s"
extern int var_smtp_conn_tmout;
@@ -1813,6 +1817,10 @@ extern bool var_lmtp_cache_conn;
#define DEF_LMTP_SKIP_QUIT_RESP 0
extern bool var_lmtp_skip_quit_resp;
+#define VAR_LMTP_MINIMUM_DELAY "smtp_minimum_delay"
+#define DEF_LMTP_MINIMUM_DELAY "0s"
+extern int var_lmtp_minimum_delay;
+
#define VAR_LMTP_CONN_TMOUT "lmtp_connect_timeout"
#define DEF_LMTP_CONN_TMOUT "0s"
extern int var_lmtp_conn_tmout;
diff --git a/postfix/src/smtp/smtp.c b/postfix/src/smtp/smtp.c
index e1a8d2c..c1a27b9 100644
--- a/postfix/src/smtp/smtp.c
+++ b/postfix/src/smtp/smtp.c
@@ -801,6 +801,7 @@
* Tunable parameters. These have compiled-in defaults that can be overruled
* by settings in the global Postfix configuration file.
*/
+int var_smtp_minimum_delay;
int var_smtp_conn_tmout;
int var_smtp_helo_tmout;
int var_smtp_xfwd_tmout;
@@ -1022,6 +1023,11 @@ static void smtp_service(VSTREAM *client_stream, char
*service, char **argv)
status = deliver_message(service, request);
deliver_request_done(client_stream, request, status);
}
+
+ if (var_smtp_minimum_delay > 0) {
+ msg_warn("Waiting %d seconds after smtp delivery",
var_smtp_minimum_delay);
+ sleep(var_smtp_minimum_delay);
+ }
}
/* post_init - post-jail initialization */
diff --git a/postfix/src/smtp/smtp_params.c b/postfix/src/smtp/smtp_params.c
index 2346441..6c4873a 100644
--- a/postfix/src/smtp/smtp_params.c
+++ b/postfix/src/smtp/smtp_params.c
@@ -64,6 +64,7 @@
0,
};
static const CONFIG_TIME_TABLE smtp_time_table[] = {
+ VAR_SMTP_MINIMUM_DELAY, DEF_SMTP_MINIMUM_DELAY,
&var_smtp_minimum_delay, 0, 0,
VAR_SMTP_CONN_TMOUT, DEF_SMTP_CONN_TMOUT, &var_smtp_conn_tmout, 0, 0,
VAR_SMTP_HELO_TMOUT, DEF_SMTP_HELO_TMOUT, &var_smtp_helo_tmout, 1, 0,
VAR_SMTP_XFWD_TMOUT, DEF_SMTP_XFWD_TMOUT, &var_smtp_xfwd_tmout, 1, 0,