+ All Categories
Home > Documents > Andres Freund PostgreSQL Developer & Committer Citus Data...

Andres Freund PostgreSQL Developer & Committer Citus Data...

Date post: 15-Oct-2020
Category:
Upload: others
View: 14 times
Download: 0 times
Share this document with a friend
26
Scalability pgday.it 2015 Andres Freund PostgreSQL Developer & Committer Citus Data – citusdata.com - @citusdata
Transcript
Page 1: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Scalabilitypgday.it 2015

Andres FreundPostgreSQL Developer & Committer

Citus Data – citusdata.com - @citusdata

Page 2: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Scalability

“Scalability is the capability of a system, network, or process to handle a growing amount of work, or

its potential to be enlarged in order to accommodate that growth”

Wikipedia

Page 3: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

1 4 8 16 32 48 64 96 1280

50000

100000

150000

200000

250000

300000

350000

400000

450000

500000

a

b

# clients

TP

S

Page 4: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Vertical

Lenovo x3950-x6

Page 5: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Horizontal

HP DL60 * 5

Page 6: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Vertically Scalable Systems

● Easier to use● Easier to maintain● Stronger Consistency

– Nearly all horizontally scalable systems are in some form eventually consistent

– some problems are very hard to solve with lower consistency models

● Often faster than horizontally scalable system● But there's definitely an upper limit

Page 7: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

When not to scale vertically

● cost(horizontal) < cost(vertical)● bigger hardware, even bigger hardware cost● latency across the world is a critical issue● current/expected scale bigger than vertically

achievable

Page 8: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

When to scale horizontally

● Little/No shared state– webservers

– cache servers

– computations

● Shared state changes infrequently● Consistency is not paramount● Global latency is an issue

Page 9: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Mix & Mash

● Web-Servers: Horizontally● Caching Infrastructure: Horizontally● Critical Data: Vertical● Bulk Data: Vertical if possible, horizontal

otherwise

Page 10: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

WHY ARE YOU TELLING ME THIS?!

Page 11: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

PostgreSQL and Vertical Scalability

● Used to be very good – ca. 2003● Important fixes have been made since 2009

– Locking tables scales very good (9.2)

– Low Level Locks scale better (9.5)

– Cache Management scales a bit better (9.5)

– Parallel Short Read/Write Xacts scale better (9.6)

● Very good for many concurrent workloads● Several important problems remain

Page 12: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

1 2 4 8 16 32 64 96 128 196 2560

100000

200000

300000

400000

500000

600000

plain

# clients

TP

S

● readonly pgbench scale 300● EC2 m4.8xlarge - 2 x E5-2676 (2 x 10 cores/20 threads)● master @ aa6b2e6● fastpath disabled in code

Page 13: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Acquiring a Heavyweight Lock

Free Lock

Free Lock

Free Lock

Free Lock

Free Lock

Free Lock

Free Lock

Shared Lock Table

Lock Lock Table

Lock by #7Backend #7

Page 14: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Heavyweight Lock - Fastpath

Backend #7

Conflict ing

Lock

Lock by #7

Page 15: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Heavyweight Lock – Slow Path

Backend #7

Conflict ing

Lock

Backend #1

Lock by #1

Backend #2

Backend #3

FFF

FFF

L #7

Page 16: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

1 2 4 8 16 32 64 96 128 196 2560

100000

200000

300000

400000

500000

600000

fastpath

plain

# clients

TP

S

● readonly pgbench scale 300● EC2 m4.8xlarge - 2 x E5-2676 (2 x 10 cores/20 threads)● master @ aa6b2e6● fastpath disabled in code

Page 17: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

LWLock scalability

# perf top ­az     89.53%  postgres  postgres  [.] s_lock      2.53%  postgres  postgres  [.] LWLockAcquire      1.79%  postgres  postgres  [.] LWLockRelease      0.63%  postgres  postgres  [.] hash_search_..._value

Page 18: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

1 4 8 16 32 48 64 96 1280

50000

100000

150000

200000

250000

300000

350000

400000

old

# clients

TP

S

● readonly pgbench● 4xE5-4620● scale 100

Page 19: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

LWLockAcquire(LWLock *l, LWLockMode mode?){  retry:    SpinLockAcquire(&lock­>mutex);        if (mode == LW_SHARED)    {        if (!lock­>exclusive)        {            lock­>shared++;        }        else        {            QueueSelf(l);            SpinLockRelease(&lock­>mutex);            WaitForRelease(l);            goto retry;        }       }    ...      SpinLockRelease(&lock­>mutex);}

Page 20: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

1 4 8 16 32 48 64 96 1280

50000

100000

150000

200000

250000

300000

350000

400000

450000

500000

old

rlwock

# clients

TP

S

● readonly pgbench● 4xE5-4620● scale 100

Page 21: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Not Fixed – Query Parallelism

● Each query only use one core– fine for transactional workloads

– horrible for analytics workloads

● Initial parallelism Infrastructure in 9.5 u. 9.6● First parallel queries hopefully in 9.6

– will take a while to work for many types of query constructs

Page 22: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Further Scalability Issues

● Expensive Snapshot Computation– Problematic: High QPS (combined read & write) workloads,

many clients

– Solution: connection pooler

● Extension Lock– Problematic: Parallel bulk write workloads to single table

– Workaround: Uh.

– Fix hopefully in 9.6

● Buffer Replacement Complexity & Accuracy– Problematic: Larger than memory workloads

– Solution: Try higher or lower shared_buffers

Page 23: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Extension Lock Scalability

1 2 4 8 16 32 48 64 96 128 196 256 5120

50

100

150

200

250

patched

unpatched

clients

CO

PY

com

ma

nd

s/s

ec

● pgbench of COPY commands to the same table (1.7MB each)● 4xE5-4620 (32 cores, 64 threads)● 48 GB shared memory, 256 GB in total

Page 24: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Horizontal Scalability & Postgres

● Manually shard● Slony & Londiste (uh, forever)● Streaming Replication / Hot Standby (9.0)

– scale reads

● Logical Decoding (9.4)– coordinate systems

– basis for logical replication solutions

● BDR & UDR (9.4)● Foreign Data Wrappers (9.1, 9.5)● postgres-xc / postgres-xl● pg_shard

Page 25: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Scaling Analytics Workloads

● Commercial Forks of Postgres:– Redshift

– Greenplum

– CitusDB

– …

Page 26: Andres Freund PostgreSQL Developer & Committer Citus Data ...anarazel.de/talks/pgday-it-2015-10-23/scalability.pdf · 0.63% postgres postgres [.] hash_search_..._value. 1 4 8 16 32

Help!

● Contribute Problems– detailed descriptions of things being to slow

– detailed descriptions of things you'd like to do

● Contribute Solutions– fix things that are too slow

● Contribute Contributions– help others to contribute


Recommended