From e4680ab62721cc6c85c84af35da3ddaea1e2e59a Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Sun, 12 Jan 2014 19:39:23 +0200 Subject: [PATCH] core: allow changing TCP keepalive packet idle time using `tcp-keepalive` command-line option or config-file option. This may be useful in certain scenarios. However, server load from keepalive is increased 6-fold if code is hard-changed from 30 to 5. So, provide it as an option instead, and use the previous value as a default (30). Explanation from https://github.com/Kalroth/cgminer-3.7.2-kalroth/commit/015c0643961b1355088967ec681a80f2fe427dd1 Kevin's middlecoin fix, CURL TCP keepalive constants lowered: CURLOPT_TCP_KEEPIDLE from 45 to 5 and CURLOPT_TCP_KEEPINTVL from 30 to 5. Before it'd trigger a keepalive packet after 45 seconds of connection idle time and then again every 30 seconds. Now it triggers a keepalive packet after 5 seconds of connection idle time and then again every 5 seconds. It makes the client more resilient against coin switching pools or just pools with connection issues in general. It will however add a tiny bit pressure to the pool server; but a TCP keepalive probe is only about 60-80 bytes, so I don't think it is an issue. --- cgminer.c | 13 +++++++++++++ miner.h | 1 + util.c | 6 ++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cgminer.c b/cgminer.c index b97daf4e..38b646a2 100644 --- a/cgminer.c +++ b/cgminer.c @@ -135,6 +135,11 @@ bool opt_delaynet; bool opt_disable_pool; static bool no_work; bool opt_worktime; +#if defined(HAVE_LIBCURL) && defined(CURL_HAS_KEEPALIVE) +int opt_tcp_keepalive = 30; +#else +int opt_tcp_keepalive; +#endif char *opt_kernel_path; char *cgminer_path; @@ -1176,6 +1181,14 @@ static struct opt_table opt_config_table[] = { opt_set_bool, &use_syslog, "Use system log for output messages (default: standard error)"), #endif + OPT_WITH_ARG("--tcp-keepalive", + set_int_0_to_9999, opt_show_intval, &opt_tcp_keepalive, +#if defined(HAVE_LIBCURL) && defined(CURL_HAS_KEEPALIVE) + "TCP keepalive packet idle time" +#else + opt_hidden +#endif + ), #ifdef HAVE_ADL OPT_WITH_ARG("--temp-cutoff", set_temp_cutoff, opt_show_intval, &opt_cutofftemp, diff --git a/miner.h b/miner.h index 45837188..e2b3a8ff 100644 --- a/miner.h +++ b/miner.h @@ -971,6 +971,7 @@ extern bool opt_delaynet; extern bool opt_restart; extern bool opt_worktime; extern int swork_id; +extern int opt_tcp_keepalive; #if LOCK_TRACKING extern pthread_mutex_t lockstat_lock; diff --git a/util.c b/util.c index f5472c30..8097eb8d 100644 --- a/util.c +++ b/util.c @@ -255,13 +255,11 @@ static void set_nettime(void) #if CURL_HAS_KEEPALIVE static void keep_curlalive(CURL *curl) { - const int tcp_keepidle = 45; - const int tcp_keepintvl = 30; const long int keepalive = 1; curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, keepalive); - curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, tcp_keepidle); - curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, tcp_keepintvl); + curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, opt_tcp_keepalive); + curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, opt_tcp_keepalive); } #else static void keep_curlalive(CURL *curl)