pg.ddx.io  psycopg/psycopg GitHub issues and pull requests  
help / color / mirror / Atom feed
From: dvarrazzo (@dvarrazzo) <noreply+dvarrazzo@github.com>
To: psycopg/psycopg <noreply+psycopg-psycopg@github.com>
Subject: Re: [psycopg/psycopg] PR #1469: perf: don't wait on the event loop when the socket is writable
Date: Sun, 01 Nov 2026 23:12:00 +0000
Message-ID: <gh-psycopg-psycopg-1469-rc4437757827@github.com> (raw)
In-Reply-To: <gh-psycopg-psycopg-1469@github.com>
References: <gh-psycopg-psycopg-1469@github.com>

(on psycopg/psycopg/waiting.py:265)

I have run a test and this pretty much becomes a busy loop which, in a long `executemany()`, never yields control, blocking other coroutines, stop canceling, etc.

Therefore let's find a middle ground. I have tested that yielding every 100 null iterations is basically free and keeps the system responsive. So we may add:

```suggestion
                # Don't starve the loop if the socket is always ready.
                nskip += 1
                if nskip >= 100:
                    nskip = 0
                    await asyncio.sleep(0)
                continue
```

(of course with a `nskip = 0` somewhere upstream and maybe a module level `MAX_SKIPPED_WAITS = 100`...)

Can you test a bit with it?

view thread (11+ messages)  latest in thread

Message-ID: <gh-psycopg-psycopg-1469-rc4437757827@github.com>
Permalink:  ../gh-psycopg-psycopg-1469-rc4437757827@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox