奇妙な問題が発生しました。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ドライブを使用する必要があります。