PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark...

50
PostgreSQL Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c 2ndQuadrant, Ltd. SF PGDAY 2015 1 / 50

Transcript of PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark...

Page 1: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

PostgreSQL PerformancePresentation

9.5devel Edition

Mark WongConsultant, 2ndQuadrant &Contributor, PostgreSQL10 March 2015

c© 2ndQuadrant, Ltd. SF PGDAY 2015 1 / 50

Page 2: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Agenda• Background• Patches to test• The test suite• Compare results between difference

versions of PostgreSQL

c© 2ndQuadrant, Ltd. SF PGDAY 2015 2 / 50

Page 3: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

BackgroundThis presentation made possible by the AXLE1

project:• Advanced Analytics for Extremely Large

European Databases• “The objectives of the AXLE project are to

greatly improve the speed and quality ofdecision making on real-world data sets.AXLE aims to make these improvementsgenerally available through high qualityopen source implementations via thePostgreSQL and Orange products.”

1http://axleproject.eu/c© 2ndQuadrant, Ltd. SF PGDAY 2015 3 / 50

Page 4: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

A few AXLE details• Aspects of the project include:

− Scalability engineering—autopartitioning,compression

− Security, privacy, and audit techniques− Visual analytics− Advanced architectures for hardware and

software• Partners

− 2ndQuadrant− Barcelona Supercomputing Center− PortaVita− University of Manchester− University of Ljubljana

c© 2ndQuadrant, Ltd. SF PGDAY 2015 4 / 50

Page 5: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

The Patches

c© 2ndQuadrant, Ltd. SF PGDAY 2015 5 / 50

Page 6: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Changes EvaluatedPatches tested in this presentation are intendedto help the performance of large databasesystems:• New feature already committed:

− BRIN indexes• Scalability related improvements still under

review:− Concurrent hash table for buffer lookups− Wait free LWLocks

• Light Weight Locks• Currently provides mutually exclusive access to shared

memory by using spin locks or semaphores

c© 2ndQuadrant, Ltd. SF PGDAY 2015 6 / 50

Page 7: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

BRIN• Block Range indexes are a

new-to-PostgreSQL type of index• Authored by Alvaro Herrera @ 2ndQuadrant• Originally proposed as MinMax indexes2

• Intended for Big Data systems• Similar to Oracle Exadata ”storage indexes”

2http://goo.gl/yUwav9c© 2ndQuadrant, Ltd. SF PGDAY 2015 7 / 50

Page 8: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Why use BRIN?• Much smaller and less costly to maintain

compared to B-tree indexes• Allowing use of an index on a large table

that would previously been impractical usingB-tree indexes without horizontalpartitioning

c© 2ndQuadrant, Ltd. SF PGDAY 2015 8 / 50

Page 9: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

When to use BRIN?Best case scenario:• On a column that has a linear sort order• Example:

− A table recording sales orders− Use BRIN on the DATE column representing

when an order was placed

c© 2ndQuadrant, Ltd. SF PGDAY 2015 9 / 50

Page 10: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Index Structure Comparison

B-tree

BRIN

c© 2ndQuadrant, Ltd. SF PGDAY 2015 10 / 50

Page 11: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Concurrent Hash Table• Authored by Robert Haas @ EnterpriseDB 3

• Improve concurrency accessing the buffertable between simultaneously executingqueries− Lookups performed using memory barriers

instead of locks− Inserts and deletes (to the buffer table) use

atomic operations instead of locks

3http://goo.gl/9naq5cc© 2ndQuadrant, Ltd. SF PGDAY 2015 11 / 50

Page 12: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Series of changes aroundLWLocks• Related to wait free LW SHARED acquisition• Authored by Andres Freund @

2ndQuadrant 4

• Use atomic compare-and-exchange toacquire LWLock

• Lockless clock sweep buffer eviction• Reduce false sharing by increase padding

between LWLocks

4http://goo.gl/8bf3CNc© 2ndQuadrant, Ltd. SF PGDAY 2015 12 / 50

Page 13: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

False sharing visual from Intel

c© 2ndQuadrant, Ltd. SF PGDAY 2015 13 / 50

Page 14: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

The Hardware

c© 2ndQuadrant, Ltd. SF PGDAY 2015 14 / 50

Page 15: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Environment: BarcelonaBarcelona Supercomputing Center• OS: SUSE Linux Enterprise Server 11 SP3• Hardware

− 2 x Intel Xeon E5-2670, Sandy Bridge DP,2.6Ghz 8 Core/16 Threads, 3.3Ghz Turbo,8GT/s QPI, 20MB cache, 115W

− 256 GB RAM− 120TB storage connected via 10GigE

c© 2ndQuadrant, Ltd. SF PGDAY 2015 15 / 50

Page 16: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Environment: ManchesterUniversity of Manchester• OS: Ubuntu 12.04.4 LTS• Hardware

