Mercurial > dovecot > core-2.2
changeset 18331:1bccf90e54ca
imapc: Added throttling settings to imapc_features=throttle:a:b:c
This change could be reverted once good settings are found.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 11 Mar 2015 20:02:20 +0200 |
parents | bac6a6a444d3 |
children | 83662ff4d93d |
files | src/lib-imap-client/imapc-client.c src/lib-imap-client/imapc-client.h src/lib-imap-client/imapc-connection.c src/lib-imap-client/imapc-connection.h src/lib-storage/index/imapc/imapc-settings.c src/lib-storage/index/imapc/imapc-settings.h src/lib-storage/index/imapc/imapc-storage.c |
diffstat | 7 files changed, 55 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-imap-client/imapc-client.c Wed Mar 11 19:44:48 2015 +0200 +++ b/src/lib-imap-client/imapc-client.c Wed Mar 11 20:02:20 2015 +0200 @@ -67,6 +67,14 @@ IMAPC_DEFAULT_CONNECT_TIMEOUT_MSECS; client->set.cmd_timeout_msecs = set->cmd_timeout_msecs != 0 ? set->cmd_timeout_msecs : IMAPC_DEFAULT_COMMAND_TIMEOUT_MSECS; + client->set.throttle_set = set->throttle_set; + + if (client->set.throttle_set.init_msecs == 0) + client->set.throttle_set.init_msecs = IMAPC_THROTTLE_DEFAULT_INIT_MSECS; + if (client->set.throttle_set.max_msecs == 0) + client->set.throttle_set.max_msecs = IMAPC_THROTTLE_DEFAULT_MAX_MSECS; + if (client->set.throttle_set.shrink_min_msecs == 0) + client->set.throttle_set.shrink_min_msecs = IMAPC_THROTTLE_DEFAULT_SHRINK_MIN_MSECS; if (set->ssl_mode != IMAPC_CLIENT_SSL_MODE_NONE) { client->set.ssl_mode = set->ssl_mode;
--- a/src/lib-imap-client/imapc-client.h Wed Mar 11 19:44:48 2015 +0200 +++ b/src/lib-imap-client/imapc-client.h Wed Mar 11 20:02:20 2015 +0200 @@ -54,6 +54,12 @@ #define IMAPC_DEFAULT_CONNECT_TIMEOUT_MSECS (1000*30) #define IMAPC_DEFAULT_COMMAND_TIMEOUT_MSECS (1000*60*5) +struct imapc_throttling_settings { + unsigned int init_msecs; + unsigned int max_msecs; + unsigned int shrink_min_msecs; +}; + struct imapc_client_settings { const char *host; unsigned int port; @@ -82,6 +88,8 @@ /* Timeout for IMAP commands. Reset every time more data is being sent or received. 0 = default. */ unsigned int cmd_timeout_msecs; + + struct imapc_throttling_settings throttle_set; }; struct imapc_command_reply {
--- a/src/lib-imap-client/imapc-connection.c Wed Mar 11 19:44:48 2015 +0200 +++ b/src/lib-imap-client/imapc-connection.c Wed Mar 11 20:02:20 2015 +0200 @@ -25,11 +25,6 @@ #define IMAPC_COMMAND_STATE_AUTHENTICATE_CONTINUE 10000 #define IMAPC_MAX_INLINE_LITERAL_SIZE (1024*32) -/* [THROTTLED] handling behavior */ -#define IMAPC_THROTTLE_INIT_MSECS 50 -#define IMAPC_THROTTLE_MAX_MSECS (16*1000) -#define IMAPC_THROTTLE_SHRINK_MIN_MSECS 500 - enum imapc_input_state { IMAPC_INPUT_STATE_NONE = 0, IMAPC_INPUT_STATE_PLUS, @@ -1135,7 +1130,7 @@ else conn->throttle_msecs = conn->throttle_msecs*3 / 4; - if (conn->throttle_shrink_msecs <= IMAPC_THROTTLE_SHRINK_MIN_MSECS) + if (conn->throttle_shrink_msecs <= conn->client->set.throttle_set.shrink_min_msecs) conn->throttle_shrink_msecs = 0; else conn->throttle_shrink_msecs = conn->throttle_shrink_msecs*3 / 4; @@ -1161,16 +1156,16 @@ it as resp-text-code also in here if it's uppercased). */ if (strstr(reply->text_full, "[THROTTLED]") != NULL) { if (conn->throttle_msecs == 0) - conn->throttle_msecs = IMAPC_THROTTLE_INIT_MSECS; + conn->throttle_msecs = conn->client->set.throttle_set.init_msecs; else if (conn->throttle_msecs < conn->last_successful_throttle_msecs) conn->throttle_msecs = conn->last_successful_throttle_msecs; else { conn->throttle_msecs *= 2; - if (conn->throttle_msecs > IMAPC_THROTTLE_MAX_MSECS) - conn->throttle_msecs = IMAPC_THROTTLE_MAX_MSECS; + if (conn->throttle_msecs > conn->client->set.throttle_set.max_msecs) + conn->throttle_msecs = conn->client->set.throttle_set.max_msecs; } if (conn->throttle_shrink_msecs == 0) - conn->throttle_shrink_msecs = IMAPC_THROTTLE_SHRINK_MIN_MSECS; + conn->throttle_shrink_msecs = conn->client->set.throttle_set.shrink_min_msecs; else conn->throttle_shrink_msecs *= 2; if (conn->to_throttle_shrink != NULL)
--- a/src/lib-imap-client/imapc-connection.h Wed Mar 11 19:44:48 2015 +0200 +++ b/src/lib-imap-client/imapc-connection.h Wed Mar 11 20:02:20 2015 +0200 @@ -3,6 +3,11 @@ #include "imapc-client.h" +/* [THROTTLED] handling behavior */ +#define IMAPC_THROTTLE_DEFAULT_INIT_MSECS 50 +#define IMAPC_THROTTLE_DEFAULT_MAX_MSECS (16*1000) +#define IMAPC_THROTTLE_DEFAULT_SHRINK_MIN_MSECS 500 + struct imapc_client; struct imapc_connection;
--- a/src/lib-storage/index/imapc/imapc-settings.c Wed Mar 11 19:44:48 2015 +0200 +++ b/src/lib-storage/index/imapc/imapc-settings.c Wed Mar 11 20:02:20 2015 +0200 @@ -90,6 +90,23 @@ }; static int +imapc_settings_parse_throttle(struct imapc_settings *set, + const char *throttle_str, const char **error_r) +{ + const char *const *tmp; + + tmp = t_strsplit(throttle_str, ":"); + if (str_array_length(tmp) != 3 || + str_to_uint(tmp[0], &set->throttle_init_msecs) < 0 || + str_to_uint(tmp[1], &set->throttle_max_msecs) < 0 || + str_to_uint(tmp[2], &set->throttle_shrink_min_msecs) < 0) { + *error_r = "imapc_features: Invalid throttle settings"; + return -1; + } + return 0; +} + +static int imapc_settings_parse_features(struct imapc_settings *set, const char **error_r) { @@ -106,6 +123,11 @@ break; } } + if (strncasecmp(*str, "throttle:", 9) == 0) { + if (imapc_settings_parse_throttle(set, *str + 9, error_r) < 0) + return -1; + continue; + } if (list->name == NULL) { *error_r = t_strdup_printf("imapc_features: " "Unknown feature: %s", *str);
--- a/src/lib-storage/index/imapc/imapc-settings.h Wed Mar 11 19:44:48 2015 +0200 +++ b/src/lib-storage/index/imapc/imapc-settings.h Wed Mar 11 20:02:20 2015 +0200 @@ -31,6 +31,9 @@ const char *pop3_deleted_flag; enum imapc_features parsed_features; + unsigned int throttle_init_msecs; + unsigned int throttle_max_msecs; + unsigned int throttle_shrink_min_msecs; }; const struct setting_parser_info *imapc_get_setting_parser_info(void);
--- a/src/lib-storage/index/imapc/imapc-storage.c Wed Mar 11 19:44:48 2015 +0200 +++ b/src/lib-storage/index/imapc/imapc-storage.c Wed Mar 11 20:02:20 2015 +0200 @@ -246,6 +246,10 @@ set.ssl_mode = IMAPC_CLIENT_SSL_MODE_NONE; set.ssl_crypto_device = mail_set->ssl_crypto_device; + set.throttle_set.init_msecs = imapc_set->throttle_init_msecs; + set.throttle_set.max_msecs = imapc_set->throttle_max_msecs; + set.throttle_set.shrink_min_msecs = imapc_set->throttle_shrink_min_msecs; + client = i_new(struct imapc_storage_client, 1); client->refcount = 1; i_array_init(&client->untagged_callbacks, 16);