惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cisco Blogs
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
Jina AI
Jina AI
Project Zero
Project Zero
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
Simon Willison's Weblog
Simon Willison's Weblog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tenable Blog
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
Last Week in AI
Last Week in AI
月光博客
月光博客
雷峰网
雷峰网
G
Google Developers Blog
V
V2EX
T
Tor Project blog
罗磊的独立博客
Schneier on Security
Schneier on Security
Know Your Adversary
Know Your Adversary
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Privacy International News Feed
S
Securelist
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
小众软件
小众软件
Scott Helme
Scott Helme
I
Intezer
T
Threat Research - Cisco Blogs
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
C
CERT Recently Published Vulnerability Notes
Security Archives - TechRepublic
Security Archives - TechRepublic
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
L
Lohrmann on Cybersecurity
T
Troy Hunt's Blog
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Latest news
Latest news
AWS News Blog
AWS News Blog
Apple Machine Learning Research
Apple Machine Learning Research

Tomas Vondra

Some more thoughts on random_page_cost How are committers selected? The real cost of random I/O The AI inversion Stabilizing Benchmarks Don't give Postgres too much memory (even on busy systems) Qubes OS is pretty great Wireguard to access a home network Don't give Postgres too much memory Tuning AIO in PostgreSQL 18 Using JWT to establish a trusted context for RLS Fun and weirdness with SSDs So why don't we pick the optimal query plan? How often is the query plan optimal? Benchmarking is hard, sometimes ... Advanced Patch Feedback Session (APFS) at pgconf.dev 2025 Good time to test io_method (for Postgres 18) [PATCH IDEA] adaptive execution for `IN` queries 15 years of Prague PostgreSQL Developer Day Performance archaeology: OLAP Performance archaeology: OLTP Tuning the glibc memory allocator (for Postgres) Playing with BOLT and Postgres [PATCH IDEA] amcheck support for BRIN indexes Writing a good talk proposal [PATCH IDEA] Statistics for the file descriptor cache Office hours experiment [PATCH IDEA] Using COPY for postgres_fdw INSERT batching Importing Postgres mailing list archives How to pick the first patch? Will Postgres development rely on mailing lists forever? The state of the Postgres community
[PATCH IDEA] parallel pgbench -i
2024-10-01 · via Tomas Vondra

There are multiple tools to run benchmarks on Postgres, but pgbench is probably the most widely used one. The workload is very simple and perhaps a bit synthetic, but almost everyone is familiar with it and it’s a very convenient way to do quick tests and assessments. It was improved in various ways (e.g. to do partitioning), but the initial data load is still serial - only a single process does the COPY. Which annoys me - it may take a lot of time before I can start with the benchmarks itself.

This week’s “first patch” idea is to extend pgbench -i to allow the data load to happen in parallel, with multiple clients generating and sending the data.

If you didn’t read the first post about how to pick the first patch, maybe do so now. Everything I wrote in that post still applies - you should pick a patch that’s interesting (and useful) for you personally. Don’t jump on this idea simply because I posted about it.

If you decide to give this patch idea a try, let me know. Maybe not right away, but once you get past the initial experiments. Otherwise multiple people might be working on it, having to throw the work away after the first one submits it to pgsql-hackers. It gives insights and ability to review the submitted patch, so not a total waste of time. But if your goal was to write the first patch …

Motivation

I think I mostly already explained the motivation - speedup pgbench -i so that the actual benchmark setup takes less time.

But on second thought, the setup can be considered a benchmark on its own. It’s useful to know how fast you can push large amounts of data into the database - analytical systems do that all the time. So why not have a convenient way to do that?

Implementation

This patch idea is a bit different from the earlier ones, because this is entirely on the client side. pgbench connects to the database over socket, but the code is much simpler. It’s a rather simple traditional C application. It does not use any of the infrastructure specific to the server - memory context, shared memory, and so on. For anyone with basic C knowledge, it’s much simpler to understand and modify.

pgbench already knows how to run multiple processes - if you specify -j N, it creates multiple “jobs” to generate the workload and manage client connections. This is done using pthread and the parallel load can use that too.

I imagine it would be possible to do pgbench -i -s 10000 -j 32 and this would load the data (in this case ~150GB) using 32 clients doing COPY of a subset of the data.

How exactly would the data be split between workers? There are different ways to do that, I’m not sure which one is the best. For example:

  • We know the range of IDs we need to generate, so we can simply split the range into N ranges, and every worker loads one of those. This breaks the locality/correlation of the single-process data.

  • We can have a coordinator that assigns the workers smaller ranges of IDs to generate data for. This maintains the locality much better.

  • If the setup uses partitioning, we could make each worker responsible for loading a subset of partitions. This would work nicely with range partitions.

There are probably a couple other ways to do this. Figuring out which strategy to use is likely one of the important tasks.

Risks

I think the main risk is that the speedup may be worse than expected, and the improvement won’t be considered worth the complexity. This can be mitigated by doing some quick tests first, to see how much faster a parallel load would be.

Conclusions

That’s it. As always - if you’re interested, feel free to reach out to me directly by email. Or you can talk to other Postgres developers in pgsql-hackers, or the new discord channel.

Do you have feedback on this post? Please reach out by e-mail to tomas@vondra.me.