“
Perché dovrei avere un
database su Kubernetes?
“
Perché dovrei usare Postgres
come database?
“
Perché dovrei fare un
benchmark del database prima
di andare in produzione?
Benchmarking
Cloud Native
PostgreSQL
Francesco Canovai
1 Luglio 2021
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Francesco Canovai
• PostgreSQL
• Infrastruttura
• Automazione
• Testing
• Kubernetes
5
Twitter: @fcanovai / @EDBPostgres
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Argomenti
• I “perché”
• Com’è iniziato
• Storage
• Database
• cnp-bench
• Risultati
• Conclusioni
Intro
I “Perché”
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Perché un database su Kubernetes
Utilizzare al meglio un’infrastruttura a microservizi
8
● Un microservizio dovrebbe essere il proprietario dei suoi dati
○ I dati devono essere organizzati in un singolo data store o database
○ Solo il servizio deve avere accesso ai dati
○ Gestione dello schema inclusa
● Riduce il Carico cognitivo del Team
○ “Software that fits in your head” (Dan North)
● Definire chiare interfacce di comunicazione tra microservizi
● In Kubernetes, le applicazioni e i database coesistono:
○ Tutto è un workload (incluso il database)
○ Container e microservizi sono parte della definizione di Cloud Native
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Esempio di microservizi
9
Applicazioni web con backend PostgreSQL
Rest API
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
PostgreSQL popularity
Source: DB-Engines.com, 2021
Source: Stack Overflow Developer Survey, 2020
Perché PostgreSQL?
10
2017
2018
2020
Most loved database
Chi lo prova lo ama
Most popular database
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Feature
11
Versione ridotta
● Replica streaming nativa, logica e fisica, sincrona ed asincrona
● Continuous backup e point in time recovery
● Partizionamento dichiarativo
● Supporto JSON
● Estensioni (e.g. PostGIS)
● Query parallele
● INSERT .. ON CONFLICT DO UPDATE
● Supporto TLS e autenticazione con certificati
● SQL Standard (2016)
● DDL transazionali
● Ricerca full text nativa
● Tablespace
● ...
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
PostgreSQL: architettura di replica
12
Primario e repliche tramite replica streaming fisica nativa
● PostgreSQL supporta in modo nativo l’architettura primary/standby
○ Evolutione della Crash Recovery e della Point-In-Time Recovery
○ Introdotta in PostgreSQL 8.2 con WAL shipping e Warm Standby
○ Migliorata in PostgreSQL 9.0 con WAL streaming e Hot Standby (replica sola lettura)
● Ulteriori miglioramenti:
○ Replica sincrona
○ Replica in cascata
○ Replica logica
● Robusta e affidabile, con ottimi risultati in termini di RPO e RTO
2021 Copyright © EnterpriseDB Corporation All Rights Reserved 13
Due approcci a PostgreSQL su Kubernetes
Operatore (con replica PostgreSQL)
Container (con replica del file system)
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Stato richiesto Stato attuale
RW RW
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Cloud Native PostgreSQL by EDB
15
Il migliore database open source sul migliore orchestratore di container open source
● Operatore proprietario, con una licenza di prova implicita di 30 giorni
● Operandi:
○ PostgreSQL
○ EDB Postgres Advanced Server
● Documentazione disponibile
○ docs.enterprisedb.io
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Perché fare benchmark su PostgreSQL
16
Metodo scientifico
● Decisioni basate su dati e misurazioni ripetibili
○ “Lo sanno tutti” vs. “Perché le TPS osservate non sono sufficienti”
● Obiettivi:
○ Capacity planning e ottimizzazione dei costi
○ Prestazioni predicibili
● Prestazioni
○ Possono variare per molteplici fattori (hardware, software, network!)
○ Il database è pesantemente influenzato dallo storage (bottleneck)
● Prima di andare in produzione
Parte 1
Come è iniziato
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Un nuovo prodotto in 2ndQuadrant
18
L’esplorazione di Kubernetes inizia nel Q3/2019
● Contesto: esperienza pluriennale su DevOps/Lean/Agile
● Portare PostgreSQL su Kubernetes
○ Cosa manca dentro PostgreSQL per un esperto Kubernetes?
○ Cosa manca in Kubernetes per un esperto PostgreSQL?
○ Esplorazione con approccio fail-fast
● Obiettivo: arrivare in Kubernetes allo stesso livello che abbiamo su PostgreSQL
○ Prima compagnia PostgreSQL a diventare Kubernetes Certified Service Provider
● Per le nostre esperienza, le prestazioni dello storage erano la priorità principale
○ Possiamo fare funzionare PostgreSQL in un Kubernetes su bare-metal?
2021 Copyright © EnterpriseDB Corporation All Rights Reserved 19
Parte 2
Storage
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Cosa si aspetta un database dallo storage?
21
In bare metal, VM e container
● Disponibilità
● Scalabilità
● Prestazioni
● Consistenza
● Durabilità
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Storage e architetture
22
● Antipattern K8s
● Accesso diretto allo storage del SO
○ Sul nodo worker
● Richieste degli utenti PostgreSQL
○ Architettura shared nothing
○ Prestazioni
○ Predicibilità
○ HA tramite replica Postgres
Locale
Network
• Pattern K8s
• Numerose soluzioni disponibili
• HA tramite replica dello storage
• Storage condiviso
• Altri workload
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
PostgreSQL e lo storage (versione semplificata)
23
Dove lo storage diventa critico per PostgreSQL
● Write Ahead Log (WAL), in passato xlog
○ Scritture sequenziali e fsync
● Scrittura degli shared buffers
○ Fatta dal checkpoint, dal bgwriter, o dal backend
○ Scritture random
● Letture di pagine
○ Letture random
● Table scan
○ Letture sequenziali
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Cosa misurare
24
Metriche per la valutazione di uno storage
● Throughput:
○ Sequential read
○ Sequential write
○ Random read
○ Random write
● IOPS:
○ Limiti sul cloud
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Come misurare
25
● Il tool che abbiamo scelto per le misure
○ In passato abbiamo utilizzato bonnie++
● Simula numerosi tipi di I/O
● Configurable
● Multi-piattaforma
○ Utilizzabile anche su Kubernetes
● Open Source
○ GNU GPL 2
○ https://fio.readthedocs.io/
fio: Flexible I/O
“
Se lo storage è lento
il database sarà lento
Parte 3
Database
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Workload PostgreSQL
28
Tipi di carico di lavoro
● In-Memory
○ Il database entra interamente in RAM
○ Limitato da velocità di CPU e RAM
● OnLine Transactional Processing (OLTP)
○ Molte piccole transazioni concorrenti
○ Mix di inserimenti, letture e aggiornamenti
● OnLine Analytical Processing (OLAP)
○ Poche query complesse, principalmente in lettura, su dati storici
○ Usato per reportistica e business intelligence
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Cosa misurare
29
Quali metriche usare per valutare le prestazioni del database?
● Ci siamo concentrati su:
○ Carico di lavoro OLTP
○ Dimensione del database superiore alla RAM
■ Questo ci costringe a lavorare sul disco
● Metrica scelta:
○ Transazioni al secondo (TPS)
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Come misurare
30
pgbench
● Lo strumento che abbiamo scelto per il benchmark del database
● Parte del core di PostgreSQL
● Simula un carico di lavoro TPC-B like (OLTP)
● Configurabile
○ scale factor, numero di client e thread, durata, …
● Open Source, TPL
● Supporto per query custom
○ Niente batte l’applicazione reale
Parte 4
cnp-bench
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
cnp-bench
32
● Una raccolta di Helm chart
○ Facili da eseguire
○ Facili da personalizzare
○ Facili da riprodurre
● Esecuzione di benchmark per cluster Cloud Native PostgreSQL (CNP)
○ Utilizza fio e pgbench
○ Misurazione di IOPS e TPS
● github.com/EnterpriseDB/cnp-bench
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Fio benchmark
33
● Creazione di un PVC
○ Scegliendo la storage class e la dimensione
● Crea una ConfigMap per il job fio
○ Specifica il tipo di workload da eseguire sul PVC
● Fio è eseguito come deployment
○ Effettua il benchmark
○ Serve i risultati
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
values.yaml
34
pvcStorageClassName: default
pvcSize: 2Gi
nodeSelector: {}
jobRW: read
jobBs: 8k
jobRuntime: 60
jobTimeBased: 1
jobSize: 1G
jobIodepth: 32
jobDirect: 1
jobIoengine: libaio
jobEndFsync: 1
jobLogAvgMsec: 1000
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Risultati
35
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
pgbench
36
● Avvia un cluster Cloud Native PostgreSQL
○ Configurabile
○ Impostazioni di PostgreSQL diverse possono cambiare il risultato
● Esegue un job con pgbench
● I log di pgbench contengono i risultati
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
values.yaml
37
cnpInstances: 1
cnpStorageClass: default
cnpSize: 1Gi
cnpImage: quay.io/enterprisedb/postgresql:13.3
cnpNodeSelector:
workload: postgresql
cnpPostgreSQLParameters:
shared_buffers: '512MB'
maintenance_work_mem: '128MB'
pgbenchNodeSelector:
workload: pgbench
pgbenchScaleFactor: 1
pgbenchTime: 60
pgbenchClients: 1
pgbenchJobs: 1
pgbenchWarmTime: 0
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Risultati
38
starting vacuum...end.
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
duration: 60 s
number of transactions actually processed: 23114
latency average = 2.596 ms
tps = 385.225531 (including connections establishing)
tps = 385.271092 (excluding connections establishing)
Parte 5
cnp-bench su AKS
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
AKS
40
● Abbiamo eseguito dei test su AKS, con diverse combinazioni di VM dischi
● Le VM non sono definite solo da CPU e RAM
○ Diverse VM hanno limiti diversi per IOPS, larghezza di banda per I/O e rete
● Anche i dischi hanno i loro limiti di IOPS e banda
○ Alcuni dischi permettono di eccedere i limiti per breve tempo (burst)
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
AKS
41
Network storage
● P10
● P30
● P80
Standard_E8d_v4
● vCPU: 8
● RAM: 64GB
● Network bandwidth: 4000 Mb/s
Disk Size (GiB) BW (MiB/s) IOPS Burst
P10 100 100 500 Yes
P30 1000 200 5000 No
P80 20000 900 20000 No
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Benchmark fio: risultati
42
3600s - 8kb block size
Disk
Max BW
(MiB/s)
Max
IOPS
Seq Read Seq Write Rand Read Rand Write
MB/s IOPS MB/s IOPS MB/s IOPS MB/s IOPS
P10 100 500 483 58994 16.4 2003 452 55137 15.5 1960
P30 200 5000 85.3 10415 41.6 5082 42.7 5217 37.5 4575
P80 900 20000 81.3 9930 89.1 10881 92.6 11306 68.2 9655
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Il burst
43
Scritture sequenziali sul P10
Max BW
(MiB/s)
Max
IOPS
Seq Write
MB/s IOPS
100 500 16.4 2003
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
La cache di lettura
44
Disk
BW
(MiB/s)
IOPS
Seq Read Seq Write Rand Read Rand Write
MB/s IOPS MB/s IOPS MB/s IOPS MB/s IOPS
P10 100 500 483 58994 16.4 2003 452 55137 15.5 1960
P10NC 100 500 16.3 1986 16.4 2003 16.3 1985 15.5 1952
P30 200 5000 85.3 10415 41.6 5082 42.7 5217 37.5 4575
P30NC 200 5000 41.7 5088 41.6 5082 41.7 5087 37.5 4580
P80 900 20000 81.3 9930 89.1 10881 92.6 11306 68.2 9655
P80NC 900 20000 88.3 10778 88.2 10795 90.7 11,074 68.3 9621
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Durata: 1h
Dimensioni diverse del DB per dischi diversi
Configurazioni di PostgreSQL (comuni):
● shared_buffers: '16GB'
○ 64GB di RAM
● max_wal_size: '15GB'
● checkpoint_timeout: '900s'
● checkpoint_completion_target: '0.9'
● maintenance_work_mem: '2GB'
Pgbench: risultati
45
Disk DB size (GB) TPS
P10 71 1,499
P30 731 1,274
P80 1,490 1,051
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Work in progress: storage locale
46
Standard_L8s_v2
CPU: 8
RAM: 64
Throughput:
Max Read BW: 2000 MB/s
Max Read IOPS: 400000
Disks: 1x1.92 TB NVME
Seq Read Seq Write Rand Read Rand Write DB size
(GB)
TPS
MB/s IOPS MB/s IOPS MB/s IOPS MB/s IOPS
1,142 139,370 696 84,996 1,070 130,587 262 32,010 732 2,082
Conclusioni
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Riepilogo degli argomenti
48
PostgreSQL su Kubernetes? Si può fare!
● Un metodo per effettuare benchmark di PostgreSQL su Kubernetes
● Degli strumenti open source per il benchmark
● Perché è importante fare benchmark dello storage e del database
● Usare cnp-bench per il benchmark di Cloud Native PostgreSQL:
○ github.com/EnterpriseDB/cnp-bench
2021 Copyright © EnterpriseDB Corporation All Rights Reserved
Stiamo assumendo!
• enterprisedb.com/careers
• Numerose posizioni
• Da remoto, in tutto il mondo
• Nel nostro team:
• GoLang Developer, Kubernetes
• Automation engineer, DevOps/Kubernetes

