Skip to content

abidahmad-rw/django-load-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Load test ADRF async endpoints

Two endpoints for comparing async CPU work vs asyncio.to_thread offloading.

  • GET /api/async-normal/?iterations=5000000
  • GET /api/async-to-thread/?iterations=5000000

Both return JSON including elapsed time and a dummy result.

New: I/O-bound emulation endpoints

  • GET /api/async-io/?duration_s=0.2 — non-blocking I/O latency via asyncio.sleep
  • GET /api/async-io-to-thread/?duration_s=0.2 — blocking time.sleep offloaded to a worker thread

Both return JSON with elapsed time and the input duration.

Setup

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python manage.py migrate --noinput

Note on Python 3.13 (macOS):

  • uvloop and granian may fail to build on Python 3.13 due to missing wheels.
  • This project marks them optional on Python ≥ 3.13. You can:
    • Use plain uvicorn (no uvloop/granian), or
    • Create a Python 3.12 virtualenv if you want to use granian and uvloop.

Run (ASGI with uvicorn)

uvicorn loadtest.asgi:application --host 0.0.0.0 --port 8000 --reload

Run (ASGI with Granian - recommended for load testing)

granian --interface asgi loadtest.asgi:application --host 0.0.0.0 --port 8000 --workers 4 --threads 1
granian --interface wsgi loadtest.wsgi:application --host 0.0.0.0 --port 8000 --workers 4 --threads 8

Then hit:

curl "http://127.0.0.1:8000/api/async-normal/?iterations=6000000"
curl "http://127.0.0.1:8000/api/async-to-thread/?iterations=6000000"
curl "http://127.0.0.1:8000/api/async-io/?duration_s=0.25"
curl "http://127.0.0.1:8000/api/async-io-to-thread/?duration_s=0.25"

Load test helper script (curl-based)

Use the helper to fire N requests with configurable concurrency against any URL:

chmod +x scripts/load_test.sh
./scripts/load_test.sh "http://127.0.0.1:8000/api/async-io/?duration_s=10" 200 20
./scripts/load_test.sh "http://127.0.0.1:8000/api/async-io-to-thread/?duration_s=10" 200 20

About

django-load-test

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors