500 Mb process
100 ms response time
70% serving requests
7 RPS
5% CPU usage
500 Mb process
103-105 ms response time
100 RPS
70% CPU usage
Latency: 50 ms → 3-15 sec
Response: 50 ms → 0.5-1 sec
Slow: 0.04 / 10 RPS
async def combine_things(http, u1, u2): value1 = await get_json1() value2 = await get_json2() return combine(value1, value2)
def combine_things(http, u1, u2): (value1, value2), _ = await asyncio.wait([ get_json1(u1), get_json2(u2), ]) return combine(value1, value2)
Nginx → Backend
with aiohttp.Timeout(10): async with session.get(url) as response: assert response.status == 200 return await response.read()
100 input connections
10 db connections
asyncio.async ≠ celery
Pool Size = 1
Browser → Gateway → Backend
async def transfer(amount, payer, payee, server): if not payer.sufficient_funds(amount): raise InsufficientFunds() payee.deposit(amount) log_transfer(amount) payer.withdraw(amount) await server.update_balances([payer, payee])
async def transfer(amount, payer, payee, server): with lock(payer, payee): if not payer.sufficient_funds(amount): raise InsufficientFunds() payee.deposit(amount) log_transfer(amount) payer.withdraw(amount) server.update_balances([payer, payee])