frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Using Postgres pg_test_fsync tool for testing low latency writes

https://tanelpoder.com/posts/using-pg-test-fsync-for-testing-low-latency-writes/
38•mfiguiere•1d ago

Comments

singron•1d ago
Note that this workload is a worst case for iops and you will get higher iops in nearly any optimized workload. E.g. postgres needs to sync the WAL in order to commit (which does look like this test), but there are a ton of other writes that happen in parallel on the heap and index pages in addition to any reading you do. IME the consumer drives that benchmark at 500K iops and get only 500 iops on this test might get 10K or 20K iops on a more typical mixed workload.
tanelpoder•1d ago
Throughput with enough I/O concurrency, yes. That's actually why I wrote this blog entry, just to bring attention to this - having nice IOPS numbers do not translate to nice individual I/O latency numbers. If an individual WAL write takes ~1.5 ms (instead of tens of microseconds), this means that your app transactions also take 1.5+ ms and not sub-millisecond. Not everyone cares about this (and often don't even need to care about this), but worth being aware of.

I tend to set up a small, but completely separate block device (usually on enterprise SAN storage or cloud block store) just for WAL/redo logs to have a different device with its own queue for that. So that when that big database checkpoint or fsync happens against datafiles, the thousands of concurrently submitted IO requests won't get in the way of WAL writes that still need to complete fast. I've done something similar in the past with separate filesystem journal devices too (for niche use cases...)

Edit: Another use case for this is that ZFS users can put the ZIL on low-latency devices, while keeping the main storage on lower cost devices.

natmaka•1d ago
> I tend to set up a small, but completely separate block device (usually on enterprise SAN storage or cloud block store) just for WAL/redo logs

I'm not sure about this, as this separate device may handle more of the total (aggregated) work by being a member of an unique pool (RAID made of all available non-spare devices) used by the PostgreSQL server.

It seems to me that in most cases the most efficient setup, even when trying hard to reduce the maximal latency (and therefore to sacrifice some throughput), is an unique pool AND an adequate I/O scheduling enforcing a "max latency" parameter.

If, during peaks of activity, your WAL-dedicated device isn't permanently at 100% usage while the data pool is, then dedicating it may (overall) bump up the max latency and reduce throughput.

Tweaking some parameters (bgwriter, full_page_writes, wal_compression, wal_writer_delay, max_wal_senders, wal_level, wal_buffers, wal_init_zero...) with respect to the usage profile (max tolerated latency, OLTP, OLAP, proportion of SELECTs and INSERTs/UPDATEs, I/O subsystem characteristics and performance, kernel parameters...) is key.

tanelpoder•1d ago
When doing 1M+ IOPS, you probably do not want to use OS IO schedulers due to the OS (timer & spinlock) overhead [1] and let the hardware take care of any scheduling in their device queues. But you're right about flattening the IO burst spikes via DB configuration, so that you'd have constant slow checkpointing going on, instead of a huge spike every 15 minutes...

All this depends on what kind of storage backend you're on, local consumer SSDs with just one NVMe namespace each, or local SSDs with multiple namespaces (with their own queues) or a full-blown enterprise storage backend where you have no idea what's really going in the backend :-)

[1]: https://tanelpoder.com/posts/11m-iops-with-10-ssds-on-amd-th...

Edit: Note that I wasn't proposing using an entire physical disk device (or multiple) for the low latency files, but just a part of it. Local enterprise-grade SSDs support multiple namespaces (with their own internal queues) so you can carve out just 1% of that for separate I/O processing. And with enterprise SAN arrays (or cloud elastic block store offerings) this works too, you don't know how many physical disks are involved in the backend anyway, but at your host OS level, you get a separate IO queue that is not gonna be full of thousands of checkpoint writes.

fendale•1d ago
> local enterprise-grade SSDs support multiple namespaces (with their own internal queues)

What do you mean by namespaces here? Are they created by having different partitions or LVM volumes? As you mentioned consumer grade SSDs only have a single namespace, I am guessing this is something that needs some config when mounting the drive?

tanelpoder•23h ago
With SSDs that support namespaces you can use commands like "nvme create-ns" to create logical "partitioning" of the underlying device, so you'll end up with device names like this (also in my blog above):

/dev/nvme0n1 /dev/nvme0n2 /dev/nvme0n3 ...

Consumer disks support only a single namespace, as far as I've seen. Different namespaces give you extra flexibility, I think some even support different sector sizes for different namespaces).