− 4 x Intel Xeon E54620 Eight Core 2.2GHzProcessors, 8 Core/32 Threads

− 256 GB RAM− 10TB storage, 17 x 600GB SSD RAID-0

c© 2ndQuadrant, Ltd. SF PGDAY 2015 16 / 50

Page 17: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

The Test

c© 2ndQuadrant, Ltd. SF PGDAY 2015 17 / 50

Page 18: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

TPC BenchmarkTMH• http://www.tpc.org/tpch/• A suite of business oriented ad-hoc queries

against a parts supplier data warehouse• Composed of three tests:

− Load Test− Power Test− Throughput Test

• Use smaller parts of the TPC-H to performmicrobenchmarks against BRIN indexes

c© 2ndQuadrant, Ltd. SF PGDAY 2015 18 / 50

Page 19: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

TPC-H Load TestMeasure the time to load data into 8 tables andbuild all indexes

c© 2ndQuadrant, Ltd. SF PGDAY 2015 19 / 50

Page 20: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

TPC-H Load Test notes• Load of each table starts simultaneously• All indexes created simultaneously as soon

as table is loaded• Expectation is that the combination of BRIN

indexes and the scalability patches willreduce the index creation portion of the test

c© 2ndQuadrant, Ltd. SF PGDAY 2015 20 / 50

Page 21: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

TPC-H Power TestRaw query execution for a single user:• 22 different queries executed consecutively• Order of queries randomized per test• Scored by taking the geometric mean of the

execution time of each query• Expectation is that the use of BRIN indexes

will be comparable to the use of B-treeindexes

c© 2ndQuadrant, Ltd. SF PGDAY 2015 21 / 50

Page 22: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

A sample of PowerTest queries

c© 2ndQuadrant, Ltd. SF PGDAY 2015 22 / 50

Page 23: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

TPC-H Query 14

This query monitors the market response to apromotion such as TV advertisements or aspecial campaign.select

100.00 ∗ sum( casewhen p type l i k e ’PROMO%’

then l e x tendedp r i ce ∗ (1 − l d i s c o u n t )else 0

end ) / sum( l ex tendedp r i ce ∗ (1 − l d i s c o u n t ) ) as promo revenuefrom

l i ne i t em ,pa r t

wherel p a r t k e y = p par tkeyand l s h i p d a t e >= date ’1994−10−01 ’and l s h i p d a t e < cast ( date ’1994−10−01 ’ + i n te rva l ’ 1 month ’ as date ) ;

c© 2ndQuadrant, Ltd. SF PGDAY 2015 23 / 50

Page 24: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

TPC-H Query 12This query determines whether selecting less expensivemodes of shipping is negatively affecting thecritical-priority orders by causing more parts to bereceived by customers after the committed date.select l shipmode ,

sum( case when o o r d e r p r i o r i t y = ’1−URGENT ’or o o r d e r p r i o r i t y = ’2−HIGH ’

then 1else 0

end ) as h i g h l i n e c o u n t ,sum( case when o o r d e r p r i o r i t y <> ’1−URGENT ’

and o o r d e r p r i o r i t y <> ’2−HIGH ’then 1else 0

end ) as l o w l i n e c o u n tfrom orders , l i n e i t e mwhere o orderkey = l o rde r key

and l shipmode in ( ’FOB ’ , ’TRUCK ’ )and l commitdate < l r e c e i p t d a t eand l s h i p d a t e < l commitdateand l r e c e i p t d a t e >= date ’1994−01−01 ’and l r e c e i p t d a t e < date ’1994−01−01 ’ + i n te rva l ’ 1 year ’

group by l shipmodeorder by l shipmode ;

c© 2ndQuadrant, Ltd. SF PGDAY 2015 24 / 50

Page 25: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

TPC-H Throughput TestMeasure the system’s ability to execute queriesfrom multiple users simultaneously:• Execute multiple Power Tests at the same

time• Each instance of a Power Test referred to

as a stream• Scored as the ratio of the total number of

queries executed over the length of the test• Expectation is that we can run more

streams and execute queries faster

c© 2ndQuadrant, Ltd. SF PGDAY 2015 25 / 50

Page 26: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Initial BRIN TestsBut first design microbenchmarks around BRINin case their use is masked in the TPC-Hworkload:• Loading a table• Creating an index• Maintenance on growing a table• Measure against the lineitem table, 6

million rows per scale factor

c© 2ndQuadrant, Ltd. SF PGDAY 2015 26 / 50

Page 27: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Load tables with BRIN1. Load data into the table when there are no

indexes2. Load data into the table when there is only

a single B-tree index on a DATE column3. Repeat after replaces the B-tree index with

a BRIN index

c© 2ndQuadrant, Ltd. SF PGDAY 2015 27 / 50

Page 28: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Create a BRIN index1. Load data into the table when there are no

