Skip to content

Commit

Permalink
add ulimit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfiola committed Dec 9, 2023
1 parent bfc079d commit a5ad454
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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
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."""

0 comments on commit a5ad454

Please sign in to comment.