More Related Content

PDF
Cloud Native PostgreSQL - Italiano
 
PDF
Db2 11.1: l'evoluzione del Database secondo IBM
PDF
MongoDB Atlas: il modo migliore per eseguire MongoDB in ambiente cloud 1
PDF
Love Your Database (ESC 2k16)
PDF
JBoss Data Grid Tech Lab
PDF
Azure Meetup: Azure Storage/Datalake Deep Dive
PDF
MongoDB Atlas: il modo migliore per eseguire MongoDB in ambiente cloud 2
PDF
Data grid
Cloud Native PostgreSQL - Italiano
 
Db2 11.1: l'evoluzione del Database secondo IBM
MongoDB Atlas: il modo migliore per eseguire MongoDB in ambiente cloud 1
Love Your Database (ESC 2k16)
JBoss Data Grid Tech Lab
Azure Meetup: Azure Storage/Datalake Deep Dive
MongoDB Atlas: il modo migliore per eseguire MongoDB in ambiente cloud 2
Data grid

What's hot (20)

PDF
Power BI: Introduzione ai dataflow e alla preparazione dei dati self-service
PDF
SQL Server Modern Query Processing
PDF
Infinispan codemotion - Codemotion Rome 2015
PPTX
Operational Data Store vs Data Lake
PDF
Hadoop
PPTX
Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...
PDF
Big data - stack tecnologico
PDF
Presentazione bd2
PPTX
Cyber Security in Multi Cloud Architecture - Luca Di Bari - Codemotion Rome 2017
PPTX
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
PPTX
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
PPTX
Azure Synapse: data lake & modern data warehouse dalla A alla Z
ODP
Cloud storage in azienda: perche` Riak ci e` piaciuto
PPTX
Webinar: Come semplificare l'utilizzo del database con MongoDB Atlas
PPTX
Apache Hadoop: Introduzione all’architettura ed approcci applicativi
PPT
Presentazione Nuvola Vertica Light
PDF
SQL Saturday 2019 - Event Processing with Spark
PDF
Hadoop - Introduzione all’architettura ed approcci applicativi
PDF
The Google File System
PPTX
Back to Basics webinar 1 IT 17 - Introduzione ai NoSQL
Power BI: Introduzione ai dataflow e alla preparazione dei dati self-service
SQL Server Modern Query Processing
Infinispan codemotion - Codemotion Rome 2015
Operational Data Store vs Data Lake
Hadoop
Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...
Big data - stack tecnologico
Presentazione bd2
Cyber Security in Multi Cloud Architecture - Luca Di Bari - Codemotion Rome 2017
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
Azure Synapse: data lake & modern data warehouse dalla A alla Z
Cloud storage in azienda: perche` Riak ci e` piaciuto
Webinar: Come semplificare l'utilizzo del database con MongoDB Atlas
Apache Hadoop: Introduzione all’architettura ed approcci applicativi
Presentazione Nuvola Vertica Light
SQL Saturday 2019 - Event Processing with Spark
Hadoop - Introduzione all’architettura ed approcci applicativi
The Google File System
Back to Basics webinar 1 IT 17 - Introduzione ai NoSQL
Ad

