Skip to content

Commit

Permalink
Merge pull request #507 from beer-garden/max_concurrent_default
Browse files Browse the repository at this point in the history
Update max_concurrent default calculation
  • Loading branch information
TheBurchLog authored Sep 20, 2024
2 parents c7c5972 + 1771f57 commit 9776051
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Brewtils Changelog
------
TBD

- Updated Plugin `max_concurrent` to support -1 to utilize the default formula that `concurrent.futures.ThreadPoolExecutor` supports `min(32, os.cpu_count() + 4)`
- Updated SystemClient to utilize the local Garden name for default Namespace if none can be determined

3.27.2
Expand Down
4 changes: 4 additions & 0 deletions brewtils/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import json
import logging
import os
from argparse import ArgumentParser

from yapconf import YapconfSpec
Expand Down Expand Up @@ -155,6 +156,9 @@ def load_config(
if "bg_url_prefix" in config:
config.bg_url_prefix = normalize_url_prefix(config.bg_url_prefix)

if "max_concurrent" not in config or config.max_concurrent < 0:
config.max_concurrent = min(32, os.cpu_count() + 4)

return config


Expand Down
7 changes: 5 additions & 2 deletions brewtils/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,11 @@ def _is_json_dict(s):
},
"max_concurrent": {
"type": "int",
"description": "Maximum number of requests to process concurrently",
"default": 5,
"description": (
"Maximum number of requests to process concurrently,"
" -1 will default max concurrent to min(32, os.cpu_count() + 4)"
),
"default": -1,
},
"worker_shutdown_timeout": {
"type": "int",
Expand Down
19 changes: 19 additions & 0 deletions test/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ def params():
}


class TestMaxConcurrent(object):

def test_negative_max_concurrent(self, monkeypatch, params):
monkeypatch.setattr(os, "cpu_count", Mock(return_value=2))

cli_args = ["--bg-host", "the_host", "--max-concurrent", "-1"]
config = load_config(cli_args=cli_args)

assert config["max_concurrent"] == 6

def test_positive_max_concurrent(self, monkeypatch, params):
monkeypatch.setattr(os, "cpu_count", Mock(return_value=2))

cli_args = ["--bg-host", "the_host", "--max-concurrent", "3"]
config = load_config(cli_args=cli_args)

assert config["max_concurrent"] == 3


class TestGetConnectionInfo(object):
def test_kwargs(self, params):
assert params == get_connection_info(**params)
Expand Down

0 comments on commit 9776051

Please sign in to comment.