So under the hood you'd still be using the same NAND storage, but the controller can now process incoming I/Os with awareness of which "logical device" they came from. So, even if your data volume has managed to submit a burst of 1000 in-flight I/O requests via its namespace, the controller can still pick some latest I/Os from other (redo volume) namespaces to be served as well (without having to serve the other burst of I/Os first).

So, you can create a high-priority queue by using multiple namespaces on the same device. It's like logical partitioning of the SSD device I/O handling capability, not physical partitioning of disk space like the OS "fdisk" level partitioning would be. The OS "fdisk" partitioning or LVM mapping is not related to NVMe namespaces at all.

Also, I'm not a NVMe SSD expert, but this is my understanding and my test results agree so far.

fendale•23h ago
Ah ok - so googling a bit on this, you do specify the size when creating the namespace. So if you have multiple namespaces, they appear as separate devices on the OS, and then you can mkfs and mount each as if its a different disk. Then you get the different IO queues at the hardware level, unlike with traditional partitioning.
tanelpoder•22h ago
Yep, exactly - with OS level partitioning or logical volumes, you'd still end up with a single underlying block device (and a single queue) at the end of the day.
CodesInChaos•1d ago
Could you run this on network block storage like EBS? I assume those have pretty high latency as well, even with high IOPS volumes?
tanelpoder•1d ago
I'll see if I have a chance to run such a test on AWS in coming days (and would need to keep running it for much longer than just 5 seconds shown in the blog).

If you care about WAL write/commit latency, you could provision a small-ish EBS io2 Block Express device (with provisioned IOPS) just for your WAL files and the rest of your data can still reside on cheaper EBS storage. And you might not even need to hugely overprovision your WAL device IOPS (as databases can batch commit writes for multiple transactions).

But the main point is that once your WAL files are on a completely separate blockdevice from all the other datafile I/O, they won't suffer from various read & write IO bursts that can happen during regular database activity. On Oracle databases, I put controlfiles to these separate devices too, as they are on the critical path during redo log switches...

CodesInChaos•1d ago
How do you backup those split volumes? I like EBS volume snapshots, since they're atomic, incremental, fast to restore and make it easy to spin up a clone. But obviously that approach won't work for split volumes.
tanelpoder•1d ago
Yep indeed, that's a tradeoff, if your DB fits into a single volume. I'm not that deeply familiar with databases other than Oracle (that has its own ways to work work around this), so for ease of use, everything on a single volume keeps things simpler.

One thing that I try to achieve anyway, is to spread & "smoothen" the database checkpoint & fsync activity over time via database checkpointing parameters, so you won't have huge "IO storms" every 15 minutes, but just steady writing of dirty buffers going on all the time. So, even if all your files are stored on the same blockdevice, you'll less likely see a case where your WAL writes wait behind 50000 checkpoint write requests issued just before.

CoolCold•22h ago
well, likely you can just use those as ZFS with ZIL or in more tradional setup with LVM + LVW writeback cache - which from my experience greatly improves latency
dboreham•20h ago
Aha! Useful article because I somehow never knew about pg_test_fsync until now. I wrote and maintained a similar tool long ago before open source times, when I worked on database storage engines. Several times since I've wished I still had that tool. Now I do. Excellent.
anarazel•17h ago
The numbers in the post highlight an issue I have with Samsung consumer SSDs - they've slowed down FUA writes to an absurd degree.

        open_datasync                       249.578 ops/sec    4007 usecs/op
        fdatasync                           608.573 ops/sec    1643 usecs/op
open_datasync (i.e. O_DSYNC) ends up as FUA writes, fdatasync() as a plain write followed by a cache flush.

On just about anything else a single FUA write is either the same speed as a write + fdatasync, or considerably faster.

This is pretty annoying, as using O_DSYNC is a lot more suitable for concurrent WAL writes, but because Samsung SSDs are widespread, changing the default would regress performance substantially for a good number of users.

Melting glacier destroys village in Swiss Alps

https://twitter.com/MeteoFrComtoise/status/1927736681852961118
1•dsnr•1m ago•0 comments

Show HN: I made a site where you can sell your techie side projects

https://www.microns.io
1•sweatC•2m ago•0 comments

Carefully Reading Programming Bitcoin

https://blog.yellowflash.in/posts/2025-05-29-programming-bitcoin-handwaved.html
1•yellowflash•2m ago•0 comments

Switzerland's 370,000 Nuclear Bunkers

1•samizdis•3m ago•0 comments

RAAF recruit had chilli in eyes and was set afire and choked in hazing ritual

