v1.2.0
1.2.0 [2023-01-08]
- dropping support for Python 3.7, 3.8, 3.9
- adding support for Gunicorn with Uvicorn workers, use dynoscale.uvicorn.DynoscaleUnicornWorker
...
π Complete ASGI example
- Add dynoscale to your app on Heroku:
heroku addons:create dscale - Prepare your amazing webapp, we'll use Starlette served by Gunicorn with Uvicorn workers:
... add Gunicorn config:
# web.py import datetime from starlette.applications import Starlette from starlette.responses import Response from starlette.routing import Route async def home(_): return Response( "Hello from π Starlette π served by Gunicorn using Uvicorn workers and scaled by Dynoscale!\n" f"It's {datetime.datetime.now()} right now.", media_type='text/plain' ) app = Starlette(debug=True, routes=[Route('/', endpoint=home, methods=['GET'])])
# gunicorn.conf.py import os # ENV vars PORT = int(os.getenv('PORT', '3000')) WEB_CONCURRENCY = int(os.getenv('WEB_CONCURRENCY', '10')) # Gunicorn config wsgi_app = "web:app" # β---------- THIS HERE IS ALL OF DYNOSCALE SETUP ----------β # | # worker_class = 'uvicorn.workers.UvicornWorker' | worker_class = 'dynoscale.uvicorn.DynoscaleUvicornWorker' # | # β---------------------------------------------------------β bind = f"0.0.0.0:{PORT}" preload_app = True workers = WEB_CONCURRENCY max_requests = 1000 max_requests_jitter = 50 accesslog = '-' loglevel = 'debug'
- Install all the dependencies:
python -m pip install "uvicorn[standard]" gunicorn dynoscale
- Start it up with:
DYNO=web.1 DYNOSCALE_DEV_MODE=true DYNOSCALE_URL=https://some_request_bin_or_some_such.com gunicorn
- On Heroku, DYNO and DYNOSCALE_URL will be set for you, you should only have
web: gunicornin your procfile. - In this example we start Dynoscale in dev mode to simulate random queue times, don't do this on Heroku!
- On Heroku, DYNO and DYNOSCALE_URL will be set for you, you should only have
- That's it you're done, now Profit! Literally, this will save you money! π°π°π° π
...