From 81c0222e4c0344552b9945fa0ef048b04b8d8fc1 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Fri, 15 May 2020 10:24:22 +0200 Subject: [PATCH 1/3] Try to increase open files limit and warn if it is still too low afterwards. adresses #1368 --- locust/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/locust/main.py b/locust/main.py index e5bcfb95ed..186ea21901 100644 --- a/locust/main.py +++ b/locust/main.py @@ -6,6 +6,7 @@ import socket import sys import time +import resource import gevent @@ -153,6 +154,15 @@ def main(): # list() call is needed to consume the dict_view object in Python 3 user_classes = list(user_classes.values()) + try: + # 24576 is the highest value I was able to set this on MacOS Mojave without getting an error + resource.setrlimit(resource.RLIMIT_NOFILE, [24576, resource.RLIM_INFINITY]) + except: + pass # this will fail on linux, not sure about windows + + if resource.getrlimit(resource.RLIMIT_NOFILE)[0] < 10000: + logger.warning("System open file limit setting is not high enough for load testing. See https://docs.locust.io/en/stable/installation.html#increasing-maximum-number-of-open-files-limit for more info.") + # create locust Environment environment = create_environment(user_classes, options, events=locust.events) From b1c2e9c769b09f476c1f4f1ff019a4b2e52deecd Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 18 May 2020 23:07:10 +0200 Subject: [PATCH 2/3] Different MacOS machines (both running Mojave) have differ in the maximum open files they allow a process to set, so reduce the target to what all allow --- locust/main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/locust/main.py b/locust/main.py index 186ea21901..a0fb6bf04a 100644 --- a/locust/main.py +++ b/locust/main.py @@ -155,13 +155,10 @@ def main(): user_classes = list(user_classes.values()) try: - # 24576 is the highest value I was able to set this on MacOS Mojave without getting an error - resource.setrlimit(resource.RLIMIT_NOFILE, [24576, resource.RLIM_INFINITY]) + if resource.getrlimit(resource.RLIMIT_NOFILE)[0] < 10000: + resource.setrlimit(resource.RLIMIT_NOFILE, [10000, resource.RLIM_INFINITY]) except: - pass # this will fail on linux, not sure about windows - - if resource.getrlimit(resource.RLIMIT_NOFILE)[0] < 10000: - logger.warning("System open file limit setting is not high enough for load testing. See https://docs.locust.io/en/stable/installation.html#increasing-maximum-number-of-open-files-limit for more info.") + logger.warning("System open file limit setting is not high enough for load testing, and the OS wouldnt allow locust to increase it by itself. See https://docs.locust.io/en/stable/installation.html#increasing-maximum-number-of-open-files-limit for more info.") # create locust Environment environment = create_environment(user_classes, options, events=locust.events) From 49ce465a1f464e21129afabff204aab0870b585c Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 18 May 2020 23:20:47 +0200 Subject: [PATCH 3/3] Add comment about when setting open file count may be expected to work --- locust/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/locust/main.py b/locust/main.py index a0fb6bf04a..ab9dfc1914 100644 --- a/locust/main.py +++ b/locust/main.py @@ -156,6 +156,8 @@ def main(): try: if resource.getrlimit(resource.RLIMIT_NOFILE)[0] < 10000: + # Increasing the limit to 10000 within a running process should work on at least MacOS. + # It does not work on all OS:es, but we should be no worse off for trying. resource.setrlimit(resource.RLIMIT_NOFILE, [10000, resource.RLIM_INFINITY]) except: logger.warning("System open file limit setting is not high enough for load testing, and the OS wouldnt allow locust to increase it by itself. See https://docs.locust.io/en/stable/installation.html#increasing-maximum-number-of-open-files-limit for more info.")