Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m0Rpr-0002cr-KW for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jul 2021 16:52:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m0Rpq-0004zj-8n for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jul 2021 16:52:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m0Rpp-0004za-VG for pgsql-hackers@lists.postgresql.org; Mon, 05 Jul 2021 16:52:42 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m0Rpn-0005Eu-Kr for pgsql-hackers@postgresql.org; Mon, 05 Jul 2021 16:52:41 +0000 Received: by mail-io1-xd31.google.com with SMTP id d9so21615898ioo.2 for ; Mon, 05 Jul 2021 09:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RblrwOIEm32JxA4a8jXMaMkNMztjT5ODpba3PlQk2Q4=; b=OyN5MWI8O/9Q7xhP8UzknzBoq2us3YkVu+krfLEUOvLuQ6bEXBvbVSFhYr5u8uNZz0 qdiNl+iG9RP389DYTB6LIWACpeEwze4MGPLkk1PpGgA69G0ok+00FyU90TUgOomRpPPr 3aacp+/whr4sF1ZsUaZItV/LSoMrm8nf60vR4pE6PEcN2GjzbBrIf9EFpCQYtV1rQloS ovkleeE80bnMBrwtGUDK02+sKRy0xVY5/W9YalWWNPumA528Jm1wJZ0iensvj/aLqdv1 2thaUYIe0nQhfcvMmqGjNAV1wpeKLtAtjw8ADKmOBoUC+ZRzSQiCtDVabUE86wQR+XEL pgZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RblrwOIEm32JxA4a8jXMaMkNMztjT5ODpba3PlQk2Q4=; b=sbROcsmLlvtNXyYpF4MWeLrva3JX4iED+1lPRTnv7LHtgIof2gKhQgQFG0i772l6yA KHG8ZudiJs12e/vDiZKeeCwbe8AxiWrCgOWKoxvik+atweVf0ecxQQOQ40spshDvw+Ym JZ84fUUgPg0Z4B00YCDZpMEnC5LK2dsGulBCXhRO8b8tRZk/MfwWEloHHePP8ds9HS6a osxCNbgFDVl+Uk8VS05JmR5KknGMRmKi8AlDbMySUrA8w7CV5pcUI2AjRSUvfG4nQWVH j3cgZMRaziZfTVoCM1Rhl3+noOE7+W1LwJFDOBI8eQCz4yGl/2u/aOS0Md9aR53kWyiT Ft7A== X-Gm-Message-State: AOAM532b4zVaTho6keulRDIIATYiz4qxK2mq1jsrRz2T54LIM3zaCMRo zGPgvImOFjVpoSDvw/W4mbs8Q/x+tcJ3M8VR9Xo= X-Google-Smtp-Source: ABdhPJzZQx92OkfAd3b30VZMsR2+9PhfAw2lJDS/eDx8xDSeQTpRAUTZwgpbh+2AohtNXiiS1Jh/YNieb73Fza0JaRk= X-Received: by 2002:a05:6638:155:: with SMTP id y21mr2413507jao.42.1625503957862; Mon, 05 Jul 2021 09:52:37 -0700 (PDT) MIME-Version: 1.0 References: <20201225200953.jjkrytlrzojbndh5@alap3.anarazel.de> <265B06BA-7B16-4C1A-BE1A-1451D22A1F83@amazon.com> In-Reply-To: <265B06BA-7B16-4C1A-BE1A-1451D22A1F83@amazon.com> From: vignesh C Date: Mon, 5 Jul 2021 22:22:27 +0530 Message-ID: Subject: Re: Pre-allocating WAL files To: "Bossart, Nathan" Cc: Andres Freund , "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jun 7, 2021 at 8:48 PM Bossart, Nathan wrote: > > On 12/25/20, 12:09 PM, "Andres Freund" wrote: > > When running write heavy transactional workloads I've many times > > observed that one needs to run the benchmarks for quite a while till > > they get to their steady state performance. The most significant reason > > for that is that initially WAL files will not get recycled, but need to > > be freshly initialized. That's 16MB of writes that need to synchronously > > finish before a small write transaction can even start to be written > > out... > > > > I think there's two useful things we could do: > > > > 1) Add pg_wal_preallocate(uint64 bytes) that ensures (bytes + > > segment_size - 1) / segment_size WAL segments exist from the current > > point in the WAL. Perhaps with the number of bytes defaulting to > > min_wal_size if not explicitly specified? > > > > 2) Have checkpointer (we want walwriter to run with low latency to flush > > out async commits etc) occasionally check if WAL files need to be > > pre-allocated. > > > > Checkpointer already tracks the amount of WAL that's expected to be > > generated till the end of the checkpoint, so it seems like it's a > > pretty good candidate to do so. > > > > To keep checkpointer pre-allocating when idle we could signal it > > whenever a record has crossed a segment boundary. > > > > > > With a plain pgbench run I see a 2.5x reduction in throughput in the > > periods where we initialize WAL files. > > I've been exploring this independently a bit and noticed this message. > Attached is a proof-of-concept patch for a separate "WAL allocator" > process that maintains a pool of WAL-segment-sized files that can be > claimed whenever a new segment file is needed. An early version of > this patch attempted to spread the I/O like non-immediate checkpoints > do, but I couldn't point to any real benefit from doing so, and it > complicated things quite a bit. > > I like the idea of trying to bake this into an existing process such > as the checkpointer. I'll admit that creating a new process just for > WAL pre-allocation feels a bit heavy-handed, but it was a nice way to > keep this stuff modularized. I can look into moving this > functionality into the checkpointer process if this is something that > folks are interested in. Thanks for posting the patch, the patch no more applies on Head: Applying: wal segment pre-allocation error: patch failed: src/backend/access/transam/xlog.c:3283 error: src/backend/access/transam/xlog.c: patch does not apply Can you rebase the patch and post, it might help if someone is picking it up for review. Regards, Vignesh