Similar to Benchmarking Cloud Native PostgreSQL (20)

PDF
Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB
PPTX
PostgrSQL 9.3&9.4 - DjangoVillage
PDF
MySQL Tech Tour 2015 - Progettare, installare e configurare MySQL Cluster
PDF
Cassandra DB - Linux Day 2019 - Catania - Italy
PDF
Da Oracle a PostgreSQL: l'evoluzione dei RDBMS
PPTX
Telegraph Cq Italian
PDF
Studio di una Architettura per un Sistema Distributivo ad Alta Affidabilità
PDF
PostgreSQL, The Big, The Fast and The Ugly
PDF
Ottimizzazione della gestione dei dati sul cloud
PPTX
Evoluzioni architetturali a partire da Hadoop
PDF
MySQL Day Roma 2019 - Le architetture a microservizi e MySQL
PDF
Pgtraining bdr
PDF
MySQL 5
PDF
Logical Data Management: La chiave per sfruttare al massimo il potenziale dei...
PDF
PostgreSQL - Hadoop: Why not? - PGDay.IT 2016
PDF
Azure SQL Database Ledger
PDF
Foundation server
PDF
SQL Server in AWS
PDF
Foundation server
ODP
TDD DataBase
Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB
PostgrSQL 9.3&9.4 - DjangoVillage
MySQL Tech Tour 2015 - Progettare, installare e configurare MySQL Cluster
Cassandra DB - Linux Day 2019 - Catania - Italy
Da Oracle a PostgreSQL: l'evoluzione dei RDBMS
Telegraph Cq Italian
Studio di una Architettura per un Sistema Distributivo ad Alta Affidabilità
PostgreSQL, The Big, The Fast and The Ugly
Ottimizzazione della gestione dei dati sul cloud
Evoluzioni architetturali a partire da Hadoop
MySQL Day Roma 2019 - Le architetture a microservizi e MySQL
Pgtraining bdr
MySQL 5
Logical Data Management: La chiave per sfruttare al massimo il potenziale dei...
PostgreSQL - Hadoop: Why not? - PGDay.IT 2016
Azure SQL Database Ledger
Foundation server
SQL Server in AWS
Foundation server
TDD DataBase
Ad

