diff --git a/vsb/cmdline_args.py b/vsb/cmdline_args.py index 849de23..d7bfaca 100644 --- a/vsb/cmdline_args.py +++ b/vsb/cmdline_args.py @@ -124,9 +124,11 @@ def add_vsb_cmdline_args( type=int, metavar="", dest="num_users", - default=1, - help="Number of database clients to execute the workload. Default is %(" - "default)s", + default=None, + help="Number of database clients to execute the workload. If not specified " + "and --requests_per_sec is set, the number of users is automatically " + "calculated to achieve the target QPS (assuming 500ms request latency). " + "Otherwise defaults to 1.", ) general_group.add_argument( "--processes", diff --git a/vsb/locustfile.py b/vsb/locustfile.py index 8e2de53..e339b51 100644 --- a/vsb/locustfile.py +++ b/vsb/locustfile.py @@ -109,7 +109,7 @@ def qutting_listener(environment, **_kwargs): def setup_environment(environment, **_kwargs): env = environment options = env.parsed_options - num_users = options.num_users or 1 + num_users = options.num_users logger.debug(f"setup_environment(): runner={type(environment.runner)}") diff --git a/vsb/main.py b/vsb/main.py index 104d47c..edee9ae 100755 --- a/vsb/main.py +++ b/vsb/main.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import math import sys from pathlib import Path @@ -41,6 +42,18 @@ def main(): args = parser.parse_args() validate_parsed_args(parser, args) + # Auto-calculate the number of users if not explicitly specified. + # Assuming a conservative 500ms request latency, each user can issue + # at most 2 requests/sec. We provision enough users to comfortably + # achieve the target QPS. + if args.num_users is None: + if args.requests_per_sec > 0: + assumed_latency = 0.5 # 500ms + args.num_users = max(1, math.ceil(args.requests_per_sec * assumed_latency)) + else: + args.num_users = 1 + sys.argv += ["--users", str(args.num_users)] + log_base = Path(args.log_dir) / args.database vsb.log_dir = setup_logging(log_base=log_base, level=args.loglevel) requests_per_sec = (