PostgreSQL 10.0 preview 性能增强 - 2PC事务恢复阶段性能提升

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

标签

PostgreSQL , 10.0 , 2pc , recovery


背景

两阶段提交,在一些客户端异步事务,或者跨库的事务处理中非常常见。

目前,如果数据库crash,PostgreSQL恢复时,对2PC处理机制如下

* on prepare 2pc data (subxacts, commitrels, abortrels, invalmsgs) saved to xlog and to file, but file not is not fsynced  
* on commit backend reads data from file  
* if checkpoint occurs before commit, then files are fsynced during checkpoint  
* if case of crash replay will move data from xlog to files  

10.0将改进为

* on prepare backend writes data only to xlog and store pointer to the start of the xlog record  
* if commit occurs before checkpoint then backend reads data from xlog by this pointer  
* on checkpoint 2pc data copied to files and fsynced  
* if commit happens after checkpoint then backend reads files  
* in case of crash replay will move data from xlog to files (as it was before patch)  

详见

Hello.  

While working with cluster stuff (DTM, tsDTM) we noted that postgres 2pc transactions is approximately two times slower than an ordinary commit on workload with fast transactions — few single-row updates and COMMIT or PREPARE/COMMIT. Perf top showed that a lot of time is spent in kernel on fopen/fclose, so it worth a try to reduce file operations with 2pc tx.  

Now 2PC in postgres does following:  
* on prepare 2pc data (subxacts, commitrels, abortrels, invalmsgs) saved to xlog and to file, but file not is not fsynced  
* on commit backend reads data from file  
* if checkpoint occurs before commit, then files are fsynced during checkpoint  
* if case of crash replay will move data from xlog to files  

In this patch I’ve changed this procedures to following:  
* on prepare backend writes data only to xlog and store pointer to the start of the xlog record  
* if commit occurs before checkpoint then backend reads data from xlog by this pointer  
* on checkpoint 2pc data copied to files and fsynced  
* if commit happens after checkpoint then backend reads files  
* in case of crash replay will move data from xlog to files (as it was before patch)  

Most of that ideas was already mentioned in 2009 thread by Michael Paquier http://www.postgresql.org/message-id/c64c5f8b0908062031k3ff48428j824a9a46f28180ac@mail.gmail.com where he suggested to store 2pc data in shared memory.   
At that time patch was declined because no significant speedup were observed. Now I see performance improvements by my patch at about 60%. Probably old benchmark overall tps was lower and it was harder to hit filesystem fopen/fclose limits.  

Now results of benchmark are following (dual 6-core xeon server):  

Current master without 2PC: ~42 ktps  
Current master with 2PC: ~22 ktps  
Current master with 2PC: ~36 ktps  

Benchmark done with following script:  

\set naccounts 100000 * :scale  
\setrandom from_aid 1 :naccounts  
\setrandom to_aid 1 :naccounts  
\setrandom delta 1 100  
\set scale :scale+1  
BEGIN;  
UPDATE pgbench_accounts SET abalance = abalance - :delta WHERE aid = :from_aid;  
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :to_aid;  
PREPARE TRANSACTION ':client_id.:scale';  
COMMIT PREPARED ':client_id.:scale';  

这个patch的讨论,详见邮件组,本文末尾URL。

PostgreSQL社区的作风非常严谨,一个patch可能在邮件组中讨论几个月甚至几年,根据大家的意见反复的修正,patch合并到master已经非常成熟,所以PostgreSQL的稳定性也是远近闻名的。

参考

https://commitfest.postgresql.org/13/915/

https://www.postgresql.org/message-id/flat/74355FCF-AADC-4E51-850B-47AF59E0B215@postgrespro.ru#74355FCF-AADC-4E51-850B-47AF59E0B215@postgrespro.ru

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
4月前
|
存储 SQL 关系型数据库
PolarDB这个sql行存和列存性能差别好大 ,为什么?
PolarDB这个sql行存和列存性能差别好大 ,为什么?
33 0
|
4月前
|
存储 关系型数据库 数据库
postgresql|数据库|提升查询性能的物化视图解析
postgresql|数据库|提升查询性能的物化视图解析
155 0
|
6月前
|
监控 关系型数据库 数据库
《PostgreSQL性能大提升:实用优化技巧》
《PostgreSQL性能大提升:实用优化技巧》
333 0
|
3月前
|
关系型数据库 MySQL Serverless
阿里云云原生数据库 PolarDB MySQL Serverless:卓越的性能与无与伦比的弹性
阿里云原生数据库 PolarDB MySQL Serverless 拥有卓越性能和无与伦比的弹性。通过实验体验,深入了解其基本管理和配置、智能弹性伸缩特性和全局一致性特性。实验包括主节点和只读节点的弹性压测以及全局一致性测试,旨在亲身体验 PolarDB 的强大性能。通过实验,可以更好地在实际业务场景中应用 PolarDB,并根据需求进行性能优化和调整。
679 2
|
3月前
|
存储 关系型数据库 分布式数据库
阿里云PolarDB解决乐麦多源数据存储性能问题
乐麦通过使用PolarDB数据库,使整个系统之间的数据查询分析更加高效
390 3
|
3月前
|
关系型数据库 数据挖掘 分布式数据库
报名预约|体验PolarDB澎湃性能与高性价比在线直播
「飞天技术沙龙数据库技术周」直播聚焦PolarDB产品体验
|
4月前
|
SQL 存储 关系型数据库
PolarDB-X Operator 基于两次心跳事务的指定时间点恢复方案介绍
本文将介绍,PolarDB-X Operator将在事务策略为XA事务或者TSO事务时,如何实现全局一致的任意时间点恢复,提出了基于两次心跳事务的恢复方案。
|
4月前
|
存储 SQL 关系型数据库
PolarDB-x 比mysql查询性能怎么样?速度快吗
PolarDB-x 比mysql查询性能怎么样?速度快吗
156 0
|
4月前
|
存储 关系型数据库 MySQL
PolarDB的性能对比
PolarDB的性能对比
123 1
|
5月前
|
存储 人工智能 关系型数据库
5倍性能提升,阿里云AnalyticDB PostgreSQL版新一代实时智能引擎重磅发布
2023 云栖大会上,AnalyticDB for PostgreSQL新一代实时智能引擎重磅发布,全自研计算和行列混存引擎较比开源Greenplum有5倍以上性能提升。AnalyticDB for PostgreSQL与通义大模型家族深度集成,推出一站式AIGC解决方案。阿里云新发布的行业模型及“百炼”平台,采用AnalyticDB for PostgreSQL作为内置向量检索引擎,性能较开源增强了2~5倍。大会上来自厦门国际银行、三七互娱等知名企业代表和瑶池数据库团队产品及技术资深专家们结合真实场景实践,深入分享了最新的技术进展和解析。
5倍性能提升,阿里云AnalyticDB PostgreSQL版新一代实时智能引擎重磅发布

相关产品

  • 云原生数据库 PolarDB