výkonnostní archeologie
DESCRIPTION
Přehled výkonu PostgreSQL od verze 7.4 do 9.4TRANSCRIPT
![Page 1: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/1.jpg)
Výkonnostní archeologie
Tomáš Vondra, [email protected] / [email protected]
@fuzzycz, http://blog.pgaddict.com
Photo by Jason Quinlan, Creative Commons CC-BY-NC-SAhttps://www.flickr.com/photos/catalhoyuk/9400568431
![Page 2: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/2.jpg)
![Page 3: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/3.jpg)
Jak se změnil výkon PostgreSQL za
několik posledních verzí?
7.4 vyšla 2003, tj. cca 10 let
![Page 4: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/4.jpg)
(překvapivě) ošidná otázka
● během vývoje se většinou dělají “parciální” testy– srovnání dvou verzí / commitů
– zaměřené na konkrétní část kódu / vlastnost
● komplexnější benchmarky pro srovnání dvou verzí– obtížné “zkombinovat” (různý hardware, ...)
● aplikační výkon (ultimátní benchmark)– podléhá (pravidelným) upgradům hardwaru
– růst datových objemů, evoluce aplikace (nové fičury)
![Page 5: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/5.jpg)
(poněkud) nefér otázka
● vývoj probíhá oproti aktuálně dostupnému hardwaru– Kolik RAM jste měli v serveru před 10 lety?
– Kdo z vás měl před 10 lety SSD/NVRAM disky?
– Kdo z nás měl stroje s 8 CPU?
● některé rozdíly jsou důsledkem těchto změn (algoritmy)
Každopádně vyšší výkon na aktuálním
hardwaru je fajn ;-)
![Page 6: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/6.jpg)
Pojďme si zabenchmarkovat!
![Page 7: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/7.jpg)
Pokud se bojíte čísel nebo grafů, asi byste
radši měli odejít hned.
Bude tu spousta obojího ...
![Page 8: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/8.jpg)
http://blog.pgaddict.com
http://planet.postgresql.org
![Page 9: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/9.jpg)
82,71% statistik na internetu je
vycucaných z prstu ...
![Page 10: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/10.jpg)
... přísahám že ty moje to nejsou!
![Page 11: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/11.jpg)
Benchmarky (přehled)
● pgbench (TPC-B)– “transakční” benchmark
– operace pracují s malými počty řádek (přístup přes primární klíče)
● TPC-DS (náhrada TPC-H)– “warehouse” benchmark
– dotazy drtící spousty dat (aggregace, joiny, ROLLUP/CUBE, ...)
● fulltext benchmark (tsearch2)– primárně o vylepšeních GIN/GiST indexů
– platí pro další aplikace používající GIN/GiST (geo, ...)
![Page 12: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/12.jpg)
Použitý hardware
HP DL380 G5 (2007-2009)● 2x Xeon E5450 (each 4 cores @ 3GHz, 12MB cache)● 16GB RAM (FB-DIMM DDR2 667 MHz), FSB 1333 MHz● 6x10k RAID10 (SAS) @ P400 with 512MB write cache● S3700 100GB (SSD)
Workstation i5 (2011-2013)● 1x i5-2500k (4 cores @ 3.3 GHz, turbo 3.9 GHz, 6MB cache)● 8GB RAM (DIMM DDR3 1333 MHz)● S3700 100GB (SSD)
![Page 13: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/13.jpg)
pgbench
TPC-B “transakční” benchmark
![Page 14: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/14.jpg)
pgbench
● tři velikosti datasetů– malý (150 MB)– střední (~50% RAM)– velký (~200% RAM)
● dva módy– read-only a read-write
● rozsah klientů (1, 2, 4, ..., 32)
![Page 15: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/15.jpg)
pgbench
● tři velikosti datasetů– malý (150 MB) <– problémy se zámky, etc.– střední (~50% RAM) <– CPU bound– velký (~200% RAM) <– I/O bound
● dva módy– read-only a read-write
● rozsah klientů (1, 2, 4, ..., 32)
![Page 16: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/16.jpg)
BEGIN;
UPDATE accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM accounts WHERE aid = :aid;
UPDATE tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;
![Page 17: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/17.jpg)
0 5 10 15 20 25 30 350
2000
4000
6000
8000
10000
12000
pgbench / large read-only (on SSD)
HP DL380 G5 (2x Xeon E5450, 16 GB DDR2 RAM), Intel S3700 100GB SSD
7.4 8.0 8.1 head
number of clients
tran
sact
ion
s p
er s
econ
d
![Page 18: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/18.jpg)
0 5 10 15 20 25 30 350
10000
20000
30000
40000
50000
60000
70000
80000
pgbench / medium read-only (SSD)
HP DL380 G5 (2x Xeon E5450, 16 GB DDR2 RAM), Intel S3700 100GB SSD
8.0 8.1 8.2 8.3 9.0 9.2
number of clients
tra
nsa
ctio
ns
pe
r se
con
d
![Page 19: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/19.jpg)
0 5 10 15 20 25 30 350
500
1000
1500
2000
2500
3000
pgbench / large read-write (SSD)
HP DL380 G5 (2x Xeon E5450, 16 GB DDR2 RAM), Intel S3700 100GB SSD
7.4 8.1 8.3 9.1 9.2
number of clients
tra
nsa
ctio
ns
pe
r se
con
d
![Page 20: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/20.jpg)
0 5 10 15 20 25 30 350
1000
2000
3000
4000
5000
6000
pgbench / small read-write (SSD)
HP DL380 G5 (2x Xeon E5450, 16 GB DDR2 RAM), Intel S3700 100GB SSD
7.4 8.0 8.1 8.2 8.3 8.4 9.0 9.2
number of clients
tra
nsa
ctio
ns
pe
r se
con
d
![Page 21: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/21.jpg)
Co rotační disky?
6 x 10k SAS drives (RAID 10)
P400 with 512MB write cache
![Page 22: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/22.jpg)
0 5 10 15 20 25 300
100
200
300
400
500
600
700
800
pgbench / large read-write (SAS)
HP DL380 G5 (2x Xeon E5450, 16 GB DDR2 RAM), 6x 10k SAS RAID10
7.4 (sas) 8.4 (sas) 9.4 (sas)
number of clients
tra
nsa
ctio
n p
er
seco
nd
![Page 23: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/23.jpg)
No a co ta i5-2500k mašina?
![Page 24: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/24.jpg)
0 5 10 15 20 25 30 350
5000
10000
15000
20000
25000
30000
35000
40000
pgbench / large read-only (Xeon vs. i5)
2x Xeon E5450 (3GHz), 16 GB DDR2 RAM, Intel S3700 100GB SSDi5-2500k (3.3 GHz), 8GB DDR3 RAM, Intel S3700 100GB SSD
7.4 (Xeon) 9.0 (Xeon) 7.4 (i5) 9.0 (i5)
number of clients
tra
nsa
ctio
ns
pe
r se
con
d
![Page 25: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/25.jpg)
0 5 10 15 20 25 30 350
20000
40000
60000
80000
100000
pgbench / small read-only (Xeon vs. i5)
2x Xeon E5450 (3GHz), 16 GB DDR2 RAM, Intel S3700 100GB SSDi5-2500k (3.3 GHz), 8GB DDR3 RAM, Intel S3700 100GB SSD
7.4 (Xeon) 9.0 (Xeon) 9.4 (Xeon)7.4 (i5) 9.0 (i5) 9.4 (i5)
number of clients
tra
nsa
ctio
ns
pe
r se
con
d
![Page 26: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/26.jpg)
0 5 10 15 20 25 30 350
1000
2000
3000
4000
5000
6000
7000
8000
pgbench / small read-write (Xeon vs. i5)
2x Xeon E5450 (3GHz), 16 GB DDR2 RAM, Intel S3700 100GB SSDi5-2500k (3.3 GHz), 8GB DDR3 RAM, Intel S3700 100GB SSD
7.4 (Xeon) 9.4 (Xeon) 7.4 (i5) 9.4b1 (i5)
number of clients
tra
nsa
ctio
ns
pe
r se
con
d
![Page 27: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/27.jpg)
Legendy říkají že starší verze lépe
fungují s nižšími paměťovými limity
(shared_buffers etc.)
![Page 28: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/28.jpg)
0 5 10 15 20 25 30 350
5000
10000
15000
20000
25000
30000
35000
40000
pgbench / large read-only (i5-2500)
different sizes of shared_buffers (128MB vs. 2GB)
7.4 7.4 (small) 8.0 8.0 (small) 9.4b1
number of clients
tra
nsa
ctio
ns
pe
r se
con
d
![Page 29: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/29.jpg)
transactions per second vs. latence
![Page 30: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/30.jpg)
0
1000
2000
3000
4000
5000
6000
pgbench transaction rate / 7.4 vs. 9.4
transactions per second / large read-write dataset (32 clients)
7.4 9.4
test timeline (30 minutes)
tra
nsa
ctio
ns
pe
r se
con
d
![Page 31: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/31.jpg)
1
10
100
1000
pgbench transaction latency / 7.4 vs. 9.4
average latency (miliseconds) / large read-write
7.4 9.4
test duration
mili
seco
nd
s
![Page 32: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/32.jpg)
pgbench / shrnutí
● značná vylepšení● vylepšené zamykání
– lepší škálování na velké počty jader (64 ...)
● mnoho dalších optimalizací– výrazné zrychlení i na malém počtu klientů
● lessons learned– frekvence procesoru není míra výkonu
– počet jader není míra výkonu
![Page 33: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/33.jpg)
TPC-DS
“Decision Support” benchmark
(aka “Data Warehouse” benchmark)
![Page 34: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/34.jpg)
TPC-DS
● orientováno na analytiku / warehousing– dotazy drtící velké objemy dat (GROUP BY, JOIN)
– neuniformní rozdělení dat (realističtější než TPC-H)
● definováno 99 šablon dotazů (TPC-H jen 22)– některé rozbité (padá generátor)
– některé zatím nepodporované (ROLLUP/CUBE)
– 41 dotazů pro >= 7.4
– 61 dotazů pro >= 8.4 (CTE, Window functions)
![Page 35: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/35.jpg)
TPC-DS
● 1GB and 16GB datasets (raw data)– 1GB nedostatečný pro publikaci, 16GB je nestandardní (dle TPC)
● ale i tak je to zajímavé ...– většina produkčních databází se vejde do 16GB
– ukazuje to trendy (do jisté míry aplikovatelné na větší DB)
● schéma– víceméně defaultní (standard compliance FTW!)
– stejné pro všechny verze (indexy na FK/join keys, pár dalších)
– nepochybně možno dál zoptimalizovat
![Page 36: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/36.jpg)
8.0 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.4 head0
1000
2000
3000
4000
5000
6000
7000
TPC DS / database size per 1GB raw data
data indexes
size
[M
B]
![Page 37: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/37.jpg)
8.0 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.4 head0
200
400
600
800
1000
1200
1400
TPC DS / load duration (1GB)
copy indexes vacuum full vacuum freeze analyze
du
ratio
n [
s]
![Page 38: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/38.jpg)
8.0 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.4 head0
200
400
600
800
1000
1200
TPC DS / load duration (1GB)
copy indexes vacuum freeze analyze
du
ratio
n [
s]
![Page 39: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/39.jpg)
8.0 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.40
1000
2000
3000
4000
5000
6000
7000
8000
9000
TPC DS / load duration (16 GB)
LOAD INDEXES VACUUM FREEZE ANALYZE
du
ratio
n [
seco
nd
s]
![Page 40: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/40.jpg)
8.0 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.4 head
0
50
100
150
200
250
300
350
TPC DS / duration (1GB)
average duration of 41 queries
seco
nd
s
![Page 41: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/41.jpg)
8.0* 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.40
1000
2000
3000
4000
5000
6000
TPC DS / duration (16 GB)
average duration of 41 queries
version
du
ratio
n [
seco
nd
s]
![Page 42: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/42.jpg)
TPC-DS / shrnutí
● výrazně rychlejší load dat– většina času se vytváří indexy (paralelizace, RAM)
– pokud ignorujeme VACUUM FULL (změna implementace v 9.0)
– mírné snížení velikosti
● výrazně rychlejší dotazy– značné zrychlení dotazů (~6x)
– širší použití indexů, index only scany
![Page 43: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/43.jpg)
Fulltext Benchmark
testování GIN a GiST indexůprostřednictvím fulltextu
![Page 44: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/44.jpg)
Fulltext benchmark
● prohledávání archivů pgsql mailing listů– ~1M zpráv, ~5GB dat
● ~33k reálných dotazů (z postgresql.org)– syntetické dotazy dávají cca stejné výsledky
SELECT id FROM messages
WHERE body @@ ('high & performance')::tsquery
ORDER BY ts_rank(body, ('high & performance')::tsquery)
DESC LIMIT 100;
![Page 45: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/45.jpg)
0200400600800
100012001400160018002000
Fulltext benchmark / load
COPY / with indexes and PL/pgSQL triggers
COPY VACUUM FREEZE ANALYZE
du
ratio
n [
sec]
![Page 46: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/46.jpg)
8.0 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.4
0
1000
2000
3000
4000
5000
6000
Fulltext benchmark / GiST
33k queries from postgresql.org [TOP 100]
tota
l ru
ntim
e [
sec]
![Page 47: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/47.jpg)
8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.4
0
100
200
300
400
500
600
700
800
Fulltext benchmark / GIN
33k queries from postgresql.org [TOP 100]
tota
l ru
ntim
e [s
ec]
![Page 48: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/48.jpg)
8.0 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 9.40
1000
2000
3000
4000
5000
6000
Fulltext benchmark - GiST vs. GIN
33k queries from postgresql.org [TOP 100]
GiST GIN
tota
l du
ratio
n [
sec]
![Page 49: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/49.jpg)
0.1 1 10 100 10000
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
Fulltext benchmark / 9.3 vs. 9.4 (GIN fastscan)
9.4 durations, divided by 9.3 durations (e.g. 0.1 means 10x speedup)
duration on 9.3 [miliseconds, log scale]
9.4
du
ratio
n (
rela
tive
to
9.3
)
![Page 50: Výkonnostní archeologie](https://reader034.vdocuments.site/reader034/viewer/2022042601/54816317b4af9fce158b5f0e/html5/thumbnails/50.jpg)
Fulltext / shrnutí
● GIN fastscan– dotazy kombinující “časté & vzácné”
– 9.4 skenuje “vzácné” seznam první
– exponenciální zrychlení pro tyto dotazy
– ... to je celkem fajn ;-)
● jenom ~5% dotazů se zpomalilo– víceméně dotazy pod 1ms (chyby měření)