Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect hard limit when setting open file limit (NOFILE) #2386

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ def is_valid_percentile(parameter):
import resource

minimum_open_file_limit = 10000
current_open_file_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
(soft_limit, hard_limit) = resource.getrlimit(resource.RLIMIT_NOFILE)

if current_open_file_limit < minimum_open_file_limit:
if soft_limit < minimum_open_file_limit:
# 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, [minimum_open_file_limit, resource.RLIM_INFINITY])
resource.setrlimit(resource.RLIMIT_NOFILE, [minimum_open_file_limit, hard_limit])
except BaseException:
logger.warning(
f"""System open file limit '{current_open_file_limit}' is below minimum setting '{minimum_open_file_limit}'.
f"""System open file limit '{soft_limit} is below minimum setting '{minimum_open_file_limit}'.
It's not high enough for load testing, and the OS didn't allow locust to increase it by itself.
See https://github.com/locustio/locust/wiki/Installation#increasing-maximum-number-of-open-files-limit for more info."""
)
Expand Down