Skip to content

Instantly share code, notes, and snippets.

@muayyad-alsadi
Created February 2, 2023 07:23
Show Gist options
  • Save muayyad-alsadi/3a1e1cdbafca34df8b17810a09805faf to your computer and use it in GitHub Desktop.
Save muayyad-alsadi/3a1e1cdbafca34df8b17810a09805faf to your computer and use it in GitHub Desktop.
from aiohttp import web
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from starlette.requests import Request as ASGIRequest
from aiohttp_asgi import ASGIResource
aiohttp_app = web.Application()
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
asgi_resource = ASGIResource(app, root_path="/")
aiohttp_app.router.register_resource(asgi_resource)
asgi_resource.lifespan_mount(aiohttp_app)
web.run_app(aiohttp_app)

Serving Files in Python: How FastAPI failed us!

Article: Secret Sauce is Zero-Copy Single Context-Switching

follow up scripts

this is follow up to HN: comments

$ siege -b -c 50 -r 5 'http://127.0.0.1:8080/static/zero.bin'
** SIEGE 4.1.4
** Preparing 50 concurrent users for battle.
The server is now under siege...
Transactions:		         250 hits
Availability:		      100.00 %
Elapsed time:		       58.91 secs
Data transferred:	    23841.86 MB
Response time:		       11.66 secs
Transaction rate:	        4.24 trans/sec
Throughput:		      404.72 MB/sec
Concurrency:		       49.49
Successful transactions:         250
Failed transactions:	           0
Longest transaction:	       12.78
Shortest transaction:	       10.14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment