Repository navigation
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Documentation build overview
192 files changed ·
|
2950322 to
917f47b
Compare
|
Sorry, but I don't see in any tests, assertion on the |
|
Right, no test asserts the value of |
|
That sounds good to me. |
…e polling for I/O Run callbacks that are scheduled during an event loop iteration eagerly, within the limits of the new asyncio.EventLoopSettings, instead of always waiting for the next I/O poll. asyncio.sleep(0) and loop.stop() end eager processing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@kumaraditya303 have you a chance to review this PR? Thanks. |
|
I'll try to take a look soon |
# Conflicts: # Modules/clinic/_asynciomodule.c.h
# Conflicts: # Modules/clinic/_asynciomodule.c.h
|
A few issues found by Claude: 1. Callbacks can be lost in the final iteration after In the import asyncio, sys
async def worker(fut):
await fut
async def main():
loop = asyncio.get_running_loop()
fut = loop.create_future()
asyncio.create_task(worker(fut))
hop = loop.create_future()
loop.call_soon(hop.set_result, None)
await hop # get into the eager phase
loop.call_soon(fut.set_result, None) # same batch as the stop() callback
loop.call_later(0, sys.exit, 3) # due at the final iteration's poll
asyncio.run(main())On main this exits with status 3. With this PR it hangs forever in 2. A server can miss a short-lived client, and A client's connect / write / close / async def once():
seen = []
async def handler(r, w):
seen.append(1); w.close()
server = await asyncio.start_server(handler, '127.0.0.1', 0)
rd, wr = await asyncio.open_connection(*server.sockets[0].getsockname())
wr.write(b'test msg'); await wr.drain()
wr.close(); await wr.wait_closed()
server.close(); await server.wait_closed()
return bool(seen)On an idle machine (macOS, debug build) the handler ran in 2000/2000 rounds on main and 1961/2000 with this PR. |
I'd like to see if this improves performance of any real world workload. In my experience, such improvements on microbenchmarks don't improve performance of asyncio workloads generally. The microbenchmarks use trivial callbacks but application code callback are much slower so the cost of I/O isn't bottleneck. |
Run callbacks that are scheduled during an event loop iteration eagerly, within a small budget, instead of always waiting for the next I/O poll. This removes one
select()/epoll_wait()call per hop in code that resolves futures or wakes tasks in chains.asyncio.EventLoopSettings(eager_max_time, eager_max_callbacks)andloop.get_settings()/loop.set_settings(). The defaults are 100 µs and 100 callbacks;eager_max_time=0turns eager processing off.asyncio.sleep(0), which still guarantees an I/O poll, and onloop.stop(), which keeps its documented "current batch only" behaviour.Benchmarks (release build, script): a
call_soon()chain is 38% faster,Queueping-pong 25% faster, and a task awaiting a child task 33% faster. Servers with many connections are unchanged. While a long run of callbacks keeps going, timers and I/O can be delayed by up to about 100–200 µs.A few tests that assumed "one task hop = one I/O poll" were adjusted.