More from EDB (20)

PDF
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
 
PDF
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
PDF
Migre sus bases de datos Oracle a la nube
 
PDF
EFM Office Hours - APJ - July 29, 2021
 
PDF
Las Variaciones de la Replicación de PostgreSQL
 
PDF
NoSQL and Spatial Database Capabilities using PostgreSQL
 
PDF
Is There Anything PgBouncer Can’t Do?
 
PDF
Data Analysis with TensorFlow in PostgreSQL
 
PDF
Practical Partitioning in Production with Postgres
 
PDF
A Deeper Dive into EXPLAIN
 
PDF
IOT with PostgreSQL
 
PDF
A Journey from Oracle to PostgreSQL
 
PDF
Psql is awesome!
 
PDF
EDB 13 - New Enhancements for Security and Usability - APJ
 
PPTX
Comment sauvegarder correctement vos données
 
PDF
New enhancements for security and usability in EDB 13
 
PPTX
Best Practices in Security with PostgreSQL
 
PDF
Cloud Native PostgreSQL - APJ
 
PDF
Best Practices in Security with PostgreSQL
 
PDF
EDB Postgres & Tools in a Smart City Project
 
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
Migre sus bases de datos Oracle a la nube
 
EFM Office Hours - APJ - July 29, 2021
 
