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

Issue fix: Set ulimit in Grasshopper launch function #29

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions src/grasshopper/lib/grasshopper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
import logging
import os
import resource
import signal
from typing import Dict, List, Optional, Type, Union

Expand Down Expand Up @@ -116,6 +117,7 @@ def launch_test(
TODO: the test - primarily, it's getting a little long and complex but also
TODO: to have better separation of concerns
"""
Grasshopper.set_ulimit()
if isinstance(weighted_user_classes, type): # if it's a class
weighted_user_classes = {weighted_user_classes: 1}
elif isinstance(weighted_user_classes, list):
Expand Down Expand Up @@ -177,3 +179,27 @@ def load_shape(shape_name: str, **kwargs) -> LoadTestShape:
f"Shape {shape_name} does not exist in "
f"grasshopper.lib.util.shapes! Please check the spelling."
)

@staticmethod
def set_ulimit():
"""Increase the maximum number of open files allowed."""
# Adapted from locust source code, main function in locust.main.
try:
minimum_open_file_limit = 10000
jmfiola marked this conversation as resolved.
Show resolved Hide resolved
current_open_file_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
if current_open_file_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],
)
except BaseException:
logger.warning(
f"""System open file limit '{current_open_file_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."""
)
4 changes: 2 additions & 2 deletions src/grasshopper/lib/reporting/iextendedreporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def event_post_suite(
start_epoch: float,
end_epoch: float,
suite_args: dict = {},
**kwargs
**kwargs,
):
"""Call by ReporterExtensions when a post-test event occurs."""

Expand All @@ -49,6 +49,6 @@ def event_post_test(
end_epoch: float,
locust_env: locust_environment = None,
test_args: dict = {},
**kwargs
**kwargs,
):
"""Call by ReporterExtensions when a post-test event occurs."""