mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-11-27 17:00:37 +00:00
fix(benchmark): honor AIO service flags in Docker lifecycle runs (#8493)
* fix(benchmark): honor AIO service flags in Docker lifecycle runs * fix(benchmark): resolve only selected AIO service flags * test(benchmark): support skill uploads in the offline OpenSandbox transport * fix(benchmark): load dotenv before selecting the AIO service profile
This commit is contained in:
parent
ecfe8264ea
commit
b669144246
@ -49,6 +49,34 @@ explicit destruction. `warm_hit` comes from the actual reclaim path. Keep differ
|
||||
images, pool settings, replica limits, user counts and concurrency levels separate;
|
||||
the summary's default grouping does so. Percentiles use inclusive interpolation.
|
||||
|
||||
## Comparing AIO Docker service profiles
|
||||
|
||||
For `bench_provider.py --provider aio-docker`, select a disposable DeerFlow YAML
|
||||
with `DEER_FLOW_CONFIG_PATH`. You can export it in the shell or set it in the
|
||||
default `.env` or the file selected by `DEER_FLOW_ENV_FILE`. Set the service
|
||||
switches under `sandbox.environment`:
|
||||
|
||||
```yaml
|
||||
sandbox:
|
||||
use: deerflow.community.aio_sandbox:AioSandboxProvider
|
||||
environment:
|
||||
DISABLE_CODE_SERVER: "true"
|
||||
DISABLE_JUPYTER: "true"
|
||||
```
|
||||
|
||||
The benchmark forwards these two switches and any of `DISABLE_BROWSER`,
|
||||
`DISABLE_MCP_BROWSER`, `DISABLE_NODEJS_REPL`, and `DISABLE_VNC` that are present.
|
||||
Use the strings `"true"` and `"false"`, or a DeerFlow `$VAR` reference that
|
||||
resolves to one of them. Other sandbox environment entries stay out of the
|
||||
benchmark container and result rows.
|
||||
|
||||
Run the same command and pinned image once per config, using a fresh run ID and
|
||||
output file each time. For the baseline, omit the switches. Each JSONL row
|
||||
records the requested overrides in `aio_service_profile`. A run with no
|
||||
overrides (including an unset `DEER_FLOW_CONFIG_PATH`) records `image-defaults`.
|
||||
The default summary groups by profile and shows `?` for older rows without it.
|
||||
Verify that the pinned image honors each switch before interpreting timings.
|
||||
|
||||
## OpenSandbox
|
||||
|
||||
`--provider opensandbox` uses the production OpenSandbox provider and reads its
|
||||
|
||||
39
backend/scripts/benchmark/sandbox/bench_provider.py
Executable file → Normal file
39
backend/scripts/benchmark/sandbox/bench_provider.py
Executable file → Normal file
@ -231,6 +231,36 @@ def _make_boxlite_provider(config: dict[str, Any]) -> tuple[Any, dict[str, Any]]
|
||||
return provider, sandbox_attrs
|
||||
|
||||
|
||||
# Keep benchmark inputs and public profile labels limited to the AIO service switches.
|
||||
_AIO_SERVICE_FLAGS = ("DISABLE_BROWSER", "DISABLE_CODE_SERVER", "DISABLE_JUPYTER", "DISABLE_MCP_BROWSER", "DISABLE_NODEJS_REPL", "DISABLE_VNC")
|
||||
|
||||
|
||||
def _aio_service_environment() -> dict[str, str]:
|
||||
import yaml
|
||||
|
||||
from deerflow.config.app_config import AppConfig
|
||||
|
||||
# Importing app_config loads the dotenv file that can select the benchmark YAML.
|
||||
config_path = os.getenv("DEER_FLOW_CONFIG_PATH")
|
||||
if not config_path:
|
||||
return {}
|
||||
with AppConfig.resolve_config_path(config_path).open(encoding="utf-8") as stream:
|
||||
config = yaml.safe_load(stream)
|
||||
if config is None:
|
||||
return {}
|
||||
if not isinstance(config, dict) or not isinstance(sandbox := config.get("sandbox", {}), dict):
|
||||
raise ValueError("Expected a config mapping with a sandbox mapping")
|
||||
environment = sandbox.get("environment", {})
|
||||
if not isinstance(environment, dict):
|
||||
raise ValueError("sandbox.environment must be a mapping")
|
||||
|
||||
flags = {key: AppConfig.resolve_env_variables(environment[key]) for key in _AIO_SERVICE_FLAGS if key in environment}
|
||||
for key, value in flags.items():
|
||||
if value not in ("true", "false"):
|
||||
raise ValueError(f"sandbox.environment.{key} must be 'true' or 'false' for the AIO benchmark")
|
||||
return flags
|
||||
|
||||
|
||||
def _make_aio_provider(config: dict[str, Any]) -> tuple[Any, dict[str, Any]]:
|
||||
"""Create an AioSandboxProvider with stub config."""
|
||||
from deerflow.community.aio_sandbox.aio_sandbox_provider import AioSandboxProvider
|
||||
@ -562,7 +592,11 @@ def _write_results(results: list[BenchResult], output_path: Path, config_used: d
|
||||
result.image = config_used.get("image")
|
||||
with output_path.open("a", encoding="utf-8") as stream:
|
||||
for result in results:
|
||||
stream.write(json.dumps(asdict(result), ensure_ascii=False) + "\n")
|
||||
row = asdict(result)
|
||||
if result.provider == "aio-docker":
|
||||
environment = config_used.get("environment", {})
|
||||
row["aio_service_profile"] = ",".join(f"{key}={environment[key]}" for key in _AIO_SERVICE_FLAGS if key in environment) or "image-defaults"
|
||||
stream.write(json.dumps(row, ensure_ascii=False) + "\n")
|
||||
|
||||
|
||||
def _run_scenario(
|
||||
@ -782,6 +816,9 @@ def main(argv: list[str] | None = None) -> int:
|
||||
"container_prefix": f"deerflow-bench-{args.run_id}",
|
||||
}
|
||||
|
||||
if args.provider == "aio-docker":
|
||||
config["environment"] = _aio_service_environment()
|
||||
|
||||
factory = PROVIDER_FACTORIES[args.provider]
|
||||
provider, config_used = factory(config)
|
||||
_install_warm_hit_tracking(provider)
|
||||
|
||||
@ -99,6 +99,7 @@ _COLUMNS = [
|
||||
"idle_timeout",
|
||||
"health_check_skip_seconds",
|
||||
"image",
|
||||
"aio_service_profile",
|
||||
"count",
|
||||
"ok",
|
||||
"errors",
|
||||
@ -154,7 +155,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
p.add_argument("inputs", nargs="+", help="JSONL file(s) from sandbox/bench_provider.py")
|
||||
p.add_argument(
|
||||
"--group",
|
||||
default="provider,scenario,workload,concurrency,users,no_warmpool,replicas,idle_timeout,health_check_skip_seconds,image",
|
||||
default="provider,scenario,workload,concurrency,users,no_warmpool,replicas,idle_timeout,health_check_skip_seconds,image,aio_service_profile",
|
||||
help="Comma-separated grouping dimensions (default includes provider configuration and user count)",
|
||||
)
|
||||
p.add_argument(
|
||||
|
||||
@ -7,6 +7,7 @@ import threading
|
||||
import time
|
||||
from datetime import timedelta
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import ANY, Mock
|
||||
|
||||
import pytest
|
||||
|
||||
@ -26,6 +27,7 @@ class Remote:
|
||||
self.destroy_error = False
|
||||
self.command_error = False
|
||||
self.commands = SimpleNamespace(run=self.run)
|
||||
self.files = Mock(spec_set=["write_file"])
|
||||
self.state = ""
|
||||
|
||||
def run(self, command, **kwargs):
|
||||
@ -66,6 +68,11 @@ def transport(monkeypatch, tmp_path):
|
||||
|
||||
monkeypatch.setattr(provider_module, "_import_sdk", lambda: (SimpleNamespace(create=create), SimpleNamespace, SimpleNamespace))
|
||||
monkeypatch.setenv("DEER_FLOW_HOME", str(tmp_path / "home"))
|
||||
skills_root = tmp_path / "skills"
|
||||
monkeypatch.setenv("DEER_FLOW_SKILLS_PATH", str(skills_root))
|
||||
skill = skills_root / "public" / "bench-skill" / "SKILL.md"
|
||||
skill.parent.mkdir(parents=True)
|
||||
skill.write_bytes(b"---\nname: bench-skill\ndescription: Benchmark fixture\n---\n")
|
||||
config = AppConfig(
|
||||
sandbox=SandboxConfig(
|
||||
use="deerflow.community.opensandbox:OpenSandboxProvider",
|
||||
@ -79,9 +86,13 @@ def transport(monkeypatch, tmp_path):
|
||||
environment={"BENCH_SECRET": "sentinel-environment"},
|
||||
)
|
||||
)
|
||||
# Benchmark worker threads load the config from disk outside the caller's context.
|
||||
config_path = tmp_path / "config.yaml"
|
||||
config_path.write_text(config.model_dump_json(exclude_unset=True), encoding="utf-8")
|
||||
monkeypatch.setenv("DEER_FLOW_CONFIG_PATH", str(config_path))
|
||||
push_current_app_config(config)
|
||||
try:
|
||||
yield SimpleNamespace(remotes=remotes, requests=requests, config=config)
|
||||
yield SimpleNamespace(remotes=remotes, requests=requests, config=config, skill=skill)
|
||||
finally:
|
||||
pop_current_app_config()
|
||||
|
||||
@ -92,6 +103,7 @@ def test_factory_preserves_connection_config_without_exporting_secrets(transport
|
||||
assert get_app_config() is transport.config
|
||||
assert transport.config.sandbox.image == "test-image@sha256:fixture"
|
||||
sid = provider.acquire("thread", user_id="owner")
|
||||
transport.remotes[0].files.write_file.assert_any_call(ANY, transport.skill.read_bytes(), mode=644)
|
||||
request = transport.requests[0]
|
||||
assert request["image"] == "test-image@sha256:fixture"
|
||||
assert request["env"] == {"BENCH_SECRET": "sentinel-environment"}
|
||||
|
||||
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@ -68,58 +69,92 @@ class _FakeSandbox:
|
||||
return self.output
|
||||
|
||||
|
||||
def test_aio_provider_default_leaves_image_unset(monkeypatch, tmp_path):
|
||||
captured_config: dict[str, Any] = {}
|
||||
def test_aio_provider_default_uses_image_defaults(monkeypatch, tmp_path):
|
||||
monkeypatch.delenv("DEER_FLOW_CONFIG_PATH", raising=False)
|
||||
captured = {}
|
||||
|
||||
def _factory(config: dict[str, Any]):
|
||||
captured_config.update(config)
|
||||
return _FakeProvider(), {"replicas": config["replicas"], "idle_timeout": config["idle_timeout"], "image": config.get("image")}
|
||||
def factory(config):
|
||||
captured.update(config)
|
||||
return _FakeProvider(), config
|
||||
|
||||
monkeypatch.setitem(bench.PROVIDER_FACTORIES, "aio-docker", _factory)
|
||||
monkeypatch.setitem(bench.PROVIDER_FACTORIES, "aio-docker", factory)
|
||||
output = tmp_path / "out.jsonl"
|
||||
assert bench.main(["--provider", "aio-docker", "--iterations", "1", "--warmup-iterations", "0", "--output", str(output)]) == 0
|
||||
assert captured["image"] is None
|
||||
assert captured["environment"] == {}
|
||||
assert json.loads(output.read_text(encoding="utf-8"))["aio_service_profile"] == "image-defaults"
|
||||
|
||||
rc = bench.main(
|
||||
[
|
||||
"--provider",
|
||||
"aio-docker",
|
||||
"--iterations",
|
||||
"0",
|
||||
"--warmup-iterations",
|
||||
"0",
|
||||
"--output",
|
||||
str(tmp_path / "out.jsonl"),
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("env_file", [".env", "benchmark.env"])
|
||||
def test_aio_cli_reads_config_path_from_dotenv_on_startup(tmp_path, env_file):
|
||||
(tmp_path / "profile.yaml").write_bytes(b'sandbox:\n environment:\n DISABLE_JUPYTER: "$BENCH_JUPYTER"\n')
|
||||
(tmp_path / env_file).write_bytes(b"DEER_FLOW_CONFIG_PATH=profile.yaml\nBENCH_JUPYTER=true\n")
|
||||
env = {key: os.environ[key] for key in ("PATH", "SYSTEMROOT") if key in os.environ}
|
||||
env["PYTHONPATH"] = str(Path(__file__).resolve().parents[1])
|
||||
if env_file != ".env":
|
||||
env["DEER_FLOW_ENV_FILE"] = env_file
|
||||
|
||||
# A fresh interpreter exercises the CLI's first config import. Stop at the Docker boundary.
|
||||
script = """
|
||||
import json
|
||||
from scripts.benchmark.sandbox import bench_provider as bench
|
||||
|
||||
def capture(config):
|
||||
print(json.dumps(config["environment"]))
|
||||
raise SystemExit(0)
|
||||
|
||||
bench.PROVIDER_FACTORIES["aio-docker"] = capture
|
||||
bench.main(["--provider", "aio-docker"])
|
||||
"""
|
||||
run = subprocess.run([sys.executable, "-c", script], cwd=tmp_path, env=env, capture_output=True, encoding="utf-8", timeout=30)
|
||||
assert run.returncode == 0, run.stderr
|
||||
assert json.loads(run.stdout) == {"DISABLE_JUPYTER": "true"}
|
||||
|
||||
|
||||
def test_aio_cli_forwards_selected_service_flags_and_records_profile(monkeypatch, tmp_path):
|
||||
config_path = tmp_path / "config.yaml"
|
||||
config_path.write_text(
|
||||
"""\
|
||||
sandbox:
|
||||
use: deerflow.community.aio_sandbox:AioSandboxProvider
|
||||
environment:
|
||||
DISABLE_JUPYTER: "$BENCH_JUPYTER"
|
||||
DISABLE_CODE_SERVER: "false"
|
||||
OTHER: private-fixture
|
||||
UNUSED: "$BENCH_UNSET_UNUSED"
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setenv("DEER_FLOW_CONFIG_PATH", str(config_path))
|
||||
monkeypatch.delenv("BENCH_UNSET_UNUSED", raising=False)
|
||||
monkeypatch.setenv("BENCH_JUPYTER", "true")
|
||||
captured = {}
|
||||
|
||||
assert rc == 0
|
||||
assert captured_config["image"] is None
|
||||
def factory(config):
|
||||
captured.update(config)
|
||||
return _FakeProvider(), config
|
||||
|
||||
monkeypatch.setitem(bench.PROVIDER_FACTORIES, "aio-docker", factory)
|
||||
output = tmp_path / "out.jsonl"
|
||||
assert bench.main(["--provider", "aio-docker", "--image", "custom/aio:latest", "--iterations", "1", "--warmup-iterations", "0", "--output", str(output)]) == 0
|
||||
assert captured["image"] == "custom/aio:latest"
|
||||
assert captured["environment"] == {"DISABLE_CODE_SERVER": "false", "DISABLE_JUPYTER": "true"}
|
||||
data = output.read_text(encoding="utf-8")
|
||||
assert json.loads(data)["aio_service_profile"] == "DISABLE_CODE_SERVER=false,DISABLE_JUPYTER=true"
|
||||
assert "private-fixture" not in data
|
||||
|
||||
def test_explicit_aio_provider_image_is_forwarded(monkeypatch, tmp_path):
|
||||
captured_config: dict[str, Any] = {}
|
||||
captured.clear()
|
||||
monkeypatch.delenv("BENCH_JUPYTER")
|
||||
with pytest.raises(ValueError, match="BENCH_JUPYTER"):
|
||||
bench.main(["--provider", "aio-docker", "--output", str(output)])
|
||||
assert not captured
|
||||
|
||||
def _factory(config: dict[str, Any]):
|
||||
captured_config.update(config)
|
||||
return _FakeProvider(), {"replicas": config["replicas"], "idle_timeout": config["idle_timeout"], "image": config.get("image")}
|
||||
|
||||
monkeypatch.setitem(bench.PROVIDER_FACTORIES, "aio-docker", _factory)
|
||||
|
||||
rc = bench.main(
|
||||
[
|
||||
"--provider",
|
||||
"aio-docker",
|
||||
"--image",
|
||||
"custom/aio:latest",
|
||||
"--iterations",
|
||||
"0",
|
||||
"--warmup-iterations",
|
||||
"0",
|
||||
"--output",
|
||||
str(tmp_path / "out.jsonl"),
|
||||
]
|
||||
)
|
||||
|
||||
assert rc == 0
|
||||
assert captured_config["image"] == "custom/aio:latest"
|
||||
monkeypatch.setenv("BENCH_JUPYTER", "private-invalid-value")
|
||||
with pytest.raises(ValueError, match="DISABLE_JUPYTER") as exc:
|
||||
bench.main(["--provider", "aio-docker", "--output", str(output)])
|
||||
assert "private-invalid-value" not in str(exc.value)
|
||||
assert not captured
|
||||
assert output.read_text(encoding="utf-8") == data
|
||||
|
||||
|
||||
def test_failed_turn_releases_acquired_sandbox() -> None:
|
||||
@ -506,6 +541,17 @@ def test_default_summary_does_not_merge_cold_baseline_with_warm_pool(tmp_path, c
|
||||
assert {r["no_warmpool"] for r in rows} == {True, False}
|
||||
|
||||
|
||||
def test_default_summary_separates_service_profiles_and_legacy_rows(tmp_path, capsys):
|
||||
base = {"provider": "aio-docker", "success": True, "acquire_ms": 1, "total_ms": 2}
|
||||
profiles = ["image-defaults", "DISABLE_JUPYTER=true", "DISABLE_JUPYTER=true"]
|
||||
rows = [base, *({**base, "aio_service_profile": profile} for profile in profiles)]
|
||||
path = tmp_path / "profiles.jsonl"
|
||||
path.write_text("\n".join(json.dumps(row) for row in rows), encoding="utf-8")
|
||||
assert summarize.main([str(path), "--json"]) == 0
|
||||
summary = json.loads(capsys.readouterr().out)
|
||||
assert {row["aio_service_profile"]: row["count"] for row in summary} == {"?": 1, "image-defaults": 1, "DISABLE_JUPYTER=true": 2}
|
||||
|
||||
|
||||
def test_summary_failed_data_exits_nonzero(tmp_path, capsys):
|
||||
path = tmp_path / "results.jsonl"
|
||||
path.write_text(json.dumps({"provider": "aio-docker", "success": False}))
|
||||
@ -627,7 +673,8 @@ def test_aio_factory_uses_current_config_contract_and_reports_effective_image(mo
|
||||
self._config = real_provider._load_config(self)
|
||||
|
||||
monkeypatch.setattr(provider_module, "AioSandboxProvider", ConfigOnlyProvider)
|
||||
provider, config = bench._make_aio_provider({"container_prefix": "deerflow-bench-test"})
|
||||
provider, config = bench._make_aio_provider({"container_prefix": "deerflow-bench-test", "environment": {"DISABLE_JUPYTER": "true"}})
|
||||
assert provider._config["environment"]["DISABLE_JUPYTER"] == "true"
|
||||
assert provider._config["network"]["mode"] == "open"
|
||||
assert config["image"] == provider._config["image"]
|
||||
assert config["image"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user