diff --git a/balancer-docker-entrypoint.py b/balancer-docker-entrypoint.py index a7f585b..7083047 100644 --- a/balancer-docker-entrypoint.py +++ b/balancer-docker-entrypoint.py @@ -21,14 +21,16 @@ def set_nginx_parameter(): logger_endpoints_ds.info('Running the setting of values in Nginx config') nginx_worker_processes = os.environ.get('BALANCER_WORKER_PROCESSES') nginx_worker_connections = os.environ.get('BALANCER_WORKER_CONNECTIONS') + nginx_worker_timeout = os.environ.get('BALANCER_WORKER_TIMEOUT') path = '/usr/local/openresty/nginx/conf/nginx.conf' try: with open(path, "r") as nginx_conf_read: nginx_config = nginx_conf_read.read() worker_processes = re.sub(r"worker_processes.*", f'worker_processes {nginx_worker_processes};', nginx_config) worker_connections = re.sub(r"worker_connections.*", f'worker_connections {nginx_worker_connections};', worker_processes) + worker_shutdown = re.sub(r"worker_shutdown_timeout.*", f'worker_shutdown_timeout {nginx_worker_timeout};', worker_connections) with open(path, "w") as config_write: - config_write.write(worker_connections) + config_write.write(worker_shutdown) except Exception as msg_set_nginx_conf: logger_endpoints_ds.error(f'Failed when trying to set a value in the Nginx config... {msg_set_nginx_conf}\n') else: diff --git a/config/balancer/lua/docs_balancer.lua b/config/balancer/lua/docs_balancer.lua index 9f106a6..6e4d603 100644 --- a/config/balancer/lua/docs_balancer.lua +++ b/config/balancer/lua/docs_balancer.lua @@ -84,18 +84,28 @@ function _M.balance_ep() end local idx = rr_reserved_dict:get("last_used_index") or 1 + local max_index = #reserved_addresses + + if idx > max_index then + idx = 1 + end random_endpoint = reserved_addresses[idx] -- Update to the next index for the next request idx = idx + 1 - if idx > #matching_addresses then + if idx > #reserved_addresses then idx = 1 end rr_reserved_dict:set("last_used_index", idx) else local idx = rr_live_dict:get("last_used_index") or 1 + local max_index = #matching_addresses + + if idx > max_index then + idx = 1 + end random_endpoint = matching_addresses[idx] diff --git a/config/balancer/nginx.conf b/config/balancer/nginx.conf index 62dc474..079fd62 100644 --- a/config/balancer/nginx.conf +++ b/config/balancer/nginx.conf @@ -2,7 +2,7 @@ worker_processes 1; worker_rlimit_nofile 1047552; -worker_shutdown_timeout 300; +worker_shutdown_timeout 18000; # Enables the use of JIT for regular expressions to speed-up their processing. pcre_jit on;