MCPcopy
hub / github.com/redis/redis-py / run_baseline_scenario_async

Function run_baseline_scenario_async

benchmarks/otel_benchmark.py:902–956  ·  view source on GitHub ↗

Run async benchmark against a baseline git tag using AsyncComprehensiveLoadGenerator. This clones the repo at the specified tag, manipulates sys.path to import the old redis-py version, and runs the benchmark using the async comprehensive load generator for consistent comparison wi

(tag: str, config: LoadGeneratorConfig)

Source from the content-addressed store, hash-verified

900
901
902async def run_baseline_scenario_async(tag: str, config: LoadGeneratorConfig) -> Optional[BenchmarkResult]:
903 """
904 Run async benchmark against a baseline git tag using AsyncComprehensiveLoadGenerator.
905
906 This clones the repo at the specified tag, manipulates sys.path to import
907 the old redis-py version, and runs the benchmark using the async comprehensive
908 load generator for consistent comparison with other scenarios.
909
910 Returns:
911 BenchmarkResult or None on failure
912 """
913 repo_root = Path(__file__).parent.parent
914
915 with TemporaryDirectory() as tmpdir:
916 print(f" Cloning repository at tag {tag}...")
917 try:
918 subprocess.run(
919 ["git", "clone", "--depth", "1", "--branch", tag, str(repo_root), tmpdir],
920 check=True, capture_output=True, text=True
921 )
922 except subprocess.CalledProcessError as e:
923 print(f" ERROR: Failed to clone tag {tag}: {e.stderr}")
924 return None
925
926 # Save original sys.path and modules state
927 original_path = sys.path.copy()
928
929 try:
930 # Clear any existing redis imports and prepend cloned directory
931 _clear_redis_modules()
932 sys.path.insert(0, tmpdir)
933
934 # Import redis from the cloned directory
935 import redis as baseline_redis
936
937 print(f" Using redis from: {baseline_redis.__file__}")
938
939 # Create async comprehensive generator with baseline redis module
940 generator = AsyncComprehensiveLoadGenerator(config, redis_module=baseline_redis)
941 await generator.setup()
942 try:
943 await generator.warmup()
944 result = await generator.run()
945 result.scenario = "baseline"
946 result.metadata["tag"] = tag
947 result.metadata["description"] = "Baseline without OTel code (async)"
948 result.metadata["client_type"] = "async"
949 return result
950 finally:
951 await generator.teardown()
952
953 finally:
954 # Restore original sys.path and clear redis modules again
955 sys.path[:] = original_path
956 _clear_redis_modules()
957
958
959def _get_metric_groups_for_benchmark(metric_group_names: Optional[List[str]]) -> Optional[List[Any]]:

Callers 1

_run_async_benchmarkFunction · 0.85

Calls 10

setupMethod · 0.95
warmupMethod · 0.95
runMethod · 0.95
teardownMethod · 0.95
PathClass · 0.85
_clear_redis_modulesFunction · 0.85
copyMethod · 0.80
runMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected