diff options
author | Christian Hesse <mail@eworm.de> | 2015-12-12 12:09:52 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2015-12-12 12:09:52 +0100 |
commit | d7e41016af9ba005390469cabd8e5cda1360b90e (patch) | |
tree | 663682de2fbfa698e1a938600570db03a97391b2 | |
parent | e7afd8bab7e52a1dd53b900fd93fbd97092278d8 (diff) | |
download | paccache-d7e41016af9ba005390469cabd8e5cda1360b90e.tar.gz paccache-d7e41016af9ba005390469cabd8e5cda1360b90e.tar.zst |
allow to limit the number of query threads
-rw-r--r-- | pacredir.c | 14 | ||||
-rw-r--r-- | pacredir.conf | 7 |
2 files changed, 20 insertions, 1 deletions
@@ -20,6 +20,7 @@ const static struct option options_long[] = { /* global variables */ struct hosts * hosts = NULL; struct ignore_interfaces * ignore_interfaces = NULL; +int max_threads = 0; static AvahiSimplePoll *simple_poll = NULL; uint8_t verbose = 0; @@ -368,6 +369,12 @@ static int ahc_echo(void * cls, continue; } + /* Check for limit on threads */ + if (max_threads > 0 && req_count + 1 >= max_threads) { + write_log(stdout, "Hit hard limit for max threads (%d), not doing more requests\n", max_threads); + break; + } + /* This is multi-threading code! * Pointer to struct request does not work as realloc can relocate the data. * We need a pointer to pointer to struct request, store the addresses in @@ -544,8 +551,13 @@ int main(int argc, char ** argv) { /* parse config file */ if ((ini = iniparser_load(CONFIGFILE)) == NULL) { write_log(stderr, "cannot parse file " CONFIGFILE ", continue anyway\n"); - /* continue anyway, there is nothing essential in the config file */ + /* continue anyway, there is nothing essential in the config file */ } else { + /* get max threads */ + max_threads = iniparser_getint(ini, "general:max threads", max_threads); + if (verbose > 0) + write_log(stdout, "Limiting number of threads to a maximum of %d\n", max_threads); + /* store interfaces to ignore */ if ((inistring = iniparser_getstring(ini, "general:ignore interfaces", NULL)) != NULL) { values = strdup(inistring); diff --git a/pacredir.conf b/pacredir.conf index e68393e..75f8514 100644 --- a/pacredir.conf +++ b/pacredir.conf @@ -3,6 +3,13 @@ # We need a default section and call it 'general', so do not change this line. [general] +# By default pacredir does requests to all services it knows about +# simultaneously. Use this to limit the number of threads, the special value +# 0 means unlimited. +# Be aware that pacredir will not find files on servers it does not check! +max threads = 0 +#max threads = 32 + # Some people like to run avahi on network interfaces with low bandwidth or # high cost, for example to use 'Bonjour' (Link-Local Messaging) on it. # Add these interfaces here to ignore them by pacredir. Just give multiple |