@@ -1846,6 +1846,119 @@ postgres=# select * from tt;
18461846(7 rows)
18471847```
18481848
1849+ ## 17 同步模式 VS 异步模式 性能对比
1850+
1851+ 1、生成1亿TPC-B测试数据
1852+
1853+ ```
1854+ pgbench -i -s 1000
1855+ ```
1856+
1857+ 2、多副本同步模式
1858+
1859+ ```
1860+ postgres=# show synchronous_commit ;
1861+ synchronous_commit
1862+ --------------------
1863+ remote_write
1864+ (1 row)
1865+
1866+ postgres=# show synchronous_standby_names ;
1867+ synchronous_standby_names
1868+ ---------------------------
1869+ ANY 1 (*)
1870+ (1 row)
1871+ ```
1872+
1873+ 3、压测
1874+
1875+ ```
1876+ pgbench -M prepared -n -r -P 1 -c 56 -j 56 -T 120
1877+
1878+ transaction type: <builtin: TPC-B (sort of)>
1879+ scaling factor: 1000
1880+ query mode: prepared
1881+ number of clients: 56
1882+ number of threads: 56
1883+ duration: 120 s
1884+ number of transactions actually processed: 5381146
1885+ latency average = 1.248 ms
1886+ latency stddev = 4.118 ms
1887+ tps = 44840.272218 (including connections establishing)
1888+ tps = 44853.145859 (excluding connections establishing)
1889+ script statistics:
1890+ - statement latencies in milliseconds:
1891+ 0.002 \set aid random(1, 100000 * :scale)
1892+ 0.001 \set bid random(1, 1 * :scale)
1893+ 0.001 \set tid random(1, 10 * :scale)
1894+ 0.001 \set delta random(-5000, 5000)
1895+ 0.063 BEGIN;
1896+ 0.171 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
1897+ 0.096 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
1898+ 0.109 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
1899+ 0.118 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
1900+ 0.090 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
1901+ 0.597 END;
1902+ ```
1903+
1904+ 4、本地持久化,单副本模式
1905+
1906+ ```
1907+ postgres@-> psql
1908+ psql (10.3)
1909+ Type "help" for help.
1910+
1911+ postgres=# alter role postgres set synchronous_commit = local;
1912+ ALTER ROLE
1913+ postgres=# \q
1914+ postgres@-> psql
1915+ psql (10.3)
1916+ Type "help" for help.
1917+
1918+ postgres=# show synchronous_commit ;
1919+ synchronous_commit
1920+ --------------------
1921+ local
1922+ (1 row)
1923+ ```
1924+
1925+ 5、压测
1926+
1927+ ```
1928+ pgbench -M prepared -n -r -P 1 -c 56 -j 56 -T 120
1929+
1930+ transaction type: <builtin: TPC-B (sort of)>
1931+ scaling factor: 1000
1932+ query mode: prepared
1933+ number of clients: 56
1934+ number of threads: 56
1935+ duration: 120 s
1936+ number of transactions actually processed: 6684833
1937+ latency average = 1.005 ms
1938+ latency stddev = 1.494 ms
1939+ tps = 55695.800213 (including connections establishing)
1940+ tps = 55700.524316 (excluding connections establishing)
1941+ script statistics:
1942+ - statement latencies in milliseconds:
1943+ 0.002 \set aid random(1, 100000 * :scale)
1944+ 0.001 \set bid random(1, 1 * :scale)
1945+ 0.001 \set tid random(1, 10 * :scale)
1946+ 0.001 \set delta random(-5000, 5000)
1947+ 0.061 BEGIN;
1948+ 0.133 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
1949+ 0.096 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
1950+ 0.108 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
1951+ 0.114 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
1952+ 0.091 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
1953+ 0.400 END;
1954+ ```
1955+
1956+ OLTP写场景本地持久化 VS 多副本性能对比:
1957+
1958+ 1、多副本模式,RT 提高了0.24毫秒,约20%
1959+
1960+ 2、多副本模式,TPS 下降了10855,约20%
1961+
18491962## 小结
18501963
18511964PostgreSQL的多副本复制非常的简单并且健壮。
0 commit comments