Skip to content

v1.2.0

Choose a tag to compare

@fuho fuho released this 08 Feb 18:07
· 23 commits to main since this release
02778bc

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

  1. Add dynoscale to your app on Heroku: heroku addons:create dscale
  2. Prepare your amazing webapp, we'll use Starlette served by Gunicorn with Uvicorn workers:
    # 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'])])
    ... add Gunicorn config:
    # 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'
  3. Install all the dependencies:
    • python -m pip install "uvicorn[standard]" gunicorn dynoscale
  4. 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: gunicorn in your procfile.
    • In this example we start Dynoscale in dev mode to simulate random queue times, don't do this on Heroku!
  5. That's it you're done, now Profit! Literally, this will save you money! πŸ’°πŸ’°πŸ’° 😏
    ...