From 531a04042e120981b5fb78484567dab5bb56c192 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 9 Apr 2023 20:59:55 +0200 Subject: [PATCH] fix: don't use select as wait function if possible select is marginally faster than others, but has the limitation of not allowing FD > 1024, so it is not a good default. If people need performance, they will use wait_c anyway, which is based on poll, and doesn't have the limitation. --- psycopg/psycopg/waiting.py | 9 +-------- tests/test_waiting.py | 8 ++++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py index 7abfc58a9..2c4a10fd1 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -318,14 +318,7 @@ elif selectors.DefaultSelector is getattr(selectors, "SelectSelector", None): wait = wait_select elif selectors.DefaultSelector is getattr(selectors, "EpollSelector", None): - # NOTE: select seems more performing than epoll. It is admittedly unlikely - # that a platform has epoll but not select, so maybe we could kill - # wait_epoll altogether(). More testing to do. - wait = wait_select if hasattr(selectors, "SelectSelector") else wait_epoll - -elif selectors.DefaultSelector is getattr(selectors, "KqueueSelector", None): - # wait_select is faster than wait_selector, probably because of less overhead - wait = wait_select if hasattr(selectors, "SelectSelector") else wait_selector + wait = wait_epoll else: wait = wait_selector diff --git a/tests/test_waiting.py b/tests/test_waiting.py index f5ece29e5..bcfd348c2 100644 --- a/tests/test_waiting.py +++ b/tests/test_waiting.py @@ -83,9 +83,9 @@ def test_wait_bad(pgconn, waitfn): @pytest.mark.skipif( "sys.platform == 'win32'", reason="win32 works ok, but FDs are mysterious" ) -@pytest.mark.parametrize("waitfn", waitfns) -def test_wait_large_fd(dsn, waitfn): - waitfn = getattr(waiting, waitfn) +@pytest.mark.parametrize("fname", waitfns) +def test_wait_large_fd(dsn, fname): + waitfn = getattr(waiting, fname) files = [] try: @@ -100,7 +100,7 @@ def test_wait_large_fd(dsn, waitfn): assert pgconn.socket > 1024 pgconn.send_query(b"select 1") gen = generators.execute(pgconn) - if waitfn is waiting.wait_select: + if fname == "wait_select": with pytest.raises(ValueError): waitfn(gen, pgconn.socket) else: -- 2.47.3