SlideShare a Scribd company logo
© 2013 EDB All rights reserved. 1
Scalability And Performance
Improvements In PostgreSQL 9.6
•
Dilip Kumar | 2016.03.17
PgDay Asia Singapore
Who am I ?
Dilip Kumar
 Currently working at EnterpriseDB
 Have worked to develop various features on PostgreSQL (for
internal projects) as well as on other In-House DB at Huawei.
 I have also contributed patches to community.
 Holds around 14 patents in my name in various DB technologies.
 I have presented a paper in PgCon 2015
3
 Journey From 9.1 to 9.5
 What’s In 9.6 ?
 MVCC Scalability Improvement
 Clog Scalability
 Bulk Load Scalability
 Parallel Query
 Sorting Improvement
 Hash Lock Improvement
 Index Only Scan with partial Index
 Partial Sort
 Cache the Snapshot
 Buffer Header Spin Lock
Contents
Journey From 9.1 to 9.5
Whats’s In 9.6 ?
ProcArray Lock Contention Solved : Commited
Parallel Sequence Scan : Commited
Parallel NLJ and HJ : Commited
Clog Control Lock Issue : In Progress
Bulk Load Scalability : In Progress
Buffer Header Lock Issue : In progress
Hash Header Lock Contention : In Progress
Sorting Improvement using Quick Sort : In Progress
Checkpoint Continuous Flushing : In Progress
Index Only Scan with partial Index : In Progress
Caching the Snapshot : In Progress
Partial Sort : In Progress
MVCC Scalability Improvement
6
ProcArrayLock:
 Was the major contention point
reported in 9.5 and blocking Read
write workload to scale beyond 30
cores in TPCC.
 With Pgbench also After 30 cores
scalability was not linear.
1 8 16 32 64 128
0
5000
10000
15000
20000
25000
30000
pgbench -M prepared Median Of 30 mins of Runs Syncrhronous Commit=On
Head
Clients
TPS
MVCC Scalability Improvement
 Many Solutions were tried to
overcome this problem, like
CSN snapshot, Incremental
Snapshot.
 Finally Group clear Xid in
ProcArrayEnd Transaction
Successfully got committed for
9.6 version and Scaling is
almost linear upto 64 Clients in
64 thread machine.
1 8 16 32 64 128
0
5000
10000
15000
20000
25000
30000
35000
pgbench-MpreparedMedianOf30minsofRunsSyncrhronousCommit=On
Head
Patch
Clients
TPS
Clog Control Improvement
8
Clog Control Lock:
 Afer reducing ProcArrayLock contenton CLogControlLock become next   
visible contenton Point.
 Contenton is mainly due to two reasons, one is that while writng the
transacton status in CLOG, it acquires EXCLUSIVE CLogControlLock which   
contends with every other transacton which tries to access the CLOG for   
checking transacton status and to reduce it. Second contenton is due to   
the reason that when the CLOG page is not found in CLOG bufers, it needs       
to acquire CLogControlLock in Exclusive mode which again contends with   
shared lockers which tries to access the transacton status.
 Soluton Used for ClogControl Lock is Similar to the ProcArray Group Clear
XID.
Clog Control Improvement
9
Bulk Load Scalability
Relation Extension Lock:
 Currently Relation extension Lock is becoming bottleneck while extending
the relation in parallel.
 Both COPY and INSERT are Suffering From the same problem.
 Recently we are working on this various solutions are tries, and Currently
this is in Progress. (Lock Free Extension, Extend In multiple Blocks with
User Knob, Group Extend the Relation, Extend In multiple of Lock
Waiters).
Bulk Load Scalability
1 2 4 8 16 32 64
0
200
400
600
800
1000
1200
COPY10000 Record (4Bytes) Data Fits in Shared Buffers
Base
Patch
Clients
TPS
1 2 4 8 16 32 64
0
50
100
150
200
250
300
INSERT 1000 Records (1K) data doesn't fits In Shared Buffers
Base
Patch
Clients
TPS
Parallel Query
12
 Parallel Query is a Great Win for 9.6 this allows to run
single query in Parallel in multiple workers.
 Parallel Sequence Scan and Parallel Join are already
Committed and some are in progress like Parallel Index
Scan, Parallel Aggregate.
 Parallel Sequence Scan and Parallel Join has shown Great
