]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: don't use select as wait function if possible
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 9 Apr 2023 18:59:55 +0000 (20:59 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 10 Apr 2023 08:45:44 +0000 (10:45 +0200)
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
tests/test_waiting.py

index 7abfc58a964555b9e8c0a85094bdeac9b95bb97a..2c4a10fd1d02a35bb848be598c870198cfca1cf5 100644 (file)
@@ -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
index f5ece29e5c7e447ea614caa80b81aa8a9dad366b..bcfd348c294fc0bde4fcc6fbfa3464705aa7d5b9 100644 (file)
@@ -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: