Sphere
Log in Join
☆ 10

I added async to my script and it got slower

I rewrote a script that fetches 100 URLs. Expected it to be much faster. It went from 40 seconds to 52 seconds. I used async def and await on every request but kept the requests library because it is what I know.

⚑ Report

3 replies

☆ 0
N Nate ·2026-09-27#1

requests is synchronous. Calling it inside async def still blocks the event loop, and you pay extra overhead for the coroutine machinery.

⚑ Report
☆ 0
S Sofia ·2026-09-27#2

That explains it. I also had time.sleep between requests to be polite to the server.

⚑ Report
☆ 0
R Robin ·2026-09-27#3

Swap to httpx.AsyncClient and asyncio.gather. For politeness use a semaphore around 10 concurrent requests and await asyncio.sleep instead of time.sleep.

⚑ Report
Log in to reply.