Manajemen beban PostgreSQL, ketika satu server tidak cukup. Andrey Salnikov

Saya mengusulkan untuk berkenalan dengan decoding laporan awal 2019 oleh Andrey Salnikov, "Mengelola beban di PostgreSQL, ketika satu server sudah tidak cukup"


Poin utama:
1) Praktik penyeimbangan beban standar PostgreSQL. Pertama, kami membahas alasan tingginya beban pada basis data. Langkah selanjutnya adalah mempertimbangkan metode load balancing tersebut.
2) Pertanyaan akan dibahas tentang bagaimana replikasi diatur dalam PostgreSQL, apa perbedaan antara replika sinkron dan asinkron, dan bagaimana mengkonfigurasi replika dengan benar.




, . – Data Egret. . . HeadHunter, Lamoda. DBA PostgreSQL. DBA – . . , .


, - , .


Postgres open source’ community, . , Postgres.


, RDBMS . – enterprise: Oracle MSSQL, open source: MySQL Posgres, .


- . . . – Postgres .


– .


, - . , , , . . . Postgres, , , . , , .



. ? , . , -, .



, .



, , . . , , , , , , .


. , ? , raid 1 raid 0. . -. , , . , . , .



, , – 20 000-30 000. 40 000, , - . .


, . 50 000 . .



, , - - . . – , . . , . , . . . , , - , , , . .



. . , , . . , . .


, . – «exclusive», «share».


20 000 ( ), , - .


: HH Lamoda. , ? 10-20-50 , .


. , .



, , . , , . - . , , , , , , . .


, , Postgres , . . Postgres Posix, , , . – . , , : «, » sleep. , . , . , .



. .



timestamps.


, 30 . . . . RDBMS , . , - . , . , . .



-. , . .


, – idle-. Idle- , - pool connection. , , . , , , , , , , . overhead, , -, .


– . – , .


– , . - , : , . .


– - , . , , , .


? . .


, . ? -, . -, - Postgres ( MVCC), . update/delete, , , , .


idle in transaction , , Postgres . , . . , . , . , . - ( ), 10 , 300 , 400 . . Postgres, .


– waiting. , - . , , . , , .


, . . : - , . , Ruby, Python. , . , , - , . idle in transaction.


instances , . . - . . . , .



-. , pool connection . pools, . Hibernate pools. , pool. , pool .


, . , , idle-. . . , . , , , . , . , . . .


, , .



, , , . , .



.


, . . , , – . , - .


, , , . . , .


, 2,5 . 2 – transaction log. . , . , . . . 1,5 . : « . ». 0,5 . 2,5 0,5 . , .


. , . , , . .


. ORM-. . , , , . .


, , 2 , , 490 , . 490 , , . - . .


, , . , , , , , .


. , , , . . , - . , , , - , .


, , . , , . , . . , , . . , , – 3-4 , .


. . , .


? , . , , - . , : , , . , , « , ». , , , . , , , .


. Json, , . . . - Json . . , .


. , , , , . . . . , , , . , Json, . Json, . , .



. , join. . , , , , , .


Java , hibernate . Hibernate, , . . , 2 , . , . 2 – , .


, , Python, 490 , . . 5 . . . , . , - , , .


2 . , , . .


, , , . . , , , , . . , , . . . LEFT JOIN, DISTINCT , , - .


GROUP BY – DISTINCT. . . , . .


– COUNT, MAX, MIN , . . , , . , , . , . . . - . . , MIN, MAX . . .


, . «WHERE id IN (SELECT id FROM)», . «NOT EXISTS». id, , .


, . SELECT ids. id , – .


NOT EXISTS , . , : «, id, ». WHERE, . , WHERE , , , .


– . . , - , , . cron- ( ) , , , . , .


. , -, , . - . , , . PIDs . , , .


, HH , cron …, . . cron . , , – .



. . , : Kafka, RabbitMQ, ZeroMQ, .


