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 1uP6pC-000WpW-Lm for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Jun 2025 21:48:06 +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 1uP6pA-00ANva-DB for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Jun 2025 21:48:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uP6pA-00ANvR-3T for pgsql-hackers@lists.postgresql.org; Tue, 10 Jun 2025 21:48:04 +0000 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uP6p9-001JpO-05 for pgsql-hackers@lists.postgresql.org; Tue, 10 Jun 2025 21:48:03 +0000 Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3dda399db09so52243535ab.3 for ; Tue, 10 Jun 2025 14:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592082; x=1750196882; 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=K5x2/EUB0yiyje/9zc94538yYLEh9mB5FnkAZPI50U8=; b=fSGAcER42ECZ8dmqbD6QbrjN5S3MrfPGE4fbslvn1b+eVw8mPpFcMfEIWWGXMueH8S elCu0ui72pPAfZgknBVv/XrkjJW33yAH+Kvt+oEmBx2ziOejAKx0BMm9SM9pRDEE1APK pwd9H/BRXDa1BLxz/8RSw9YOIrkLqVl7R4Z4bB9pldHyjHw2pv/9pLVS4xtIRB+9mMjE qIHbzg551LfosJSDAe/mSjrVI7aCxz5getST94mY5A9smtIQ/AYAVF6clBoLbaT0+tFE mzXeCYi7inVDcW73cwyzT2JBIwHwyPq6GrLKP63jFdGNWnffoHVDLwOQ2s9V5ovR1ZR7 nQ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592082; x=1750196882; 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=K5x2/EUB0yiyje/9zc94538yYLEh9mB5FnkAZPI50U8=; b=tVQZEyu5CLcI8WxQG0WXbj2HvlNCDWtPiJ6JgzBKmW41HC9p7xfUIQtlgg5huVlw/n i/ydcfJDXfblB6ZyeZabYdusvOxZ8liwaHpHpTQ8sZQoNhds+soDBmuCTzlArMHmFFiI pcrcplKfveOpLk6w1ZxBR22tOtdUoWRPJt4b6LmE7iqF8AzeU4AKg82mnIt+6ZTCrfJu CqjPk6ggsH6HRemIIHBLC2UJcTc5+J6b1VKvuD3w5oLuG5QuAyAPCyBGzRYimKZW5YHu NJ9zLKscu4RMu1beiN+0wBpD4bUjekavHxM4YEl2O7A11YdA58g1kvQSEeEOKalZuO9O 1oYA== X-Forwarded-Encrypted: i=1; AJvYcCU+ZP2xMtbNXe4PYr1WKuu+8nAEWyEbxqGg0GA7HiPqWNS2oIBsoGiMCAyVK5svYEbKhiZu6NS+F9zZzVSp@lists.postgresql.org X-Gm-Message-State: AOJu0YwHsH9UQxAiIlx4+mh0JWXWlSZWIL2IcXGE0OQno+gM3CIWXMMx akxdd1OU6x1XsybeF1TyQariZaed93jidpnDVh1VlEau6UPAUdgcGKuY X-Gm-Gg: ASbGncsO3aJ0Fq8VWeYnY6JlE4Vwin/UZ8J3lqp1Pa8GTNeTIlsONJD5eqAfybNsTCd ekS4lVmL7tV5Xfl2ji3/8hbMLixwyLNLCkVjZnzw69HFevrVm/3RvrNxhMPfpkFfQIHk83k+WEb ZBXZ4g48pjpqreYrlZR8C//AGz3eEWZfPn+AJqWDlXR+1DbY+/OMg1mzOywqtM8UrFHpsou60JD bDJDElxkVn3W0lhursbdJAg752C0hP6khellcklecB8ar6UNpRPRKefvy/SVKviSrFzSJ080wD9 CrZpnmeGNf4O81HYYhjO81n10M2DryJV+Fd46euvvnFoQuVoVidJaGSjUaUX8215abVaX86nxlX XrYsq2s/3pQtoHHvEE7mHtk4ON6SBkDr0M54/o6OEIf7JCRVJ9YEV60Sfs7l5Nng3SUJ9 X-Google-Smtp-Source: AGHT+IE8A3ddDoda9d6bol44UXLhGqfZhWG2vuOrrXe+q+mq3YY/RsACh5zsMQNh0WDf+aP3gz6gJA== X-Received: by 2002:a92:ca4e:0:b0:3dc:7a9a:44d5 with SMTP id e9e14a558f8ab-3ddf431592dmr9871265ab.22.1749592081183; Tue, 10 Jun 2025 14:48:01 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3ddf474f0dasm878585ab.36.2025.06.10.14.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:48:00 -0700 (PDT) Date: Tue, 10 Jun 2025 16:47:59 -0500 From: Nathan Bossart To: Dimitrios Apostolou Cc: Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: [PING] [PATCH v2] parallel pg_restore: avoid disk seeks when jumping short distance forward Message-ID: References: <2edb7a57-b225-3b23-a680-62ba90658fec@gmx.net> <1282067.1744651649@sss.pgh.pa.us> 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 Mon, Jun 09, 2025 at 10:09:57PM +0200, Dimitrios Apostolou wrote: > Fix by avoiding forward seeks for jumps of less than 1MB forward. > Do instead sequential reads. > > Performance gain can be significant, depending on the size of the dump > and the I/O subsystem. On my local NVMe drive, read speeds for that > phase of pg_restore increased from 150MB/s to 3GB/s. I was curious about what exactly was leading to the performance gains you are seeing. This page has an explanation: https://www.mjr19.org.uk/IT/fseek.html I also wrote a couple of test programs to show the difference between fseeko-ing and fread-ing through a file with various sizes. On a Linux machine, I see this: log2(n) | fseeko | fread ---------+---------+------- 1 | 109.288 | 5.528 2 | 54.881 | 2.848 3 | 27.65 | 1.504 4 | 13.953 | 0.834 5 | 7.1 | 0.49 6 | 3.665 | 0.322 7 | 1.944 | 0.244 8 | 1.085 | 0.201 9 | 0.658 | 0.185 10 | 0.443 | 0.175 11 | 0.253 | 0.171 12 | 0.102 | 0.162 13 | 0.075 | 0.13 14 | 0.061 | 0.114 15 | 0.054 | 0.1 So, fseeko() starts winning around 4096 bytes. On macOS, the differences aren't quite as dramatic, but 4096 bytes is the break-even point there, too. I imagine there's a buffer around that size somewhere... This doesn't fully explain the results you are seeing, but it does seem to validate the idea. I'm curious if you see further improvement with even lower thresholds (e.g., 8KB, 16KB, 32KB). -- nathan