Improvement for Single Query.
Parallel Query
13
Q3 Q4 Q5 Q7 Q8
0
2000
4000
6000
8000
10000
12000
14000
TPC-H Query with scale factor=5
Time in ms
Sorting Improvement
Using quicksort for every external sort:
This usage a quick sort instead of Replacement
Selection.
Replacing with quick sort which is cache
conscious algorithm, that improves the
performance significantly.
Sorting Improvement
1.7 3.5 7 14
0
50000
100000
150000
200000
250000
300000
350000
400000
Time Calculation for Using Quick Sort For All External Sort Work_mem= DEFAULT (4mb).
Head
Patch
Data Size (GB)
Time in (ms)
Hash Header Lock Contention
Hash Header mutex Contention:
 Postgres internal hash table is used for many key Operation.
 Heavy Weight Locks are managed in hash Tables.
 Buffer pool is managed by hash Tables.
 But whenever hash needs to allocate element from free list or
release to free list, there is one common lock and that become
main contention point.
 As part of this work this is converted to partitioned level freelist
now each partition have separate freelist and separate Locks.
 Freelist elements can be shared across partitions.
Hash Header Lock Contention
z
64 128
0
50000
100000
150000
200000
250000
300000
350000
PgBench: Scale Factor 300 Shared Buffer 512MB
Head
Patch
Cleints
TPS
Index only scan with partial index
What is Partial Index ?
 A partial index is an index built over a subset of a table; the subset is
defined by a conditional expression (called the predicate of the partial
index). The index contains entries for only those table rows that satisfy the
predicate.
 A major motivation for partial indexes is to avoid indexing common values.
Since a query searching for a common value (one that accounts for more
than a few percent of all the table rows) will not use the index anyway, there
is no point in keeping those rows in the index at all. This reduces the size of
the index, which will speed up queries that do use the index.
Index only scan with partial index
Problem:
 Currently partial indexes end up not using index only scans in most of the
cases.
 unless you include all columns from the index predicate to the index, the
planner will decide index only scans are not possible.
 Adding those columns which are not needed at runtime, will only increase
the index size.
Solution:
 Select the index only scan, if there are some key which are not really
required at runtime.
Partial Sort
 In PostgreSQL If all the sort keys are part of the index then
index scan will be selected for sorting.
 Otherwise scan all tuple from heap and Sort them
completely.
 As per this patch, mix both methods:
 get results from index in order which partially meets our
requirements
 do rest of work from heap.
Cache The Snapshot
 As per this Improvement whenever backend take a
snapshot its stored in a shared cache.
 Whenever any transaction is getting commited, saved
snapshot will be marked Invalid.
 When there is mix load of read and write that time if b/w
multiple read there is no write transaction, snapshot can be
reuse.
 When write transaction Invalidate the snapshot, First
transaction taking the snapshot will recalculate and update
the cached snapshot
Cache The Snapshot
64 88 128 256
0
5000
10000
15000
20000
25000
30000
35000
40000
Pgbench: Scale factor 300 Shared Buff=8GB
BASE
ONLY CLOG CHANGES
CLOG + SAVE SNAPSHOT
Clients
TPS
Buffer Header lock Improvement
Convert Pin/Unpin Spin Lock to Atomic Operation:
 Spin Lock inside the Pin and Unpin buffer is also one of the
bottleneck, While testing scalability in Big NUMA Machines.
 As per this patch Spin lock is converted to Atomic Operation and
Increasing/decreasing reference count is done using just one
ATOMIC operations.
 Other Operation which need to do more work other than just
updating state variable, that takes a Lock and Lock is using atomic
operation.
Buffer Header lock Improvement
1 8 16 32 64
0
100000
200000
300000
400000
500000
600000
700000
800000
pgbench read only test -M prepared S.F=1000 Shared Buffer=8GB
Head
Pached
Clients
TPS
Questions?
25
Thanks!
26

More Related Content

PDF
Query Parallelism in PostgreSQL: What's coming next?
PGConf APAC
 
PDF
Overview of Postgres 9.5
EDB
 
PDF
Get to know PostgreSQL!
Oddbjørn Steffensen
 