Las Variaciones de la Replicación de PostgreSQL
 
NoSQL and Spatial Database Capabilities using PostgreSQL
 
Is There Anything PgBouncer Can’t Do?
 
Data Analysis with TensorFlow in PostgreSQL
 
Practical Partitioning in Production with Postgres
 
A Deeper Dive into EXPLAIN
 
IOT with PostgreSQL
 
A Journey from Oracle to PostgreSQL
 
Psql is awesome!
 
EDB 13 - New Enhancements for Security and Usability - APJ
 
Comment sauvegarder correctement vos données
 
New enhancements for security and usability in EDB 13
 
Best Practices in Security with PostgreSQL
 
Cloud Native PostgreSQL - APJ
 
Best Practices in Security with PostgreSQL
 
EDB Postgres & Tools in a Smart City Project
 

Benchmarking Cloud Native PostgreSQL

  • 1. “ Perché dovrei avere un database su Kubernetes?
  • 2. “ Perché dovrei usare Postgres come database?
  • 3. “ Perché dovrei fare un benchmark del database prima di andare in produzione?
  • 5. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Francesco Canovai • PostgreSQL • Infrastruttura • Automazione • Testing • Kubernetes 5 Twitter: @fcanovai / @EDBPostgres
  • 6. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Argomenti • I “perché” • Com’è iniziato • Storage • Database • cnp-bench • Risultati • Conclusioni
  • 8. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Perché un database su Kubernetes Utilizzare al meglio un’infrastruttura a microservizi 8 ● Un microservizio dovrebbe essere il proprietario dei suoi dati ○ I dati devono essere organizzati in un singolo data store o database ○ Solo il servizio deve avere accesso ai dati ○ Gestione dello schema inclusa ● Riduce il Carico cognitivo del Team ○ “Software that fits in your head” (Dan North) ● Definire chiare interfacce di comunicazione tra microservizi ● In Kubernetes, le applicazioni e i database coesistono: ○ Tutto è un workload (incluso il database) ○ Container e microservizi sono parte della definizione di Cloud Native
  • 9. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Esempio di microservizi 9 Applicazioni web con backend PostgreSQL Rest API
  • 10. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved PostgreSQL popularity Source: DB-Engines.com, 2021 Source: Stack Overflow Developer Survey, 2020 Perché PostgreSQL? 10 2017 2018 2020 Most loved database Chi lo prova lo ama Most popular database
  • 11. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Feature 11 Versione ridotta ● Replica streaming nativa, logica e fisica, sincrona ed asincrona ● Continuous backup e point in time recovery ● Partizionamento dichiarativo ● Supporto JSON ● Estensioni (e.g. PostGIS) ● Query parallele ● INSERT .. ON CONFLICT DO UPDATE ● Supporto TLS e autenticazione con certificati ● SQL Standard (2016) ● DDL transazionali ● Ricerca full text nativa ● Tablespace ● ...
  • 12. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved PostgreSQL: architettura di replica 12 Primario e repliche tramite replica streaming fisica nativa ● PostgreSQL supporta in modo nativo l’architettura primary/standby ○ Evolutione della Crash Recovery e della Point-In-Time Recovery ○ Introdotta in PostgreSQL 8.2 con WAL shipping e Warm Standby ○ Migliorata in PostgreSQL 9.0 con WAL streaming e Hot Standby (replica sola lettura) ● Ulteriori miglioramenti: ○ Replica sincrona ○ Replica in cascata ○ Replica logica ● Robusta e affidabile, con ottimi risultati in termini di RPO e RTO
  • 13. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved 13 Due approcci a PostgreSQL su Kubernetes Operatore (con replica PostgreSQL) Container (con replica del file system)
  • 14. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Stato richiesto Stato attuale RW RW
  • 15. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Cloud Native PostgreSQL by EDB 15 Il migliore database open source sul migliore orchestratore di container open source ● Operatore proprietario, con una licenza di prova implicita di 30 giorni ● Operandi: ○ PostgreSQL ○ EDB Postgres Advanced Server ● Documentazione disponibile ○ docs.enterprisedb.io
  • 16. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Perché fare benchmark su PostgreSQL 16 Metodo scientifico ● Decisioni basate su dati e misurazioni ripetibili ○ “Lo sanno tutti” vs. “Perché le TPS osservate non sono sufficienti” ● Obiettivi: ○ Capacity planning e ottimizzazione dei costi ○ Prestazioni predicibili ● Prestazioni ○ Possono variare per molteplici fattori (hardware, software, network!) ○ Il database è pesantemente influenzato dallo storage (bottleneck) ● Prima di andare in produzione
  • 17. Parte 1 Come è iniziato
  • 18. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Un nuovo prodotto in 2ndQuadrant 18 L’esplorazione di Kubernetes inizia nel Q3/2019 ● Contesto: esperienza pluriennale su DevOps/Lean/Agile ● Portare PostgreSQL su Kubernetes ○ Cosa manca dentro PostgreSQL per un esperto Kubernetes? ○ Cosa manca in Kubernetes per un esperto PostgreSQL? ○ Esplorazione con approccio fail-fast ● Obiettivo: arrivare in Kubernetes allo stesso livello che abbiamo su PostgreSQL ○ Prima compagnia PostgreSQL a diventare Kubernetes Certified Service Provider ● Per le nostre esperienza, le prestazioni dello storage erano la priorità principale ○ Possiamo fare funzionare PostgreSQL in un Kubernetes su bare-metal?
  • 19. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved 19
  • 21. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Cosa si aspetta un database dallo storage? 21 In bare metal, VM e container ● Disponibilità ● Scalabilità ● Prestazioni ● Consistenza ● Durabilità
  • 22. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Storage e architetture 22 ● Antipattern K8s ● Accesso diretto allo storage del SO ○ Sul nodo worker ● Richieste degli utenti PostgreSQL ○ Architettura shared nothing ○ Prestazioni ○ Predicibilità ○ HA tramite replica Postgres Locale Network • Pattern K8s • Numerose soluzioni disponibili • HA tramite replica dello storage • Storage condiviso • Altri workload
  • 23. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved PostgreSQL e lo storage (versione semplificata) 23 Dove lo storage diventa critico per PostgreSQL ● Write Ahead Log (WAL), in passato xlog ○ Scritture sequenziali e fsync ● Scrittura degli shared buffers ○ Fatta dal checkpoint, dal bgwriter, o dal backend ○ Scritture random ● Letture di pagine ○ Letture random ● Table scan ○ Letture sequenziali
  • 24. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Cosa misurare 24 Metriche per la valutazione di uno storage ● Throughput: ○ Sequential read ○ Sequential write ○ Random read ○ Random write ● IOPS: ○ Limiti sul cloud
  • 25. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Come misurare 25 ● Il tool che abbiamo scelto per le misure ○ In passato abbiamo utilizzato bonnie++ ● Simula numerosi tipi di I/O ● Configurable ● Multi-piattaforma ○ Utilizzabile anche su Kubernetes ● Open Source ○ GNU GPL 2 ○ https://fio.readthedocs.io/ fio: Flexible I/O
  • 26. “ Se lo storage è lento il database sarà lento
  • 28. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Workload PostgreSQL 28 Tipi di carico di lavoro ● In-Memory ○ Il database entra interamente in RAM ○ Limitato da velocità di CPU e RAM ● OnLine Transactional Processing (OLTP) ○ Molte piccole transazioni concorrenti ○ Mix di inserimenti, letture e aggiornamenti ● OnLine Analytical Processing (OLAP) ○ Poche query complesse, principalmente in lettura, su dati storici ○ Usato per reportistica e business intelligence
  • 29. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Cosa misurare 29 Quali metriche usare per valutare le prestazioni del database? ● Ci siamo concentrati su: ○ Carico di lavoro OLTP ○ Dimensione del database superiore alla RAM ■ Questo ci costringe a lavorare sul disco ● Metrica scelta: ○ Transazioni al secondo (TPS)
  • 30. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Come misurare 30 pgbench ● Lo strumento che abbiamo scelto per il benchmark del database ● Parte del core di PostgreSQL ● Simula un carico di lavoro TPC-B like (OLTP) ● Configurabile ○ scale factor, numero di client e thread, durata, … ● Open Source, TPL ● Supporto per query custom ○ Niente batte l’applicazione reale
  • 32. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved cnp-bench 32 ● Una raccolta di Helm chart ○ Facili da eseguire ○ Facili da personalizzare ○ Facili da riprodurre ● Esecuzione di benchmark per cluster Cloud Native PostgreSQL (CNP) ○ Utilizza fio e pgbench ○ Misurazione di IOPS e TPS ● github.com/EnterpriseDB/cnp-bench
  • 33. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Fio benchmark 33 ● Creazione di un PVC ○ Scegliendo la storage class e la dimensione ● Crea una ConfigMap per il job fio ○ Specifica il tipo di workload da eseguire sul PVC ● Fio è eseguito come deployment ○ Effettua il benchmark ○ Serve i risultati
  • 34. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved values.yaml 34 pvcStorageClassName: default pvcSize: 2Gi nodeSelector: {} jobRW: read jobBs: 8k jobRuntime: 60 jobTimeBased: 1 jobSize: 1G jobIodepth: 32 jobDirect: 1 jobIoengine: libaio jobEndFsync: 1 jobLogAvgMsec: 1000
  • 35. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Risultati 35
  • 36. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved pgbench 36 ● Avvia un cluster Cloud Native PostgreSQL ○ Configurabile ○ Impostazioni di PostgreSQL diverse possono cambiare il risultato ● Esegue un job con pgbench ● I log di pgbench contengono i risultati
  • 37. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved values.yaml 37 cnpInstances: 1 cnpStorageClass: default cnpSize: 1Gi cnpImage: quay.io/enterprisedb/postgresql:13.3 cnpNodeSelector: workload: postgresql cnpPostgreSQLParameters: shared_buffers: '512MB' maintenance_work_mem: '128MB' pgbenchNodeSelector: workload: pgbench pgbenchScaleFactor: 1 pgbenchTime: 60 pgbenchClients: 1 pgbenchJobs: 1 pgbenchWarmTime: 0
  • 38. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Risultati 38 starting vacuum...end. transaction type: <builtin: TPC-B (sort of)> scaling factor: 1 query mode: simple number of clients: 1 number of threads: 1 duration: 60 s number of transactions actually processed: 23114 latency average = 2.596 ms tps = 385.225531 (including connections establishing) tps = 385.271092 (excluding connections establishing)
  • 40. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved AKS 40 ● Abbiamo eseguito dei test su AKS, con diverse combinazioni di VM dischi ● Le VM non sono definite solo da CPU e RAM ○ Diverse VM hanno limiti diversi per IOPS, larghezza di banda per I/O e rete ● Anche i dischi hanno i loro limiti di IOPS e banda ○ Alcuni dischi permettono di eccedere i limiti per breve tempo (burst)
  • 41. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved AKS 41 Network storage ● P10 ● P30 ● P80 Standard_E8d_v4 ● vCPU: 8 ● RAM: 64GB ● Network bandwidth: 4000 Mb/s Disk Size (GiB) BW (MiB/s) IOPS Burst P10 100 100 500 Yes P30 1000 200 5000 No P80 20000 900 20000 No
  • 42. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Benchmark fio: risultati 42 3600s - 8kb block size Disk Max BW (MiB/s) Max IOPS Seq Read Seq Write Rand Read Rand Write MB/s IOPS MB/s IOPS MB/s IOPS MB/s IOPS P10 100 500 483 58994 16.4 2003 452 55137 15.5 1960 P30 200 5000 85.3 10415 41.6 5082 42.7 5217 37.5 4575 P80 900 20000 81.3 9930 89.1 10881 92.6 11306 68.2 9655
  • 43. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Il burst 43 Scritture sequenziali sul P10 Max BW (MiB/s) Max IOPS Seq Write MB/s IOPS 100 500 16.4 2003
  • 44. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved La cache di lettura 44 Disk BW (MiB/s) IOPS Seq Read Seq Write Rand Read Rand Write MB/s IOPS MB/s IOPS MB/s IOPS MB/s IOPS P10 100 500 483 58994 16.4 2003 452 55137 15.5 1960 P10NC 100 500 16.3 1986 16.4 2003 16.3 1985 15.5 1952 P30 200 5000 85.3 10415 41.6 5082 42.7 5217 37.5 4575 P30NC 200 5000 41.7 5088 41.6 5082 41.7 5087 37.5 4580 P80 900 20000 81.3 9930 89.1 10881 92.6 11306 68.2 9655 P80NC 900 20000 88.3 10778 88.2 10795 90.7 11,074 68.3 9621
  • 45. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Durata: 1h Dimensioni diverse del DB per dischi diversi Configurazioni di PostgreSQL (comuni): ● shared_buffers: '16GB' ○ 64GB di RAM ● max_wal_size: '15GB' ● checkpoint_timeout: '900s' ● checkpoint_completion_target: '0.9' ● maintenance_work_mem: '2GB' Pgbench: risultati 45 Disk DB size (GB) TPS P10 71 1,499 P30 731 1,274 P80 1,490 1,051
  • 46. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Work in progress: storage locale 46 Standard_L8s_v2 CPU: 8 RAM: 64 Throughput: Max Read BW: 2000 MB/s Max Read IOPS: 400000 Disks: 1x1.92 TB NVME Seq Read Seq Write Rand Read Rand Write DB size (GB) TPS MB/s IOPS MB/s IOPS MB/s IOPS MB/s IOPS 1,142 139,370 696 84,996 1,070 130,587 262 32,010 732 2,082
  • 48. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Riepilogo degli argomenti 48 PostgreSQL su Kubernetes? Si può fare! ● Un metodo per effettuare benchmark di PostgreSQL su Kubernetes ● Degli strumenti open source per il benchmark ● Perché è importante fare benchmark dello storage e del database ● Usare cnp-bench per il benchmark di Cloud Native PostgreSQL: ○ github.com/EnterpriseDB/cnp-bench
  • 49. 2021 Copyright © EnterpriseDB Corporation All Rights Reserved Stiamo assumendo! • enterprisedb.com/careers • Numerose posizioni • Da remoto, in tutto il mondo • Nel nostro team: • GoLang Developer, Kubernetes • Automation engineer, DevOps/Kubernetes