https://www.dailytelegraph.com.au/nocookies
1•KnuthIsGod•5m ago•0 comments

Collaborative Agentic AI Needs Interoperability Across Ecosystems

https://arxiv.org/abs/2505.21550
1•devos50•6m ago•0 comments

A Rebuttal to "Against Life Extension"

https://domofutu.substack.com/p/a-rebuttal-to-against-life-extension
1•domofutu•6m ago•0 comments

Simple webpage to Markdown Chrome Extension

https://chromewebstore.google.com/detail/webpage-to-markdown/fgpepdeaaldghnmehdmckfibbhcjoljj
1•vinyasvi•7m ago•0 comments

A Song of “Full Self-Driving”: Elon Isn’t Tony Stark. He’s Michael Scott.

https://www.thebulwark.com/p/elon-musk-self-driving-fsd-tesla-tony-stark-michael-scott
1•latexr•8m ago•0 comments

Remote MCP Servers

https://www.stephendiehl.com/posts/remote_mcp_servers/
1•rwosync•9m ago•0 comments

Cory Doctorow on how we lost the internet

https://lwn.net/SubscriberLink/1021871/ffeed46818908c91/
1•udev4096•9m ago•0 comments

Show HN: Practical Ways to Strip EXIF Metadata and Protect Your Photo Privacy

https://slimimg.tools/blog/2025-05-26-remove-exif-metadata-privacy-guide
2•aaiiggcc000•10m ago•1 comments

Paper Houses

https://medium.com/luminasticity/paper-houses-442ea84be598
1•bryanrasmussen•12m ago•0 comments

Putting Rigid Bodies to Rest [pdf]

https://www.cs.cmu.edu/~kmcrane/Projects/RestingBodies/PuttingRigidBodiesToRest.pdf
1•murkle•14m ago•1 comments

GreyNoise Discovers Stealthy Backdoor Campaign Affecting Thousands Asus Routers

https://www.greynoise.io/blog/stealthy-backdoor-campaign-affecting-asus-routers
2•pieterr•14m ago•0 comments

Would you build on this domain stack?

1•star_boyzz•16m ago•0 comments

Ways JavaScript Frameworks Render the DOM [video]

https://www.youtube.com/watch?v=0C-y59betmY
1•todsacerdoti•20m ago•0 comments

My Glamorous Life: broken by design

https://zeldman.com/2025/05/15/my-glamorous-life-broken-by-design/
1•Michelangelo11•21m ago•0 comments

Elisabeth's Nietzsche

https://redsails.org/elisabeths-nietzsche/
1•amadeuspagel•24m ago•0 comments

Show HN: Narratrail – AWS CloudTrail to Slack Bot. Seeking Feedback

1•rikhul•24m ago•0 comments

Anthropic: The "Spiritual Bliss" Attractor State [pdf]

https://www-cdn.anthropic.com/4263b940cabb546aa0e3283f35b686f4f3b2ff47.pdf
1•danielmorozoff•27m ago•1 comments

The State of AI in Enterprise 2025

https://cloud.app.box.com/s/lai54mzu8a7nip4k1dlboiakfu4p94k1
1•hunglee2•29m ago•0 comments

An Alchemist's Notes on Deep Learning

https://notes.kvfrans.com/
1•sebg•29m ago•0 comments

Pure vs. Impure Iterators in Go

https://jub0bs.com/posts/2025-05-29-pure-vs-impure-iterators-in-go/
1•ingve•37m ago•0 comments

Building Tools for Traders (Jane Street)

https://signalsandthreads.com/building-tools-for-traders/
1•lewiscarson•41m ago•0 comments

Nvidia is in constant 'cat-and-mouse game' with US regulators

https://finance.yahoo.com/video/nvidia-constant-cat-mouse-game-215000219.html
2•rbanffy•43m ago•1 comments

If India chokes less, it will fry more

https://www.economist.com/interactive/asia/2025/05/28/if-india-chokes-less-it-will-fry-more
2•e-brake•45m ago•1 comments

Living Canvas: A web-based puzzle game powered by Generative AI

https://github.com/FirebaseExtended/solution-living-canvas
1•hmdai•48m ago•0 comments

Moneybench: Benchmark to measure the ability of AI agents to make money

https://moneybench.github.io/moneybench/#home
1•sebg•48m ago•0 comments

CAN Network Simulation with Apache NuttX

https://www.railab.me/posts/2025/5/host-based-dev-with-nuttx-can-network/
1•raiden00•58m ago•0 comments