PDF
PGConf.ASIA 2019 Bali - Performance Analysis at Full Power - Julien Rouhaud
Equnix Business Solutions
 
PDF
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
InMobi Technology
 
PDF
Loadays MySQL
lefredbe
 
PPTX
The Magic of Tuning in PostgreSQL
Ashnikbiz
 
PPTX
Low Level CPU Performance Profiling Examples
Tanel Poder
 
Query Parallelism in PostgreSQL: What's coming next?
PGConf APAC
 
Overview of Postgres 9.5
EDB
 
Get to know PostgreSQL!
Oddbjørn Steffensen
 
PGConf.ASIA 2019 Bali - Performance Analysis at Full Power - Julien Rouhaud
Equnix Business Solutions
 
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
InMobi Technology
 
Loadays MySQL
lefredbe
 
The Magic of Tuning in PostgreSQL
Ashnikbiz
 
Low Level CPU Performance Profiling Examples
Tanel Poder
 

What's hot (20)

PDF
Case Studies on PostgreSQL
InMobi Technology
 
PDF
Online Upgrade Using Logical Replication.
EDB
 
PDF
Oracle Database In-Memory and the Query Optimizer
Christian Antognini
 
PDF
PostgreSQL Enterprise Class Features and Capabilities
PGConf APAC
 
PDF
PostgreSQL WAL for DBAs
PGConf APAC
 
PPTX
Building Spark as Service in Cloud
InMobi Technology
 
PDF
Lessons PostgreSQL learned from commercial databases, and didn’t
PGConf APAC
 
PDF
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
Mydbops
 
PDF
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Tanel Poder
 
PDF
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Kristofferson A
 
PDF
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Ashnikbiz
 
PPTX
Creating a Benchmarking Infrastructure That Just Works
Tim Callaghan
 
PDF
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL-Consulting
 
PDF
Whitepaper: Exadata Consolidation Success Story
Kristofferson A
 
PDF
Whitepaper: Where did my CPU go?
Kristofferson A
 
PPT
MySQL Performance Tuning at COSCUP 2014
Ryusuke Kajiyama
 
PDF
Managing terabytes: When PostgreSQL gets big
Selena Deckelmann
 
PDF
Really Big Elephants: PostgreSQL DW
PostgreSQL Experts, Inc.
 
PDF
2016 may-countdown-to-postgres-v96-parallel-query
Ashnikbiz
 
PDF
What's New In PostgreSQL 9.4
Pavan Deolasee
 
Case Studies on PostgreSQL
InMobi Technology
 
Online Upgrade Using Logical Replication.
EDB
 
Oracle Database In-Memory and the Query Optimizer
Christian Antognini
 
PostgreSQL Enterprise Class Features and Capabilities
PGConf APAC
 
PostgreSQL WAL for DBAs
PGConf APAC
 
Building Spark as Service in Cloud
InMobi Technology
 
Lessons PostgreSQL learned from commercial databases, and didn’t
PGConf APAC
 
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
Mydbops
 
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Tanel Poder
 
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Kristofferson A
 
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Ashnikbiz
 
Creating a Benchmarking Infrastructure That Just Works
Tim Callaghan
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL-Consulting
 
Whitepaper: Exadata Consolidation Success Story
Kristofferson A
 
Whitepaper: Where did my CPU go?
Kristofferson A
 
MySQL Performance Tuning at COSCUP 2014
Ryusuke Kajiyama
 
Managing terabytes: When PostgreSQL gets big
Selena Deckelmann
 
Really Big Elephants: PostgreSQL DW
PostgreSQL Experts, Inc.
 
2016 may-countdown-to-postgres-v96-parallel-query
Ashnikbiz
 
What's New In PostgreSQL 9.4
Pavan Deolasee
 
Ad

Viewers also liked (7)

PDF
What's New in PostgreSQL 9.6
EDB
 
PPTX
One Coin One Brick project
Huy Nguyen
 
PDF
Why PostgreSQL for Analytics Infrastructure (DW)?
Huy Nguyen
 
PDF
Supersized PostgreSQL: Postgres-XL for Scale-Out OLTP and Big Data Analytics
mason_s
 
PDF
5 Postgres DBA Tips
EDB
 
PDF
Making Postgres Central in Your Data Center
EDB
 
