Automatically sizing the IO worker pool

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Automatically sizing the IO worker pool
Date: 2025-04-12 16:59:54
Message-ID: CA+hUKG+m4xV0LMoH2c=oRAdEXuCnh+tGBTWa7uFeFMGgTLAw+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

It's hard to know how to set io_workers=3. If it's too small,
io_method=worker's small submission queue overflows and it silently
falls back to synchronous IO. If it's too high, it generates a lot of
pointless wakeups and scheduling overhead, which might be considered
an independent problem or not, but having the right size pool
certainly mitigates it. Here's a patch to replace that GUC with:

io_min_workers=1
io_max_workers=8
io_worker_idle_timeout=60s
io_worker_launch_interval=500ms

It grows the pool when a backlog is detected (better ideas for this
logic welcome), and lets idle workers time out. IO jobs were already
concentrated into the lowest numbered workers, partly because that
seemed to have marginally better latency than anything else tried so
far due to latch collapsing with lucky timing, and partly in
anticipation of this.

The patch also reduces bogus wakeups a bit by being a bit more
cautious about fanout. That could probably be improved a lot more and
needs more research. It's quite tricky to figure out how to suppress
wakeups without throwing potential concurrency away.

The first couple of patches are independent of this topic, and might
be potential cleanups/fixes for master/v18. The last is a simple
latency test.

Ideas, testing, flames etc welcome.

Attachment Content-Type Size
0001-aio-Regularize-io_method-worker-naming-conventions.patch text/x-patch 6.3 KB
0002-aio-Remove-IO-worker-ID-references-from-postmaster.c.patch text/x-patch 2.5 KB
0003-aio-Try-repeatedly-to-give-batched-IOs-to-workers.patch text/x-patch 1.8 KB
0004-aio-Adjust-IO-worker-pool-size-automatically.patch text/x-patch 33.5 KB
0005-XXX-read_buffer_loop.patch text/x-patch 3.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Srirama Kucherlapati 2025-04-12 17:09:41 RE: AIX support
Previous Message Srirama Kucherlapati 2025-04-12 16:41:55 RE: AIX support