> 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
v2-0001-pgbench-add-kqueue-implementation-of-the-socket-s.patch
Description: Binary data
