Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider inline script metadadata (PEP723) for benchmark scripts. #968

Open
T-256 opened this issue Oct 12, 2024 · 1 comment
Open

Consider inline script metadadata (PEP723) for benchmark scripts. #968

T-256 opened this issue Oct 12, 2024 · 1 comment

Comments

@T-256
Copy link
Contributor

T-256 commented Oct 12, 2024

ref: #965 (comment)

File formats:

scripts/bench/server.py

# /// script
# requires-python = ">=3.8"
# dependencies = [
#   "uvicorn",
# ]
# ///

import asyncio

import uvicorn

PORT = 1234
RESP = b"a" * 2000
SLEEP = 0.01

...

scripts/bench/client.py

# /// script
# requires-python = ">=3.8"
# dependencies = [
#   "httpcore",
#   "aiohttp",
#   "matplotlib",
#   "pyinstrument",
#   "urllib3",
# ]
# ///

import asyncio
import os
import sys
import time
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager
from typing import Any, Callable, Coroutine, Iterator, List

import aiohttp
import matplotlib.pyplot as plt  # type: ignore[import-untyped]
import pyinstrument
import urllib3
from matplotlib.axes import Axes  # type: ignore[import-untyped]

import httpcore

PORT = 1234
URL = f"http://localhost:{PORT}/req"
REPEATS = 10
REQUESTS = 500
CONCURRENCY = 20
POOL_LIMIT = 100
PROFILE = False
os.environ["HTTPCORE_PREFER_ANYIO"] = "0"

...

Run scripts:

server

$ uv run scripts/bench/server.py

client

$ uv run scripts/bench/client.py
@zanieb
Copy link
Contributor

zanieb commented Oct 12, 2024

As a note, pipx supports this metadata declaration too so it seems pretty reasonable to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants