feat: add zero-cost performance benchmark workflow
This commit is contained in:
1 parent
54851fc191
commit
5293d93a30
17 files changed
+1366
-8
No files matched your search
Executable
+127
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
env_file="${1:-${repo_root}/compose/.env}"
|
||||
compose_file="${repo_root}/compose/docker-compose.backend.yml"
|
||||
|
||||
if [[ ! -f "$env_file" ]]; then
|
||||
echo "Environment file not found: $env_file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read_value() {
|
||||
local key="$1"
|
||||
sed -n "s/^${key}=//p" "$env_file" | tail -n 1
|
||||
}
|
||||
|
||||
mode="$(read_value TRIPO3D_MODE)"
|
||||
api_key="$(read_value TRIPO3D_API_KEY)"
|
||||
base_url="$(read_value TRIPO3D_BASE_URL)"
|
||||
project_name="$(read_value BACKEND_COMPOSE_PROJECT_NAME)"
|
||||
profile="$(read_value TRIPO3D_MOCK_PROFILE)"
|
||||
|
||||
if [[ "$mode" != "mock" ]]; then
|
||||
echo "TRIPO3D_MODE must be mock; found: ${mode:-unset}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$api_key" ]]; then
|
||||
echo "TRIPO3D_API_KEY must be empty in a zero-cost benchmark." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$base_url" != "http://127.0.0.1:9/tripo-mock-blocked" ]]; then
|
||||
echo "TRIPO3D_BASE_URL is not the blocked loopback sentinel." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$profile" in
|
||||
rate-limits-page)
|
||||
expected_limits=(10 5 1 10 5 10)
|
||||
;;
|
||||
model-pages-conservative)
|
||||
expected_limits=(3 3 1 3 5 10)
|
||||
;;
|
||||
*)
|
||||
echo "TRIPO3D_MOCK_PROFILE was not explicitly selected." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
limit_keys=(
|
||||
TRIPO3D_MOCK_H_CONCURRENCY
|
||||
TRIPO3D_MOCK_P_CONCURRENCY
|
||||
TRIPO3D_MOCK_IMAGE_CONCURRENCY
|
||||
TRIPO3D_MOCK_ANIMATION_CONCURRENCY
|
||||
TRIPO3D_MOCK_POSTPROCESS_CONCURRENCY
|
||||
TRIPO3D_MOCK_MESH_CONCURRENCY
|
||||
)
|
||||
for index in "${!limit_keys[@]}"; do
|
||||
actual_limit="$(read_value "${limit_keys[$index]}")"
|
||||
if [[ "$actual_limit" != "${expected_limits[$index]}" ]]; then
|
||||
echo "${limit_keys[$index]}=${actual_limit:-unset} does not match profile ${profile}." >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$(read_value TRIPO3D_MOCK_QUEUE_DELAY_SECONDS)" != "2" ]] \
|
||||
|| [[ "$(read_value TRIPO3D_MOCK_RUN_DELAY_SECONDS)" != "8" ]]; then
|
||||
echo "Mock queue/run delays do not match the benchmark baseline." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$project_name" ]]; then
|
||||
echo "BACKEND_COMPOSE_PROJECT_NAME is missing." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
compose_command=(
|
||||
docker compose
|
||||
--project-name "$project_name"
|
||||
--env-file "$env_file"
|
||||
-f "$compose_file"
|
||||
)
|
||||
|
||||
"${compose_command[@]}" exec -T backend python -c '
|
||||
import os
|
||||
|
||||
assert os.environ.get("TRIPO3D_MODE") == "mock"
|
||||
assert not os.environ.get("TRIPO3D_API_KEY")
|
||||
assert os.environ.get("TRIPO3D_BASE_URL") == "http://127.0.0.1:9/tripo-mock-blocked"
|
||||
assert os.environ.get("TRIPO3D_MOCK_PROFILE") in {"rate-limits-page", "model-pages-conservative"}
|
||||
|
||||
expected_profiles = {
|
||||
"rate-limits-page": (10, 5, 1, 10, 5, 10),
|
||||
"model-pages-conservative": (3, 3, 1, 3, 5, 10),
|
||||
}
|
||||
actual_limits = tuple(int(os.environ[name]) for name in (
|
||||
"TRIPO3D_MOCK_H_CONCURRENCY",
|
||||
"TRIPO3D_MOCK_P_CONCURRENCY",
|
||||
"TRIPO3D_MOCK_IMAGE_CONCURRENCY",
|
||||
"TRIPO3D_MOCK_ANIMATION_CONCURRENCY",
|
||||
"TRIPO3D_MOCK_POSTPROCESS_CONCURRENCY",
|
||||
"TRIPO3D_MOCK_MESH_CONCURRENCY",
|
||||
))
|
||||
assert actual_limits == expected_profiles[os.environ["TRIPO3D_MOCK_PROFILE"]]
|
||||
assert float(os.environ["TRIPO3D_MOCK_QUEUE_DELAY_SECONDS"]) == 2
|
||||
assert float(os.environ["TRIPO3D_MOCK_RUN_DELAY_SECONDS"]) == 8
|
||||
|
||||
from services.tripo3d import Tripo3DService
|
||||
|
||||
service = Tripo3DService()
|
||||
assert service._api_url("task") == "mock://tripo-local/task"
|
||||
assert service.billable_credits(40) == 0
|
||||
print("Container mock invariants passed.")
|
||||
'
|
||||
|
||||
backend_bind_address="$(read_value BACKEND_BIND_ADDRESS)"
|
||||
backend_host_port="$(read_value BACKEND_HOST_PORT)"
|
||||
health_json="$(curl --fail --silent --show-error --max-time 5 "http://${backend_bind_address}:${backend_host_port}/api/health")"
|
||||
if ! printf '%s' "$health_json" | jq -e --arg profile "$profile" \
|
||||
'.status == "healthy" and .database == "connected" and .tripo_mode == "mock" and .tripo_mock_profile == $profile' >/dev/null; then
|
||||
echo "Backend health response does not report tripo_mode=mock." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Tripo zero-cost runtime verification passed."
|
||||
Reference in new issue
Block a user