PDF
Bn 1016 demo postgre sql-online-training
conline training
 
What's New in PostgreSQL 9.6
EDB
 
One Coin One Brick project
Huy Nguyen
 
Why PostgreSQL for Analytics Infrastructure (DW)?
Huy Nguyen
 
Supersized PostgreSQL: Postgres-XL for Scale-Out OLTP and Big Data Analytics
mason_s
 
5 Postgres DBA Tips
EDB
 
Making Postgres Central in Your Data Center
EDB
 
Bn 1016 demo postgre sql-online-training
conline training
 
Ad

Similar to PostgreSQL 9.6 Performance-Scalability Improvements (20)

PDF
Maximizing Database Tuning in SAP SQL Anywhere
SAP Technology
 
PPTX
SQL Server It Just Runs Faster
Bob Ward
 
PDF
Apache Spark 3.0: Overview of What’s New and Why Care
Databricks
 
PDF
The Practice of Presto & Alluxio in E-Commerce Big Data Platform
Alluxio, Inc.
 
PPTX
Natural Laws of Software Performance
Gibraltar Software
 
PDF
Boosting spark performance: An Overview of Techniques
Ahsan Javed Awan
 
PPT
Troubleshooting SQL Server
Stephen Rose
 
PDF
[ACNA2022] Hadoop Vectored IO_ your data just got faster!.pdf
MukundThakur22
 
PDF
Hadoop bank
AMIT BHARTIYA
 
PDF
SQL on Hadoop benchmarks using TPC-DS query set
Kognitio
 
PDF
20180522 infra autoscaling_system
Kai Sasaki
 
PDF
Tech Talk - JPA and Query Optimization - publish
Gleydson Lima
 
PDF
Cse viii-advanced-computer-architectures-06cs81-solution
Shobha Kumar
 
PDF
Callgraph analysis
Roberto Agostino Vitillo
 
PPTX
Webinar | Building Apps with the Cassandra Python Driver
DataStax Academy
 
PDF
User-space Network Processing
Ryousei Takano
 
PPTX
An introduction to column store indexes and batch mode
Chris Adkin
 
PDF
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mydbops
 
PDF
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
NETWAYS
 
Maximizing Database Tuning in SAP SQL Anywhere
SAP Technology
 
SQL Server It Just Runs Faster
Bob Ward
 
Apache Spark 3.0: Overview of What’s New and Why Care
Databricks
 
The Practice of Presto & Alluxio in E-Commerce Big Data Platform
Alluxio, Inc.
 
Natural Laws of Software Performance
Gibraltar Software
 
Boosting spark performance: An Overview of Techniques
Ahsan Javed Awan
 
Troubleshooting SQL Server
Stephen Rose
 
[ACNA2022] Hadoop Vectored IO_ your data just got faster!.pdf
MukundThakur22
 
Hadoop bank
AMIT BHARTIYA
 
SQL on Hadoop benchmarks using TPC-DS query set
Kognitio
 
20180522 infra autoscaling_system
Kai Sasaki
 
Tech Talk - JPA and Query Optimization - publish
Gleydson Lima
 
Cse viii-advanced-computer-architectures-06cs81-solution
Shobha Kumar
 
Callgraph analysis
Roberto Agostino Vitillo
 
Webinar | Building Apps with the Cassandra Python Driver
DataStax Academy
 
User-space Network Processing
Ryousei Takano
 
An introduction to column store indexes and batch mode
Chris Adkin
 
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mydbops
 
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
NETWAYS
 

More from PGConf APAC (20)

PDF
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC
 
PDF
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC
 
PDF
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC
 
PDF
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
PDF
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC
 
PDF
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC
 
PDF
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC
 
PDF
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC
 
PDF
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC
 
PDF
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC
 
PDF
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC
 
PDF
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC
 
PDF
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC
 
PDF
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC
 
PDF
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PDF
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC
 
PDF
Amazon (AWS) Aurora
PGConf APAC
 
PDF
Use Case: PostGIS and Agribotics
PGConf APAC
 
PDF
How to teach an elephant to rock'n'roll
PGConf APAC
 
PDF
PostgreSQL on Amazon RDS
PGConf APAC
 
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC
 
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC
 
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC
 
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC
 
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC
 
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC
 
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC
 
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC
 
