Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uIuQ9-00DR0i-6X for pgsql-hackers@arkaria.postgresql.org; Sat, 24 May 2025 19:20:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uIuQ6-00DDnY-L4 for pgsql-hackers@arkaria.postgresql.org; Sat, 24 May 2025 19:20:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from <9erthalion6@gmail.com>) id 1uIuQ6-00DDnQ-9m for pgsql-hackers@lists.postgresql.org; Sat, 24 May 2025 19:20:33 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from <9erthalion6@gmail.com>) id 1uIuQ3-000n39-1f for pgsql-hackers@lists.postgresql.org; Sat, 24 May 2025 19:20:33 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-602346b1997so1417340a12.3 for ; Sat, 24 May 2025 12:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748114430; x=1748719230; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=AqtDW2Z05YEJALhQCsD8onRyh9KdiCK+hoydaN1VlEk=; b=C4pjgs7TmyD+FkPUr1UP39K2cLNLWX/qe88vWmKt5KTNUHs3MbBn+QlSzEFiXvneIe 7NNjNjI2mOuKXwXd0ExtksNqNxm4Ix98xwbfFPrJ4XbSdN3H/gMYmsYT24Bu8qfsZ48E lLJikucuc0xDycI6fyCay/1/a1vlk7H0T2osUTdLhiZnGyId3+/QYI6dHrTyIR1am7HW NJUx1k/FACaLYZASUXhf+5wQB9E7gKUIw84VsJZOGabsimTY5Sk7ZMJou0lEj6qoZ8bi elvLTnzexqtTVNXcyQUBw+F75cvG7lii1IubfvLT6y2clw5DbHA/XBYVLthshXhIpMwk 66Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748114430; x=1748719230; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AqtDW2Z05YEJALhQCsD8onRyh9KdiCK+hoydaN1VlEk=; b=A8G6RuZ29NtXBAt4kwPt8sNIdfn71jxM9EyBntbwAg8xFOsaW6QmvMUIZdlf27s8VU wvDAsbMhtQgNSH0oBx4fkDw8PqRxEnOHOkip5iGp1QDv3WXnE4J/hdRmXhYoKS3GK81y jixkP72N86ejX3nZy2+7+f5JOOLLD3ABRbnJJnackMjdHaj6ad5i8yW0+cfbnmibspBF liCeu4dCMzMVjO47vMw7MXxx+3246ZIuKEaeQ9roz6wt5oRLQk/aCTzET8kNX6H0AVbp krbQc68/8PDgSS+oqY+n239OeIyUqCt4vtQLFIQHuAhX7E5Irs1avL2s2gbdl2EpM6Pj RMMw== X-Gm-Message-State: AOJu0YwiaRVtbiBSzLTLiLVHFxPmzhHPam2aUMJ/v55WRb5OPGda8qjB BDLngPpfRd6iBdj3MnHsNh7oTKc3ncKDQ05SQ3l5SfgKigAnvEbFUMWc X-Gm-Gg: ASbGncsDKQsA0jdPEwyhH8MNtbMB+lT5r4TWPy4JtoY3yoM8hi04eO3PdB5oOk6D/uQ MKr/BdFPZD9D/gWPpp4w9qDzL8vYZ6qdLZBqQSqFpt+kx+ZSzyaGVzLVcYXxf0EGV/oLwIi9yQP 83lUBmVuPy9Ir9+k9htSJSZ3006BiQ5CZCbugco64kMRmPEpcOMOl6eLG9XyMaf4mAywNCyPhFO pkOcmcI0jRD0+smzsr0QxFh2vh1MItvJxE5A9ohW9//z0ozfW7bXB5JtgLsVP/l/7H55gnTK3ye wdWGG2y/5ugWToILNeSvSZsrDDk3+Ds3aUSNldmNYFM0hrUq8JaIDNYn4soFbkzWp4ca0EvNsTY 0V47qKPSsrLtbxlvMN3h1uXad9n47o3xHa1O1CWA6DdtJrWeiofElC0g5Y5wUVbjP X-Google-Smtp-Source: AGHT+IGj24jZqbaJ1m6yqvNfX9BjEEVEM1bpmBUGReP2zVO/RHxkvmfURjWNkROfRvlqq0Yg0Zka8g== X-Received: by 2002:aa7:c44c:0:b0:604:5a3a:2781 with SMTP id 4fb4d7f45d1cf-6045a3a2c61mr756758a12.12.1748114429672; Sat, 24 May 2025 12:20:29 -0700 (PDT) Received: from ddolgov-thinkpadt14sgen1.rmtde.csb (dslb-178-005-239-181.178.005.pools.vodafone-ip.de. [178.5.239.181]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6045d9ed757sm348816a12.59.2025.05.24.12.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 May 2025 12:20:29 -0700 (PDT) Date: Sat, 24 May 2025 21:20:27 +0200 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Thomas Munro Cc: PostgreSQL Hackers Subject: Re: Automatically sizing the IO worker pool Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Sun, Apr 13, 2025 at 04:59:54AM GMT, Thomas Munro wrote: > 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. I like the idea. In fact, I've been pondering about something like a "smart" configuration for quite some time, and convinced that a similar approach needs to be applied to many performance-related GUCs. Idle timeout and launch interval serving as a measure of sensitivity makes sense to me, growing the pool when a backlog (queue_depth > nworkers, so even a slightest backlog?) is detected seems to be somewhat arbitrary. From what I understand the pool growing velocity is constant and do not depend on the worker demand (i.e. queue_depth)? It may sounds fancy, but I've got an impression it should be possible to apply what's called a "low-pass filter" in the control theory (sort of a transfer function with an exponential decay) to smooth out the demand and adjust the worker pool based on that. As a side note, it might be far fetched, but there are instruments in queueing theory to figure out how much workers are needed to guarantee a certain low queueing probability, but for that one needs to have an average arrival rate (in our case, average number of IO operations dispatched to workers) and an average service rate (average number of IO operations performed by workers).