Re: kqueue backend for pgbench

From: Roman Khapov <rkhapov(at)yandex-team(dot)ru>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: kqueue backend for pgbench
Date: 2026-10-30 09:02:48
Message-ID: 59A71A20-634A-4A63-97B9-D81DAFF4E36E@yandex-team.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> POC-patch attached, any feedback would be appreciated!

I did some additional performance tests of the patch and found
a degradation with small client counts and trivially simple queries; select()
executes more ~5-8% tps transactions than v1 kevent() implementation.

This is due to the unconditional phase-1 disable/GC sync, which
costs an extra kevent() call per wait. In most cases it can be
skipped though: if the fd set is unchanged since the previous wait,
the kernel-side registrations are already in place, and we only need
to re-submit the enable changes (they are what re-attaches a knote
whose fd was closed and reused for another connection in between)
and wait for events. Attached v2 introduces this optimization.

Some measurements from my laptop (macOS, local server,
prepared protocol, medians of 3-4 runs, delta is v2 relative to select()):
select() v1 v2 delta
SELECT 1, -c 32 -j 1 ~110k ~101k ~106k -4%
SELECT 1, -c 128 -j 8 ~99k ~83k ~103k +4%
-S, -c 32 -j 32 ~96k ~89k ~99k +3%
-S, -c 512 -j 1 ~77k ~76k ~76k -1%
-S, -c 512 -j 8 ~71k ~72k ~73k +3%
-C, -c 128 -j 1 ~358 ~357 ~359 0%
-C -R, -c 128 -j 1 ~358 ~356 ~359 0%
-C -R, -c 128 -j 8 ~502 ~496 ~509 +1%
(values are tps)

With this, v2 matches select() wherever select() can run at all.

--
Best regards,
Roman Khapov

Attachment Content-Type Size
v2-0001-pgbench-add-kqueue-implementation-of-the-socket-s.patch application/octet-stream 8.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-10-30 09:16:45 RE: [PATCH] Preserve replication origin OIDs in pg_upgrade
Previous Message Bertrand Drouvot 2026-10-30 08:41:35 Re: Setting the number of digits after the decimal point with a psql's pset variable