Amazon (AWS) Aurora
PGConf APAC
 
Use Case: PostGIS and Agribotics
PGConf APAC
 
How to teach an elephant to rock'n'roll
PGConf APAC
 
PostgreSQL on Amazon RDS
PGConf APAC
 

Recently uploaded (20)

PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Architecture of the Future (09152021)
EdwardMeyman
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Architecture of the Future (09152021)
EdwardMeyman
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Software Development Company | KodekX
KodekX
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 

PostgreSQL 9.6 Performance-Scalability Improvements

  • 1. © 2013 EDB All rights reserved. 1 Scalability And Performance Improvements In PostgreSQL 9.6 • Dilip Kumar | 2016.03.17 PgDay Asia Singapore
  • 2. Who am I ? Dilip Kumar  Currently working at EnterpriseDB  Have worked to develop various features on PostgreSQL (for internal projects) as well as on other In-House DB at Huawei.  I have also contributed patches to community.  Holds around 14 patents in my name in various DB technologies.  I have presented a paper in PgCon 2015
  • 3. 3  Journey From 9.1 to 9.5  What’s In 9.6 ?  MVCC Scalability Improvement  Clog Scalability  Bulk Load Scalability  Parallel Query  Sorting Improvement  Hash Lock Improvement  Index Only Scan with partial Index  Partial Sort  Cache the Snapshot  Buffer Header Spin Lock Contents
  • 5. Whats’s In 9.6 ? ProcArray Lock Contention Solved : Commited Parallel Sequence Scan : Commited Parallel NLJ and HJ : Commited Clog Control Lock Issue : In Progress Bulk Load Scalability : In Progress Buffer Header Lock Issue : In progress Hash Header Lock Contention : In Progress Sorting Improvement using Quick Sort : In Progress Checkpoint Continuous Flushing : In Progress Index Only Scan with partial Index : In Progress Caching the Snapshot : In Progress Partial Sort : In Progress
  • 6. MVCC Scalability Improvement 6 ProcArrayLock:  Was the major contention point reported in 9.5 and blocking Read write workload to scale beyond 30 cores in TPCC.  With Pgbench also After 30 cores scalability was not linear. 1 8 16 32 64 128 0 5000 10000 15000 20000 25000 30000 pgbench -M prepared Median Of 30 mins of Runs Syncrhronous Commit=On Head Clients TPS
  • 7. MVCC Scalability Improvement  Many Solutions were tried to overcome this problem, like CSN snapshot, Incremental Snapshot.  Finally Group clear Xid in ProcArrayEnd Transaction Successfully got committed for 9.6 version and Scaling is almost linear upto 64 Clients in 64 thread machine. 1 8 16 32 64 128 0 5000 10000 15000 20000 25000 30000 35000 pgbench-MpreparedMedianOf30minsofRunsSyncrhronousCommit=On Head Patch Clients TPS
  • 8. Clog Control Improvement 8 Clog Control Lock:  Afer reducing ProcArrayLock contenton CLogControlLock become next    visible contenton Point.  Contenton is mainly due to two reasons, one is that while writng the transacton status in CLOG, it acquires EXCLUSIVE CLogControlLock which    contends with every other transacton which tries to access the CLOG for    checking transacton status and to reduce it. Second contenton is due to    the reason that when the CLOG page is not found in CLOG bufers, it needs        to acquire CLogControlLock in Exclusive mode which again contends with    shared lockers which tries to access the transacton status.  Soluton Used for ClogControl Lock is Similar to the ProcArray Group Clear XID.
  • 10. Bulk Load Scalability Relation Extension Lock:  Currently Relation extension Lock is becoming bottleneck while extending the relation in parallel.  Both COPY and INSERT are Suffering From the same problem.  Recently we are working on this various solutions are tries, and Currently this is in Progress. (Lock Free Extension, Extend In multiple Blocks with User Knob, Group Extend the Relation, Extend In multiple of Lock Waiters).
  • 11. Bulk Load Scalability 1 2 4 8 16 32 64 0 200 400 600 800 1000 1200 COPY10000 Record (4Bytes) Data Fits in Shared Buffers Base Patch Clients TPS 1 2 4 8 16 32 64 0 50 100 150 200 250 300 INSERT 1000 Records (1K) data doesn't fits In Shared Buffers Base Patch Clients TPS
  • 12. Parallel Query 12  Parallel Query is a Great Win for 9.6 this allows to run single query in Parallel in multiple workers.  Parallel Sequence Scan and Parallel Join are already Committed and some are in progress like Parallel Index Scan, Parallel Aggregate.  Parallel Sequence Scan and Parallel Join has shown Great Improvement for Single Query.
  • 13. Parallel Query 13 Q3 Q4 Q5 Q7 Q8 0 2000 4000 6000 8000 10000 12000 14000 TPC-H Query with scale factor=5 Time in ms
  • 14. Sorting Improvement Using quicksort for every external sort: This usage a quick sort instead of Replacement Selection. Replacing with quick sort which is cache conscious algorithm, that improves the performance significantly.
  • 15. Sorting Improvement 1.7 3.5 7 14 0 50000 100000 150000 200000 250000 300000 350000 400000 Time Calculation for Using Quick Sort For All External Sort Work_mem= DEFAULT (4mb). Head Patch Data Size (GB) Time in (ms)
  • 16. Hash Header Lock Contention Hash Header mutex Contention:  Postgres internal hash table is used for many key Operation.  Heavy Weight Locks are managed in hash Tables.  Buffer pool is managed by hash Tables.  But whenever hash needs to allocate element from free list or release to free list, there is one common lock and that become main contention point.  As part of this work this is converted to partitioned level freelist now each partition have separate freelist and separate Locks.  Freelist elements can be shared across partitions.
  • 17. Hash Header Lock Contention z 64 128 0 50000 100000 150000 200000 250000 300000 350000 PgBench: Scale Factor 300 Shared Buffer 512MB Head Patch Cleints TPS
  • 18. Index only scan with partial index What is Partial Index ?  A partial index is an index built over a subset of a table; the subset is defined by a conditional expression (called the predicate of the partial index). The index contains entries for only those table rows that satisfy the predicate.  A major motivation for partial indexes is to avoid indexing common values. Since a query searching for a common value (one that accounts for more than a few percent of all the table rows) will not use the index anyway, there is no point in keeping those rows in the index at all. This reduces the size of the index, which will speed up queries that do use the index.
  • 19. Index only scan with partial index Problem:  Currently partial indexes end up not using index only scans in most of the cases.  unless you include all columns from the index predicate to the index, the planner will decide index only scans are not possible.  Adding those columns which are not needed at runtime, will only increase the index size. Solution:  Select the index only scan, if there are some key which are not really required at runtime.
  • 20. Partial Sort  In PostgreSQL If all the sort keys are part of the index then index scan will be selected for sorting.  Otherwise scan all tuple from heap and Sort them completely.  As per this patch, mix both methods:  get results from index in order which partially meets our requirements  do rest of work from heap.
  • 21. Cache The Snapshot  As per this Improvement whenever backend take a snapshot its stored in a shared cache.  Whenever any transaction is getting commited, saved snapshot will be marked Invalid.  When there is mix load of read and write that time if b/w multiple read there is no write transaction, snapshot can be reuse.  When write transaction Invalidate the snapshot, First transaction taking the snapshot will recalculate and update the cached snapshot
  • 22. Cache The Snapshot 64 88 128 256 0 5000 10000 15000 20000 25000 30000 35000 40000 Pgbench: Scale factor 300 Shared Buff=8GB BASE ONLY CLOG CHANGES CLOG + SAVE SNAPSHOT Clients TPS
  • 23. Buffer Header lock Improvement Convert Pin/Unpin Spin Lock to Atomic Operation:  Spin Lock inside the Pin and Unpin buffer is also one of the bottleneck, While testing scalability in Big NUMA Machines.  As per this patch Spin lock is converted to Atomic Operation and Increasing/decreasing reference count is done using just one ATOMIC operations.  Other Operation which need to do more work other than just updating state variable, that takes a Lock and Lock is using atomic operation.
  • 24. Buffer Header lock Improvement 1 8 16 32 64 0 100000 200000 300000 400000 500000 600000 700000 800000 pgbench read only test -M prepared S.F=1000 Shared Buffer=8GB Head Pached Clients TPS