0

我刚刚遇到了一个奇怪的问题。我在 pgfourine 中做了一份报告,发现我的 XA 事务开始工作很慢。准备事务和准备提交结合起来花费了 13.2 秒中的 12.55 秒。但为什么?

#####  Overall statistics  #####

Number of unique normalized queries: 175
Number of queries:     268,772
Total query duration:  13m2s


#####  Queries by type  #####

SELECT:    116493     43.3%
INSERT:     15926      5.9%
UPDATE:      7935      3.0%
DELETE:      4923      1.8%


#####  Queries that took up the most time (N)  #####

1) 6m32s - 26,338 - COMMIT PREPARED ''
--
2) 6m23s - 25,972 - PREPARE TRANSACTION ''
--
3) 0.6s - 3,848 - update avatar set lfa_position=NULL where Id=0
.....
7) 0.3s - 21,514 - COMMIT
.....

我有一个理论,但没有证据。我有慢速光盘,我关闭了 synchronous_commit。即使 synchronous_commit 关闭,PostgreSQL 也可能必须在“准备事务”期间进行 fsync?

fsync = on 
synchronous_commit = off

有任何想法吗?

更新

相同的测试

fsync = off
synchronous_commit = off


#####  Overall statistics  #####

Number of unique normalized queries: 155
Number of queries:     186,838
Total query duration:  6.6s


#####  Queries by type  #####

SELECT:     84367     45.2%
INSERT:      9197      4.9%
UPDATE:      5486      2.9%
DELETE:      2996      1.6%


#####  Queries that took up the most time (N)  #####

1) 1.8s - 16,972 - PREPARE TRANSACTION ''
--
2) 1.1s - 16,965 - COMMIT PREPARED ''
--
3) 0.4s - 2,904 - update avatar set lfa_position=NULL where Id=0
--
4) 0.2s - 16,031 - COMMIT

看起来 fsync 花费了大量时间,但并非一直如此。16k 提交 - 0.2 秒,17k 准备 + 提交 2.9 秒。

悲剧。看起来 XA 提交比本地提交花费的时间多 15 倍,并且不考虑 synchronous_commit 设置。fsync=off 对于生产使用是不安全的。因此,如果我想使用 XA 事务,我必须小心使用它并使用具有高 IOPS 的优质 SSD 驱动器。

4

1 回答 1

1

立即同步的理论PREPARE TRANSACTION是正确的,并且在文档中提到:

摘自http://www.postgresql.org/docs/9.1/static/wal-async-commit.html

支持两阶段提交的命令,例如 PREPARE TRANSACTION,也始终是同步的。

于 2012-10-03T12:55:32.310 回答