diff --git a/locust/main.py b/locust/main.py index e5bcfb95ed..ab9dfc1914 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,14 @@ def main(): # list() call is needed to consume the dict_view object in Python 3 user_classes = list(user_classes.values()) + 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.") + # create locust Environment environment = create_environment(user_classes, options, events=locust.events)