indexes2. Create a B-tree index on the same DATE

column3. Start over and repeat with a BRIN index

c© 2ndQuadrant, Ltd. SF PGDAY 2015 28 / 50

Page 29: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

BRIN maintenance overhead1. Create table without any indexes2. Time the load of 8GB of data repeatedly

until table size reaches 1TB3. Start over and repeat with a B-tree index on

the same DATE column4. Start over and repeat with a BRIN index on

the same DATE column

c© 2ndQuadrant, Ltd. SF PGDAY 2015 29 / 50

Page 30: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

The Results

c© 2ndQuadrant, Ltd. SF PGDAY 2015 30 / 50

Page 31: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

BRINmicrobenchmarks

c© 2ndQuadrant, Ltd. SF PGDAY 2015 31 / 50

Page 32: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

BRIN index increases load time by 10% vs 84%B-tree index

c© 2ndQuadrant, Ltd. SF PGDAY 2015 32 / 50

Page 33: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Creating a BRIN index is 81% faster thancreating a B-tree index

c© 2ndQuadrant, Ltd. SF PGDAY 2015 33 / 50

Page 34: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

BRIN overhead a constant 10% vs B-treeoverhead growing slightly as the table grows

c© 2ndQuadrant, Ltd. SF PGDAY 2015 34 / 50

Page 35: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Impact on TPC-H Tests

c© 2ndQuadrant, Ltd. SF PGDAY 2015 35 / 50

Page 36: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Load Test at 30GB• B-tree

− 28 B-tree indexes across 8 tables− Total build time 46 minutes

• BRIN− 29 total indexes across 8 tables

• 21 B-tree• 8 BRIN

− Total build time 34 minutes• Use of BRIN indexes reduces load time by

26%

c© 2ndQuadrant, Ltd. SF PGDAY 2015 36 / 50

Page 37: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Power Test notes at 30GB• 15 of 22 queries to use BRIN index• Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q10, Q11,

Q14, Q15, Q16, Q19, Q20, Q21

c© 2ndQuadrant, Ltd. SF PGDAY 2015 37 / 50

Page 38: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Power Test results at 30GB

c© 2ndQuadrant, Ltd. SF PGDAY 2015 38 / 50

Page 39: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Power Test results at 100GB

c© 2ndQuadrant, Ltd. SF PGDAY 2015 39 / 50

Page 40: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Summary of Power Test• At 30GB

− Overall score 2145 (B-tree) vs 1806 (BRIN)− Use of BRIN indexes within 15% of the B-tree

score• At 100Gb

− Overall score 1418 (B-tree) vs 1815 (BRIN)− Use of BRIN indexes improves score by 28%

c© 2ndQuadrant, Ltd. SF PGDAY 2015 40 / 50

Page 41: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Index Comparison at 100GB5

5statement timeout set to 3000 seconds for no indexesc© 2ndQuadrant, Ltd. SF PGDAY 2015 41 / 50

Page 42: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Summary of Power Test withBRIN vs No indexes• At 100Gb

− Overall score 10616 (no indexes) vs 1815 BRIN− Use of BRIN indexes improves score by over

71%

6Should be lower without statement timeout setc© 2ndQuadrant, Ltd. SF PGDAY 2015 42 / 50

Page 43: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

BRIN objectives met• BRIN index size is 612 times smaller:

1.7MB vs 1GB B-tree index on 8 GB of data• BRIN overhead, maintenance, size all

improved over B-tree• Performance of BRIN a little slower than

B-tree performance

c© 2ndQuadrant, Ltd. SF PGDAY 2015 43 / 50

Page 44: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Scalability results

c© 2ndQuadrant, Ltd. SF PGDAY 2015 44 / 50

Page 45: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Scalability effect on Load TestAdditional patches 20% improved over 9.2, 14%over development branch:

c© 2ndQuadrant, Ltd. SF PGDAY 2015 45 / 50

Page 46: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Scaling on a 2-socket system

c© 2ndQuadrant, Ltd. SF PGDAY 2015 46 / 50

Page 47: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Scaling on a 4-socket system

c© 2ndQuadrant, Ltd. SF PGDAY 2015 47 / 50

Page 48: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Power Test History

c© 2ndQuadrant, Ltd. SF PGDAY 2015 48 / 50

Page 49: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

Thank you!

c© 2ndQuadrant, Ltd. SF PGDAY 2015 49 / 50

Page 50: PostgreSQL Performance Presentation - WordPress.com Performance Presentation 9.5devel Edition Mark Wong Consultant, 2ndQuadrant & Contributor, PostgreSQL 10 March 2015 c …

The research leading to these results hasreceived funding from the European Union’s

Seventh Framework Programme(FP7/2007-2013) under grant agreement n◦

318633

c© 2ndQuadrant, Ltd. SF PGDAY 2015 50 / 50