, . . Skype SkyTools PGQ. . . . . 20 000-30 000 .


– . , . , , .


. . DBA, , Postgres. .


. , , idles. , .


idle-. . . , 10 , 15, 15 , . . idle 15 . , , .


pgbouncer . . , .


PgBouncer transaction-, . . : start transaction commit rollback. , … – . – . , , , .


Pgpool-II, , .


PgBouncer , . . Odyssey. . , . . . . -, , , - Odyssey Pgbouncer. PgBouncer – .


. , COUNT 200 , 200 . MIN , .


200 , 100 . . .


– , . . . , . , , , . , .


, . ? , 100 , 2 200 . , . , 90 % 10 % . 200 , .


. . Oracle, partition. «» . - – .


. .



?



. , , .


. , : , , , . , . , , . , , . , , . , .


. , , , , .


– . , , , : HDD SSD. NVMe . – , . , NVMe, .



? WHERE , , , .


, - . . .



– . – , . – , , . . – drop table, .


. - , , . - . , – Coca-Cola, Pepsi, Nike, Adidas . . , . . . .


, , , . . . , . . . . , . , , .



, , , 4 , 2 , 2 , , : « ?».


, - . , . , RDBMS .



. , , , .


: .


– , . INSERT. INSERT INSERT’ . DELETE DELETE SQL . .


. INSERT . , . . . . , .


, .


9.4 . . 9.6 . 10-11 . , , , , .


Postgres . , – , . .


Postgres, , , , . – . INSERTS DELETES.


, . Slony, Londiste Burcado.


Burcado – . – Slony. Londiste – , . , .


, , SQL? . , , . , - . , .


, Postgres , . .


? .


– -, , -. -, . , -. - .


. , -. Postgres , Postgres , , , , , , .


. . .


, , , , , , .


. , . , , 10-20 .


. , , .


? -, . , -, 20 , , , , . - . . , . -.


. . , Postgres, . .


. delayed . , . , 8 , 8 , . , 6 , . . . , . . . , 200 – .


. . . . , , - , , . . . – . , . . , , .



. ?


wal_keep_segments. , . - , , , wal- – 16 . . . 1 000 , , 1,5 . , .


, …, , -, , , . , «0» . , .


Max_standby_streaming_delay. . ? , . , - . , , . , , , .


, , , , . , Postgres , .


Synchronous_standby_names. - . . . . . . . . . .


Hot_standby_feedback. , , . , , , . .


, - : « , -. , , ». .


. . Hot_standby_feedback , -, . , . .


Recovery_min_apply_delay. CI/CD , , - , . 6 . 6 , . 8 .


, . , .



.



Postgres , . .


, full story , -, - . -. .


? , , . , COUNT, MAX - , , .



. 20 , . . . , , - . Join, .



- , KPI -. . , . max_standby_streaming_delay. , 4 , .


, 2 , . . . OLAP-, , -, , . , OLAP-. .


, , HeadHunter , . - . . , , . .


RDBMS , , , RDBMS, . , ClickHouse, .



. , latency. , , , , - . , . , . . . , . , , , .


, - , . - . , . .


, , , , . . . .


Skema "Last Addiction Stage" di HeadHunter terlihat seperti ini. Di sana mereka memiliki 11 server dalam kaskade untuk layanan utama. Dan itu berhasil. Mereka memiliki monolit gila yang bekerja tanpa masalah seperti jam. Sebagian karena fakta bahwa tim dukungan mereka memiliki premi yang tergantung pada bagaimana downtime itu. Mereka memiliki waktu henti yang diizinkan. Dan berapa banyak yang mereka hemat dari waktu yang diizinkan ini, sehingga mereka mendapat bonus yang baik. Dan mereka berusaha. Mereka mengalami downtime.


Saya memiliki segalanya tentang hal ini. Ini lebih indah, tapi saya pikir ini akan berguna.


Video:



All Articles