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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
小众软件
小众软件
美团技术团队
Martin Fowler
Martin Fowler
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
J
Java Code Geeks
B
Blog
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
博客园 - Franky

Tomas Vondra

Postgres development activity 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
[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.