Measuring and Reducing Postgres Transaction Latency Fabien Coelho - - PowerPoint PPT Presentation

measuring and reducing postgres transaction latency
SMART_READER_LITE
LIVE PREVIEW

Measuring and Reducing Postgres Transaction Latency Fabien Coelho - - PowerPoint PPT Presentation

Measuring and Reducing Postgres Transaction Latency Fabien Coelho MINES ParisTech, PSL Research University pgDay Paris March 23, 2017 1 / 40 Postgres Latency Talk Outline 1 Introduction Subject Typical Web Application Transaction


slide-1
SLIDE 1

Measuring and Reducing Postgres Transaction Latency

Fabien Coelho

MINES ParisTech, PSL Research University

pgDay Paris – March 23, 2017

1 / 40

slide-2
SLIDE 2

Postgres Latency Talk Outline

2 Performance Comparisons Two Connection Costs Latency Pitfalls Benchmarking with Rate and Limit Three Storage Options Two Protocol Impacts Four Query Combination Tricks Reducting Server Distance Performance Scalability Miscellaneous Settings 1 Introduction Subject Typical Web Application Transaction Performance Definitions pgbench 3 Conclusion Latency and Throughput Wrap-Up Lessons Learned Contributions to Postgres

2 / 40

slide-3
SLIDE 3

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Subject

Small OLTP OnLine Transaction Processing CRUD queries ... WHERE pk=? data fit in shared buffers small, few GB RW, RO pgbench builtins Focus and Motivation performance with emphasis on latency interactive web app

3 / 40

slide-4
SLIDE 4

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Subject

Small OLTP OnLine Transaction Processing CRUD queries ... WHERE pk=? data fit in shared buffers small, few GB RW, RO pgbench builtins Focus and Motivation performance with emphasis on latency interactive web app

3 / 40

slide-5
SLIDE 5

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Subject

Small OLTP OnLine Transaction Processing CRUD queries ... WHERE pk=? data fit in shared buffers small, few GB RW, RO pgbench builtins Focus and Motivation performance with emphasis on latency interactive web app experiments & measures do not assume!

3 / 40

slide-6
SLIDE 6

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Subject

Small OLTP OnLine Transaction Processing CRUD queries ... WHERE pk=? data fit in shared buffers small, few GB RW, RO pgbench builtins Focus and Motivation performance with emphasis on latency interactive web app experiments & measures do not assume! latency performance : RW ×63, RO ×219

3 / 40

slide-7
SLIDE 7

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Typical Web Application

3-Tier Architecture Client user acts on user-agent, sends to Server process request, database operations to Database stores and retrieves data

User Client Server Database

Database Operations Connection TCP/IP , SSL & AAA Request-Response cycles transfer, parse, plan, execute, transfer back

4 / 40

slide-8
SLIDE 8

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Typical Web Application

3-Tier Architecture Client user acts on user-agent, sends to Server process request, database operations to Database stores and retrieves data

User Client Server Database

Database Operations Connection TCP/IP , SSL & AAA Request-Response cycles transfer, parse, plan, execute, transfer back

4 / 40

slide-9
SLIDE 9

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Transaction Performance

Definitions time & operations Throughput operations per time unit tx/s usual approach, load measured in tps Latency time for one operation ms/tx must fit application requirements Comments correlated and contradictory max vs enough and vice-versa sensitive to many settings net, soft & hard throughput bottleneck & latency additivity

5 / 40

slide-10
SLIDE 10

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Transaction Performance

Definitions time & operations Throughput operations per time unit tx/s usual approach, load measured in tps Latency time for one operation ms/tx must fit application requirements Comments correlated and contradictory max vs enough and vice-versa sensitive to many settings net, soft & hard throughput bottleneck & latency additivity

5 / 40

slide-11
SLIDE 11

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Transaction Performance

Definitions time & operations Throughput operations per time unit tx/s usual approach, load measured in tps Latency time for one operation ms/tx must fit application requirements Comments correlated and contradictory max vs enough and vice-versa sensitive to many settings net, soft & hard throughput bottleneck & latency additivity

5 / 40

slide-12
SLIDE 12

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Transaction Performance

Definitions time & operations Throughput operations per time unit tx/s usual approach, load measured in tps Latency time for one operation ms/tx must fit application requirements Comments correlated and contradictory max vs enough and vice-versa sensitive to many settings net, soft & hard throughput bottleneck & latency additivity

5 / 40

slide-13
SLIDE 13

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Transaction Performance

Definitions time & operations Throughput operations per time unit tx/s usual approach, load measured in tps Latency time for one operation ms/tx must fit application requirements Comments correlated and contradictory max vs enough and vice-versa sensitive to many settings net, soft & hard throughput bottleneck & latency additivity deep voodoo!

5 / 40

slide-14
SLIDE 14

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Postgres Performance Swiss Army Knife pgbench

Available Features input SQL-like scripts with minimal client-side language

  • ptions time to run, prepared, reconnections, . . .

parallelism threads, clients, asynchronous calls

  • utput statistical performance data

Caveats long enough warm-up, checkpoint and vacuum several times reproducibility pedal-to-the-metal max speed test not representative

6 / 40

slide-15
SLIDE 15

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Postgres Performance Swiss Army Knife pgbench

Available Features input SQL-like scripts with minimal client-side language

  • ptions time to run, prepared, reconnections, . . .

parallelism threads, clients, asynchronous calls

  • utput statistical performance data

Caveats long enough warm-up, checkpoint and vacuum several times reproducibility pedal-to-the-metal max speed test not representative

6 / 40

slide-16
SLIDE 16

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Default TPC-B-like Transaction pgbench -b tcpb-like

Pattern 3 updates 1 insert 1 select TPC-B-like banking transaction

  • - random ids and amount

\set aid random(1, 100000 * :scale) \set bid random(1, 1 * :scale) \set tid random(1, 10 * :scale) \set delta random(-5000, 5000)

  • - actual transaction

BEGIN; UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid; SELECT abalance FROM pgbench accounts WHERE aid = :aid; UPDATE pgbench tellers SET tbalance = tbalance + :delta WHERE tid = :tid; UPDATE pgbench branches SET bbalance = bbalance + :delta WHERE bid = :bid; INSERT INTO pgbench history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT TIMESTAMP); END;

7 / 40

slide-17
SLIDE 17

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Default TPC-B-like Transaction pgbench -b tcpb-like

Pattern 3 updates 1 insert 1 select TPC-B-like banking transaction

  • - random ids and amount

\set aid random(1, 100000 * :scale) \set bid random(1, 1 * :scale) \set tid random(1, 10 * :scale) \set delta random(-5000, 5000)

  • - actual transaction

BEGIN; UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid; SELECT abalance FROM pgbench accounts WHERE aid = :aid; UPDATE pgbench tellers SET tbalance = tbalance + :delta WHERE tid = :tid; UPDATE pgbench branches SET bbalance = bbalance + :delta WHERE bid = :bid; INSERT INTO pgbench history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT TIMESTAMP); END;

7 / 40

slide-18
SLIDE 18

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Two Connection Costs

8 / 40

slide-19
SLIDE 19

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Connection Costs pgbench -C

pgbench

Client LAN

postgres

Server

Client 8 cores, 16 GB LAN 1 Gbps Server 16 cores, 32 GB, HDD Initialization

Postgres 9.6.1

pgbench -i -s 100 1.5 GB

9 / 40

slide-20
SLIDE 20

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Connection Costs pgbench -C

pgbench

Client LAN

postgres

Server

Client 8 cores, 16 GB LAN 1 Gbps Server 16 cores, 32 GB, HDD Initialization

Postgres 9.6.1

pgbench -i -s 100 1.5 GB

9 / 40

slide-21
SLIDE 21

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Connection Costs pgbench -C

pgbench

Client LAN

postgres

Server

Client 8 cores, 16 GB LAN 1 Gbps Server 16 cores, 32 GB, HDD Initialization and Benchmarks

Postgres 9.6.1

pgbench -i -s 100 1.5 GB pgbench -T 2000 -C "host=server sslmode=require" 36.1 tps

9 / 40

slide-22
SLIDE 22

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Connection Costs pgbench -C

pgbench

Client LAN

postgres

Server

Client 8 cores, 16 GB LAN 1 Gbps Server 16 cores, 32 GB, HDD Initialization and Benchmarks

Postgres 9.6.1

pgbench -i -s 100 1.5 GB pgbench -T 2000 -C "host=server sslmode=require" 36.1 tps pgbench -T 2000 -C "host=server sslmode=disable" 56.4 tps

9 / 40

slide-23
SLIDE 23

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Connection Costs pgbench -C

pgbench

Client LAN

postgres

Server

Client 8 cores, 16 GB LAN 1 Gbps Server 16 cores, 32 GB, HDD Initialization and Benchmarks

Postgres 9.6.1

pgbench -i -s 100 1.5 GB pgbench -T 2000 -C "host=server sslmode=require" 36.1 tps pgbench -T 2000 -C "host=server sslmode=disable" 56.4 tps pgbench -T 2000 "host=server sslmode=disable" 105.4 tps

9 / 40

slide-24
SLIDE 24

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Connection Costs pgbench -C

pgbench

Client LAN

postgres

Server

Client 8 cores, 16 GB LAN 1 Gbps Server 16 cores, 32 GB, HDD Initialization and Benchmarks

Postgres 9.6.1

pgbench -i -s 100 1.5 GB pgbench -T 2000 -C "host=server sslmode=require" 36.1 tps pgbench -T 2000 -C "host=server sslmode=disable" 56.4 tps pgbench -T 2000 "host=server sslmode=disable" 105.4 tps connection AAA 8.2 ms SSL negociation 10.0 ms transfers and transactions 9.5 ms

9 / 40

slide-25
SLIDE 25

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Latency Pitfalls

10 / 40

slide-26
SLIDE 26

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 pgbench -j 4 -c 8

Version 9.5.5 throughput 329.4 tps average latency 24.3 ms Version 9.6.1 throughput 326.4 tps average latency 24.4 ms

11 / 40

slide-27
SLIDE 27

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 pgbench -j 4 -c 8

Version 9.5.5 throughput 329.4 tps average latency 24.3 ms

100 200 300 400 500 600 1 2 3 4 5 thousand transactions transaction latency in seconds

Version 9.6.1 throughput 326.4 tps average latency 24.4 ms

100 200 300 400 500 600 1 2 3 4 5 thousand transactions transaction latency in seconds

11 / 40

slide-28
SLIDE 28

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 pgbench -j 4 -c 8

Version 9.5.5 throughput 329.4 tps average latency 24.3 ms

100 200 300 400 500 600 1 2 3 4 5 thousand transactions transaction latency in seconds

latency std. dev. 79.5 ms Version 9.6.1 throughput 326.4 tps average latency 24.4 ms

100 200 300 400 500 600 1 2 3 4 5 thousand transactions transaction latency in seconds

latency std. dev. 20.3 ms

11 / 40

slide-29
SLIDE 29

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 Instant TPS

Version 9.5.5

100 200 300 400 500 500 1000 1500 2000 tps run time in seconds

Version 9.6.1

100 200 300 400 500 500 1000 1500 2000 tps run time in seconds

What is happening? transaction surges are absorbed in-memory + WAL then data are written disk checkpoint

12 / 40

slide-30
SLIDE 30

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 Instant TPS

Version 9.5.5

100 200 300 400 500 500 1000 1500 2000 tps run seconds sorted by tps

Version 9.6.1

100 200 300 400 500 500 1000 1500 2000 tps run seconds sorted by tps

What is happening? transaction surges are absorbed in-memory + WAL then data are written disk checkpoint

12 / 40

slide-31
SLIDE 31

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 Instant TPS

Version 9.5.5

100 200 300 400 500 500 1000 1500 2000 tps run seconds sorted by tps

Version 9.6.1

100 200 300 400 500 500 1000 1500 2000 tps run seconds sorted by tps

What is happening? Buy Now, Pay Later! transaction surges are absorbed in-memory + WAL then data are written disk checkpoint

12 / 40

slide-32
SLIDE 32

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 Checkpointing

Postgres 9.5 Checkpoint data writes spread over some time random I/O OS choose when to actually write 30s delay on Linux until fsync is called. . . Postgres 9.6 Checkpoint

13 / 40

slide-33
SLIDE 33

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 Checkpointing

Postgres 9.5 Checkpoint data writes spread over some time random I/O OS choose when to actually write 30s delay on Linux until fsync is called. . . Postgres 9.6 Checkpoint

13 / 40

slide-34
SLIDE 34

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 Checkpointing

Postgres 9.5 Checkpoint data writes spread over some time random I/O OS choose when to actually write 30s delay on Linux until fsync is called. . . I/O storm – on low-end HDD Postgres 9.6 Checkpoint

13 / 40

slide-35
SLIDE 35

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 Checkpointing

Postgres 9.5 Checkpoint data writes spread over some time random I/O OS choose when to actually write 30s delay on Linux until fsync is called. . . I/O storm – on low-end HDD Postgres 9.6 Checkpoint sorted data writes spread over some time sequential I/O flush instructions sent regularly (256 kB)

checkpoint flush after

13 / 40

slide-36
SLIDE 36

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Latency Comparison – 9.5 vs 9.6 Checkpointing

Postgres 9.5 Checkpoint data writes spread over some time random I/O OS choose when to actually write 30s delay on Linux until fsync is called. . . I/O storm – on low-end HDD Postgres 9.6 Checkpoint sorted data writes spread over some time sequential I/O flush instructions sent regularly (256 kB)

checkpoint flush after

when fsync is called

  • k!

13 / 40

slide-37
SLIDE 37

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Benchmarking with Rate and Limit

14 / 40

slide-38
SLIDE 38

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Rate (tps) and Limit (ms) pgbench -R 100 -L 100 -N

Pg 9.5 basic checkpoint slow & skipped latency Pg 9.6 sorted checkpoint slow & skipped latency Pg 9.6 sorted & flushed checkpoint slow & skipped latency

15 / 40

slide-39
SLIDE 39

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Rate (tps) and Limit (ms) pgbench -R 100 -L 100 -N

Pg 9.5 basic checkpoint slow & skipped latency

50 100 150 500 1000 1500 2000 2500 tps run time in seconds

Pg 9.6 sorted checkpoint slow & skipped latency Pg 9.6 sorted & flushed checkpoint slow & skipped latency

15 / 40

slide-40
SLIDE 40

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Rate (tps) and Limit (ms) pgbench -R 100 -L 100 -N

Pg 9.5 basic checkpoint slow & skipped 24.0% latency 15.6 ± 158.3 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

Pg 9.6 sorted checkpoint slow & skipped latency Pg 9.6 sorted & flushed checkpoint slow & skipped latency

15 / 40

slide-41
SLIDE 41

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Rate (tps) and Limit (ms) pgbench -R 100 -L 100 -N

Pg 9.5 basic checkpoint slow & skipped 24.0% latency 15.6 ± 158.3 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

Pg 9.6 sorted checkpoint slow & skipped latency

50 100 150 500 1000 1500 2000 2500 tps run time in seconds

Pg 9.6 sorted & flushed checkpoint slow & skipped latency

15 / 40

slide-42
SLIDE 42

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Rate (tps) and Limit (ms) pgbench -R 100 -L 100 -N

Pg 9.5 basic checkpoint slow & skipped 24.0% latency 15.6 ± 158.3 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

Pg 9.6 sorted checkpoint slow & skipped 2.7% latency 3.6 ± 24.6 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

Pg 9.6 sorted & flushed checkpoint slow & skipped latency

15 / 40

slide-43
SLIDE 43

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Rate (tps) and Limit (ms) pgbench -R 100 -L 100 -N

Pg 9.5 basic checkpoint slow & skipped 24.0% latency 15.6 ± 158.3 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

Pg 9.6 sorted checkpoint slow & skipped 2.7% latency 3.6 ± 24.6 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

Pg 9.6 sorted & flushed checkpoint slow & skipped latency

50 100 150 500 1000 1500 2000 2500 tps run time in seconds

15 / 40

slide-44
SLIDE 44

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Rate (tps) and Limit (ms) pgbench -R 100 -L 100 -N

Pg 9.5 basic checkpoint slow & skipped 24.0% latency 15.6 ± 158.3 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

Pg 9.6 sorted checkpoint slow & skipped 2.7% latency 3.6 ± 24.6 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

Pg 9.6 sorted & flushed checkpoint slow & skipped 0.5% latency 2.6 ± 13.8 ms

50 100 150 500 1000 1500 2000 2500 tps run seconds sorted by tps

15 / 40

slide-45
SLIDE 45

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Three Storage Options

16 / 40

slide-46
SLIDE 46

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

FILLFACTOR Storage Parameter

CREATE TABLE pgbench accounts(...) WITH (FILLFACTOR = 100);

FILLFACTOR Usage MVCC: UPDATE = DELETE + INSERT up to 3 pages changes some free space available in page 1 inside page change but more pages/costs for other operations trade-off FILLFACTOR = 100 throughput 406.9 tps latency 19.7 ± 12.3 ms FILLFACTOR = 95 throughput latency

17 / 40

slide-47
SLIDE 47

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

FILLFACTOR Storage Parameter

CREATE TABLE pgbench accounts(...) WITH (FILLFACTOR = 100);

FILLFACTOR Usage MVCC: UPDATE = DELETE + INSERT up to 3 pages changes some free space available in page 1 inside page change but more pages/costs for other operations trade-off FILLFACTOR = 100 throughput 406.9 tps latency 19.7 ± 12.3 ms FILLFACTOR = 95 throughput latency

17 / 40

slide-48
SLIDE 48

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

FILLFACTOR Storage Parameter

CREATE TABLE pgbench accounts(...) WITH (FILLFACTOR = 100);

FILLFACTOR Usage MVCC: UPDATE = DELETE + INSERT up to 3 pages changes some free space available in page 1 inside page change but more pages/costs for other operations trade-off FILLFACTOR = 100 throughput 406.9 tps latency 19.7 ± 12.3 ms FILLFACTOR = 95 throughput 416.8 tps latency 19.2 ± 8.3 ms

17 / 40

slide-49
SLIDE 49

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Hardware HDD vs SSD

Hard Disk Drive mechanics fast sequential I/O slow random I/O vs Solid State Disk electronics fast sequential I/O fast random I/O pgbench -j 4 -c 8 -T 2500 -M prepared ... Postgres 9.6 HDD

406.9 tps 19.7 ± 12.3 ms

SSD

18 / 40

slide-50
SLIDE 50

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Hardware HDD vs SSD

Hard Disk Drive mechanics fast sequential I/O slow random I/O vs Solid State Disk electronics fast sequential I/O fast random I/O pgbench -j 4 -c 8 -T 2500 -M prepared ... Postgres 9.6 HDD

406.9 tps 19.7 ± 12.3 ms

SSD

100 200 300 400 500 600 500 1000 1500 2000 2500 tps seconds HDD

18 / 40

slide-51
SLIDE 51

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Hardware HDD vs SSD

Hard Disk Drive mechanics fast sequential I/O slow random I/O vs Solid State Disk electronics fast sequential I/O fast random I/O pgbench -j 4 -c 8 -T 2500 -M prepared ... Postgres 9.6 HDD

406.9 tps 19.7 ± 12.3 ms

SSD

4,764.9 tps 1.7 ± 2.4 ms

1000 2000 3000 4000 5000 6000 500 1000 1500 2000 2500 tps seconds SSD HDD

18 / 40

slide-52
SLIDE 52

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Hardware HDD vs SSD

Hard Disk Drive mechanics fast sequential I/O slow random I/O vs Solid State Disk electronics fast sequential I/O fast random I/O pgbench -j 4 -c 8 -T 2500 -M prepared ... Postgres 9.6 HDD

406.9 tps 19.7 ± 12.3 ms

SSD

4,764.9 tps 1.7 ± 2.4 ms checkpoint full page write effect

1000 2000 3000 4000 5000 6000 500 1000 1500 2000 2500 tps seconds SSD HDD

18 / 40

slide-53
SLIDE 53

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

UNLOGGED TABLE Can you loose your data?

CREATE UNLOGGED TABLE pgbench accounts(...); Standard ACID throughput 406.9 tps latency 19.7 ± 12.3 ms UNLOGGED throughput latency

...

19 / 40

slide-54
SLIDE 54

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

UNLOGGED TABLE Can you loose your data?

CREATE UNLOGGED TABLE pgbench accounts(...); Standard ACID throughput 406.9 tps latency 19.7 ± 12.3 ms UNLOGGED throughput latency

...

19 / 40

slide-55
SLIDE 55

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

UNLOGGED TABLE Can you loose your data?

CREATE UNLOGGED TABLE pgbench accounts(...); Standard ACID throughput 406.9 tps latency 19.7 ± 12.3 ms UNLOGGED good luck! throughput 5,310.7 tps latency 1.5 ± 0.3 ms

...

19 / 40

slide-56
SLIDE 56

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

UNLOGGED TABLE Can you loose your data?

CREATE UNLOGGED TABLE pgbench accounts(...); Standard ACID throughput 406.9 tps latency 19.7 ± 12.3 ms UNLOGGED good luck! throughput 5,310.7 tps latency 1.5 ± 0.3 ms

NO!

19 / 40

slide-57
SLIDE 57

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Two Protocol Impacts

20 / 40

slide-58
SLIDE 58

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Read-Only In-Cache Test ro3.sql

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) BEGIN; SELECT abalance FROM pgbench accounts WHERE aid=:aid; SELECT tbalance FROM pgbench tellers WHERE tid=:tid; SELECT bbalance FROM pgbench branches WHERE bid=:bid; COMMIT;

Operations Queries on 3 tables

1 transfers

network protocol

2 parse query

syntax analysis

3 plan query

  • ptimization

4 execute query

cheap if in cache

21 / 40

slide-59
SLIDE 59

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Read-Only In-Cache Test ro3.sql

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) BEGIN; SELECT abalance FROM pgbench accounts WHERE aid=:aid; SELECT tbalance FROM pgbench tellers WHERE tid=:tid; SELECT bbalance FROM pgbench branches WHERE bid=:bid; COMMIT;

Operations Queries on 3 tables

1 transfers

network protocol

2 parse query

syntax analysis

3 plan query

  • ptimization

4 execute query

cheap if in cache

21 / 40

slide-60
SLIDE 60

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Protocol SSL or not

SSL Costs time & e negotiation and re-negotiation cryptographic functions certificate Benefits Confidentiality Integrity Authentication sslmode=require SSL throughput 709.7 tps latency 1.407 ± 0.132 ms sslmode=disable clear throughput latency

22 / 40

slide-61
SLIDE 61

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Protocol SSL or not

SSL Costs time & e negotiation and re-negotiation cryptographic functions certificate Benefits Confidentiality Integrity Authentication sslmode=require SSL throughput 709.7 tps latency 1.407 ± 0.132 ms sslmode=disable clear throughput latency

22 / 40

slide-62
SLIDE 62

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Protocol SSL or not

SSL Costs time & e negotiation and re-negotiation cryptographic functions certificate? Benefits Snake Oil! Confidentiality Integrity Authentication sslmode=require SSL throughput 709.7 tps latency 1.407 ± 0.132 ms sslmode=disable clear throughput latency

22 / 40

slide-63
SLIDE 63

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Protocol SSL or not

SSL Costs time & e negotiation and re-negotiation cryptographic functions certificate Benefits Snake Oil! Confidentiality Integrity Authentication

pgbench -j 1 -c 1 -D scale=100 -f ro3.sql -T 30 "host=server ..."

sslmode=require SSL throughput 709.7 tps latency 1.407 ± 0.132 ms sslmode=disable clear throughput latency

22 / 40

slide-64
SLIDE 64

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Protocol SSL or not

SSL Costs time & e negotiation and re-negotiation cryptographic functions certificate Benefits Snake Oil! Confidentiality Integrity Authentication

pgbench -j 1 -c 1 -D scale=100 -f ro3.sql -T 30 "host=server ..."

sslmode=require SSL throughput 709.7 tps latency 1.407 ± 0.132 ms sslmode=disable clear throughput 781.6 tps latency 1.277 ± 0.034 ms

22 / 40

slide-65
SLIDE 65

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Protocol Simple vs Prepared

  • - prepare once in session

PREPARE Abal(INT) AS SELECT abalance FROM pgbench accounts WHERE aid=$1;

  • - execute multiple times...

EXECUTE Abal(1); EXECUTE Abal(5432); EXECUTE Abal(18);

Prepare temporary one-cmd function factor out parse cost keep plan and execute pgbench -M prepared . . . ro3.sql simple throughput 709.7 tps latency 1.407 ± 0.132 ms ro3.sql prepared throughput latency

23 / 40

slide-66
SLIDE 66

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Protocol Simple vs Prepared

  • - prepare once in session

PREPARE Abal(INT) AS SELECT abalance FROM pgbench accounts WHERE aid=$1;

  • - execute multiple times...

EXECUTE Abal(1); EXECUTE Abal(5432); EXECUTE Abal(18);

Prepare temporary one-cmd function factor out parse cost keep plan and execute pgbench -M prepared . . . ro3.sql simple throughput 709.7 tps latency 1.407 ± 0.132 ms ro3.sql prepared throughput latency

23 / 40

slide-67
SLIDE 67

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Protocol Simple vs Prepared

  • - prepare once in session

PREPARE Abal(INT) AS SELECT abalance FROM pgbench accounts WHERE aid=$1;

  • - execute multiple times...

EXECUTE Abal(1); EXECUTE Abal(5432); EXECUTE Abal(18);

Prepare temporary one-cmd function factor out parse cost keep plan and execute pgbench -M prepared . . . ro3.sql simple throughput 709.7 tps latency 1.407 ± 0.132 ms ro3.sql prepared throughput 860.0 tps latency 1.161 ± 0.082 ms

23 / 40

slide-68
SLIDE 68

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Four Query Combination Tricks

24 / 40

slide-69
SLIDE 69

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Query Combination UPDATE & SELECT

  • - update table

UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid;

  • - get updated data

SELECT abalance FROM pgbench accounts WHERE aid = :aid;

  • - combined

UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid RETURNING abalance;

UPDATE RETURNING Option return updated rows

  • ne parse, plan, execute

Standard throughput 406.9 tps latency 19.7 ± 12.3 ms Combined Update throughput latency

25 / 40

slide-70
SLIDE 70

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Query Combination UPDATE & SELECT

  • - update table

UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid;

  • - get updated data

SELECT abalance FROM pgbench accounts WHERE aid = :aid;

  • - combined

UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid RETURNING abalance;

UPDATE RETURNING Option return updated rows

  • ne parse, plan, execute

Standard throughput 406.9 tps latency 19.7 ± 12.3 ms Combined Update throughput latency

25 / 40

slide-71
SLIDE 71

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Query Combination UPDATE & SELECT

  • - update table

UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid;

  • - get updated data

SELECT abalance FROM pgbench accounts WHERE aid = :aid;

  • - combined

UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid RETURNING abalance;

UPDATE RETURNING Option return updated rows

  • ne parse, plan, execute

Standard throughput 406.9 tps latency 19.7 ± 12.3 ms Combined Update throughput latency

25 / 40

slide-72
SLIDE 72

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Query Combination UPDATE & SELECT

  • - update table

UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid;

  • - get updated data

SELECT abalance FROM pgbench accounts WHERE aid = :aid;

  • - combined

UPDATE pgbench accounts SET abalance = abalance + :delta WHERE aid = :aid RETURNING abalance;

UPDATE RETURNING Option return updated rows

  • ne parse, plan, execute

Standard throughput 406.9 tps latency 19.7 ± 12.3 ms Combined Update throughput 408.2 tps latency 19.6 ± 8.7 ms

25 / 40

slide-73
SLIDE 73

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Client-combined SQL Queries

  • - ”ro3c.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) BEGIN \; SELECT abalance FROM pgbench accounts WHERE aid=:aid \; SELECT tbalance FROM pgbench tellers WHERE tid=:tid \; SELECT bbalance FROM pgbench branches WHERE bid=:bid \; COMMIT;

Combine with \; embedded semi-colon ; request with multiple queries response with list of results avoid request-response loop ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3c.sql combined throughput latency

26 / 40

slide-74
SLIDE 74

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Client-combined SQL Queries

  • - ”ro3c.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) BEGIN \; SELECT abalance FROM pgbench accounts WHERE aid=:aid \; SELECT tbalance FROM pgbench tellers WHERE tid=:tid \; SELECT bbalance FROM pgbench branches WHERE bid=:bid \; COMMIT;

Combine with \; embedded semi-colon ; request with multiple queries response with list of results avoid request-response loop ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3c.sql combined throughput latency

26 / 40

slide-75
SLIDE 75

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Client-combined SQL Queries

  • - ”ro3c.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) BEGIN \; SELECT abalance FROM pgbench accounts WHERE aid=:aid \; SELECT tbalance FROM pgbench tellers WHERE tid=:tid \; SELECT bbalance FROM pgbench branches WHERE bid=:bid \; COMMIT;

Combine with \; embedded semi-colon ; request with multiple queries response with list of results avoid request-response loop ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3c.sql combined throughput 1,311.5 tps latency 0.748 ± 0.132 ms

26 / 40

slide-76
SLIDE 76

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Server-Side SQL queries

CREATE TYPE Balances AS (abal INT, tbal INT, bbal INT); CREATE FUNCTION getBalSQL(INT, INT, INT) RETURNS Balances AS $$ SELECT (SELECT abalance FROM pgbench accounts WHERE aid=$1), (SELECT tbalance FROM pgbench tellers WHERE tid=$2), (SELECT bbalance FROM pgbench branches WHERE bid=$3) $$ LANGUAGE SQL;

  • - ”ro3sf.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) SELECT getBalSQL(:aid, :tid, :bid);

ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3sf.sql SQL call throughput latency

27 / 40

slide-77
SLIDE 77

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Server-Side SQL queries

CREATE TYPE Balances AS (abal INT, tbal INT, bbal INT); CREATE FUNCTION getBalSQL(INT, INT, INT) RETURNS Balances AS $$ SELECT (SELECT abalance FROM pgbench accounts WHERE aid=$1), (SELECT tbalance FROM pgbench tellers WHERE tid=$2), (SELECT bbalance FROM pgbench branches WHERE bid=$3) $$ LANGUAGE SQL;

  • - ”ro3sf.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) SELECT getBalSQL(:aid, :tid, :bid);

ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3sf.sql SQL call throughput latency

27 / 40

slide-78
SLIDE 78

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Server-Side SQL queries

CREATE TYPE Balances AS (abal INT, tbal INT, bbal INT); CREATE FUNCTION getBalSQL(INT, INT, INT) RETURNS Balances AS $$ SELECT (SELECT abalance FROM pgbench accounts WHERE aid=$1), (SELECT tbalance FROM pgbench tellers WHERE tid=$2), (SELECT bbalance FROM pgbench branches WHERE bid=$3) $$ LANGUAGE SQL;

  • - ”ro3sf.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) SELECT getBalSQL(:aid, :tid, :bid);

ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3sf.sql SQL call throughput 1,395.4 tps latency 0.712 ± 0.075 ms

27 / 40

slide-79
SLIDE 79

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Server-Side PL/pgSQL queries

CREATE FUNCTION getBalPL(a INT, t INT, b INT) RETURNS Balances AS $$ DECLARE abal INT; tbal INT; bbal INT; BEGIN SELECT abalance INTO abal FROM pgbench accounts WHERE aid=a; SELECT tbalance INTO tbal FROM pgbench tellers WHERE tid=t; SELECT bbalance INTO bbal FROM pgbench branches WHERE bid=b; RETURN (abal, tbal, bbal)::Balances; END; $$ LANGUAGE PLpgSQL;

  • - ”ro3pf.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) SELECT getBalPL(:aid, :tid, :bid);

ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3pf.sql PL/pgSQL call throughput latency

28 / 40

slide-80
SLIDE 80

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Server-Side PL/pgSQL queries

CREATE FUNCTION getBalPL(a INT, t INT, b INT) RETURNS Balances AS $$ DECLARE abal INT; tbal INT; bbal INT; BEGIN SELECT abalance INTO abal FROM pgbench accounts WHERE aid=a; SELECT tbalance INTO tbal FROM pgbench tellers WHERE tid=t; SELECT bbalance INTO bbal FROM pgbench branches WHERE bid=b; RETURN (abal, tbal, bbal)::Balances; END; $$ LANGUAGE PLpgSQL;

  • - ”ro3pf.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) SELECT getBalPL(:aid, :tid, :bid);

ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3pf.sql PL/pgSQL call throughput latency

28 / 40

slide-81
SLIDE 81

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Server-Side PL/pgSQL queries

CREATE FUNCTION getBalPL(a INT, t INT, b INT) RETURNS Balances AS $$ DECLARE abal INT; tbal INT; bbal INT; BEGIN SELECT abalance INTO abal FROM pgbench accounts WHERE aid=a; SELECT tbalance INTO tbal FROM pgbench tellers WHERE tid=t; SELECT bbalance INTO bbal FROM pgbench branches WHERE bid=b; RETURN (abal, tbal, bbal)::Balances; END; $$ LANGUAGE PLpgSQL;

  • - ”ro3pf.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) SELECT getBalPL(:aid, :tid, :bid);

? ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3pf.sql PL/pgSQL call throughput 2,485.5 tps latency 0.400 ± 0.055 ms

28 / 40

slide-82
SLIDE 82

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Server-Side PL/pgSQL queries

CREATE FUNCTION getBalPL(a INT, t INT, b INT) RETURNS Balances AS $$ DECLARE abal INT; tbal INT; bbal INT; BEGIN SELECT abalance INTO abal FROM pgbench accounts WHERE aid=a; SELECT tbalance INTO tbal FROM pgbench tellers WHERE tid=t; SELECT bbalance INTO bbal FROM pgbench branches WHERE bid=b; RETURN (abal, tbal, bbal)::Balances; END; $$ LANGUAGE PLpgSQL;

  • - ”ro3pf.sql” pgbench script

\set aid random(1, 100000 * :scale) \set tid random(1, 10 * :scale) \set bid random(1, :scale) SELECT getBalPL(:aid, :tid, :bid);

PL/pgSQL caches plans! ro3.sql standard throughput 709.7 tps latency 1.407 ± 0.132 ms ro3pf.sql PL/pgSQL call throughput 2,485.5 tps latency 0.400 ± 0.055 ms

28 / 40

slide-83
SLIDE 83

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Reducting Server Distance

29 / 40

slide-84
SLIDE 84

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Client-Server Distance

Interconnection LAN Local Area Network Ethernet LO loopback interface localhost IPC Inter-Process Communication Unix domain socket TPC-B-Like

  • n HDD

LAN 100.3 tps 9.9 ms LO IPC Read-Only 3 LAN 709.7 tps 1.4 ms LO IPC

30 / 40

slide-85
SLIDE 85

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Client-Server Distance

Interconnection LAN Local Area Network Ethernet LO loopback interface localhost IPC Inter-Process Communication Unix domain socket TPC-B-Like

  • n HDD

LAN 100.3 tps 9.9 ms LO 114.5 tps 8.7 ms IPC 113.5 tps 8.8 ms Read-Only 3 LAN 709.7 tps 1.4 ms LO IPC

30 / 40

slide-86
SLIDE 86

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Client-Server Distance

Interconnection LAN Local Area Network Ethernet LO loopback interface localhost IPC Inter-Process Communication Unix domain socket TPC-B-Like

  • n SSD

LAN 403.8 tps 2.4 ms LO 1,133.3 tps 0.9 ms IPC 1,243.1 tps 0.8 ms Read-Only 3 LAN 709.7 tps 1.4 ms LO IPC

30 / 40

slide-87
SLIDE 87

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Client-Server Distance

Interconnection LAN Local Area Network Ethernet LO loopback interface localhost IPC Inter-Process Communication Unix domain socket TPC-B-Like

  • n SSD

LAN 403.8 tps 2.4 ms LO 1,133.3 tps 0.9 ms IPC 1,243.1 tps 0.8 ms Read-Only 3 LAN 709.7 tps 1.4 ms LO 2,515.3 tps 0.4 ms IPC 3,607.6 tps 0.3 ms

30 / 40

slide-88
SLIDE 88

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Performance Scalability

31 / 40

slide-89
SLIDE 89

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

# Clients Scalability Base

Read-Only 3 – remote SSL simple queries Best Throughput Best Latency Compromise

32 / 40

slide-90
SLIDE 90

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

# Clients Scalability Base

Read-Only 3 – remote SSL simple queries Best Throughput

37,639 tps 4.103 ms 156/4

Best Latency Compromise

10 20 30 40 20 40 60 80 100 120 140 160 180 thousand tps number of clients 32 / 40

slide-91
SLIDE 91

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

# Clients Scalability Base

Read-Only 3 – remote SSL simple queries Best Throughput

37,639 tps 4.103 ms 156/4

Best Latency

5,748 tps 1.042 ms 6/1

Compromise

10 20 30 40 20 40 60 80 100 120 140 160 180 thousand tps number of clients 1 2 3 4 5 6 20 40 60 80 100 120 140 160 180 latency ms number of clients 32 / 40

slide-92
SLIDE 92

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

# Clients Scalability Base

Read-Only 3 – remote SSL simple queries Best Throughput

37,639 tps 4.103 ms 156/4

Best Latency

5,748 tps 1.042 ms 6/1

Compromise

31,494 tps 1.837 ms 58/4

10 20 30 40 20 40 60 80 100 120 140 160 180 thousand tps number of clients 1 2 3 4 5 6 20 40 60 80 100 120 140 160 180 latency ms number of clients 32 / 40

slide-93
SLIDE 93

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

# Clients Scalability Best

Read-Only 3 – remote noSSL prepared PL call Best Throughput Best Latency Compromise

33 / 40

slide-94
SLIDE 94

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

# Clients Scalability Best

Read-Only 3 – remote noSSL prepared PL call Best Throughput

181,503 tps 0.766 ms 140/4

Best Latency Compromise

50 100 150 200 20 40 60 80 100 120 140 160 180 thousand tps number of clients Best Base 33 / 40

slide-95
SLIDE 95

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

# Clients Scalability Best

Read-Only 3 – remote noSSL prepared PL call Best Throughput

181,503 tps 0.766 ms 140/4

Best Latency

39,232 tps 0.254 ms 10/2

Compromise

50 100 150 200 20 40 60 80 100 120 140 160 180 thousand tps number of clients Best Base 0.2 0.4 0.6 0.8 1 1.2 20 40 60 80 100 120 140 160 180 latency ms number of clients Best Base 33 / 40

slide-96
SLIDE 96

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

# Clients Scalability Best

Read-Only 3 – remote noSSL prepared PL call Best Throughput

181,503 tps 0.766 ms 140/4

Best Latency

39,232 tps 0.254 ms 10/2

Compromise

156,945 tps 0.381 ms 60/4

50 100 150 200 20 40 60 80 100 120 140 160 180 thousand tps number of clients Best Base 0.2 0.4 0.6 0.8 1 1.2 20 40 60 80 100 120 140 160 180 latency ms number of clients Best Base 33 / 40

slide-97
SLIDE 97

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Performance Comparisons

Miscellaneous Settings

34 / 40

slide-98
SLIDE 98

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Miscellaneous Settings App & Postgres

Application framework? connection persistence cache Memcached Redis Postgres configuration change defaults disk block size random page cost memory shared buffers effective cache size huge pages checkpoint

timeout completion target flush after

wal max wal size

35 / 40

slide-99
SLIDE 99

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Miscellaneous Settings App & Postgres

Application framework? connection persistence cache Memcached Redis Postgres configuration change defaults disk block size random page cost memory shared buffers effective cache size huge pages checkpoint

timeout completion target flush after

wal max wal size

35 / 40

slide-100
SLIDE 100

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Miscellaneous Settings OS & Hardware

OS tweak and choose FS XFS ext4 Btrfs ZFS, mount options IO io scheduler, queue length, write delay, dirty bytes. . .

  • thers NUMA, . . .

Hardware expensive is (probably) better diskS tables wal logs, HDD-with-cache, SSD tweaking read ahead, write flush RAID with large caches, BBU

36 / 40

slide-101
SLIDE 101

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Miscellaneous Settings OS & Hardware

OS tweak and choose FS XFS ext4 Btrfs ZFS, mount options IO io scheduler, queue length, write delay, dirty bytes. . .

  • thers NUMA, . . .

Hardware expensive is (probably) better diskS tables wal logs, HDD-with-cache, SSD tweaking read ahead, write flush RAID with large caches, BBU

36 / 40

slide-102
SLIDE 102

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Conclusion

37 / 40

slide-103
SLIDE 103

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Wrap-up pgbench -j 1 -c 1 ...

TPC-B-like Read-Only 3 tps ms tps ms HDD -C SSL 36.1 27.7 52.7 18.96 HDD -C noSSL 56.4 17.7 110.1 9.08 HDD SSL 105.4 9.5 709.7 1.41 SSD SSL 403.8 2.47 695.1 1.44 SSD noSSL 465.4 2.15 820.1 1.22 . . . + prepared 548.1 1.82 974.0 1.02 – returning 529.4 1.89 – – . . . + prepared 681.2 1.47 – – – combined 857.8 1.15 1,536.4 0.64 – SQL func 940.3 1.06 1,818.1 0.55 . . . + prepared 957.9 1.04 2,144.7 0.46 – PL func 1,279.4 0.78 2,778.0 0.36 . . . + prepared 1,323.2 0.75 3,040.4 0.33 localhost 1,907.6 0.52 10,006.8 0.10 socket 2,273.1 0.44 11,545.5 0.09

connection HDD to SSD SSL to none simple to prepared

  • combinations. . .

remote to local

38 / 40

slide-104
SLIDE 104

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Wrap-up pgbench -j 1 -c 1 ...

TPC-B-like Read-Only 3 tps ms tps ms HDD -C SSL 36.1 27.7 52.7 18.96 HDD -C noSSL 56.4 17.7 110.1 9.08 HDD SSL 105.4 9.5 709.7 1.41 SSD SSL 403.8 2.47 695.1 1.44 SSD noSSL 465.4 2.15 820.1 1.22 . . . + prepared 548.1 1.82 974.0 1.02 – returning 529.4 1.89 – – . . . + prepared 681.2 1.47 – – – combined 857.8 1.15 1,536.4 0.64 – SQL func 940.3 1.06 1,818.1 0.55 . . . + prepared 957.9 1.04 2,144.7 0.46 – PL func 1,279.4 0.78 2,778.0 0.36 . . . + prepared 1,323.2 0.75 3,040.4 0.33 localhost 1,907.6 0.52 10,006.8 0.10 socket 2,273.1 0.44 11,545.5 0.09

connection HDD to SSD SSL to none simple to prepared

  • combinations. . .

remote to local ×3 to ×14

38 / 40

slide-105
SLIDE 105

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Wrap-up pgbench -j 1 -c 1 ...

TPC-B-like Read-Only 3 tps ms tps ms HDD -C SSL 36.1 27.7 52.7 18.96 HDD -C noSSL 56.4 17.7 110.1 9.08 HDD SSL 105.4 9.5 709.7 1.41 SSD SSL 403.8 2.47 695.1 1.44 SSD noSSL 465.4 2.15 820.1 1.22 . . . + prepared 548.1 1.82 974.0 1.02 – returning 529.4 1.89 – – . . . + prepared 681.2 1.47 – – – combined 857.8 1.15 1,536.4 0.64 – SQL func 940.3 1.06 1,818.1 0.55 . . . + prepared 957.9 1.04 2,144.7 0.46 – PL func 1,279.4 0.78 2,778.0 0.36 . . . + prepared 1,323.2 0.75 3,040.4 0.33 localhost 1,907.6 0.52 10,006.8 0.10 socket 2,273.1 0.44 11,545.5 0.09

connection HDD to SSD SSL to none simple to prepared

  • combinations. . .

remote to local ×4 to =

38 / 40

slide-106
SLIDE 106

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Wrap-up pgbench -j 1 -c 1 ...

TPC-B-like Read-Only 3 tps ms tps ms HDD -C SSL 36.1 27.7 52.7 18.96 HDD -C noSSL 56.4 17.7 110.1 9.08 HDD SSL 105.4 9.5 709.7 1.41 SSD SSL 403.8 2.47 695.1 1.44 SSD noSSL 465.4 2.15 820.1 1.22 . . . + prepared 548.1 1.82 974.0 1.02 – returning 529.4 1.89 – – . . . + prepared 681.2 1.47 – – – combined 857.8 1.15 1,536.4 0.64 – SQL func 940.3 1.06 1,818.1 0.55 . . . + prepared 957.9 1.04 2,144.7 0.46 – PL func 1,279.4 0.78 2,778.0 0.36 . . . + prepared 1,323.2 0.75 3,040.4 0.33 localhost 1,907.6 0.52 10,006.8 0.10 socket 2,273.1 0.44 11,545.5 0.09

connection HDD to SSD SSL to none simple to prepared

  • combinations. . .

remote to local +15% to +18%

38 / 40

slide-107
SLIDE 107

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Wrap-up pgbench -j 1 -c 1 ...

TPC-B-like Read-Only 3 tps ms tps ms HDD -C SSL 36.1 27.7 52.7 18.96 HDD -C noSSL 56.4 17.7 110.1 9.08 HDD SSL 105.4 9.5 709.7 1.41 SSD SSL 403.8 2.47 695.1 1.44 SSD noSSL 465.4 2.15 820.1 1.22 . . . + prepared 548.1 1.82 974.0 1.02 – returning 529.4 1.89 – – . . . + prepared 681.2 1.47 – – – combined 857.8 1.15 1,536.4 0.64 – SQL func 940.3 1.06 1,818.1 0.55 . . . + prepared 957.9 1.04 2,144.7 0.46 – PL func 1,279.4 0.78 2,778.0 0.36 . . . + prepared 1,323.2 0.75 3,040.4 0.33 localhost 1,907.6 0.52 10,006.8 0.10 socket 2,273.1 0.44 11,545.5 0.09

connection HDD to SSD SSL to none simple to prepared

  • combinations. . .

remote to local +2% to +28%

38 / 40

slide-108
SLIDE 108

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Wrap-up pgbench -j 1 -c 1 ...

TPC-B-like Read-Only 3 tps ms tps ms HDD -C SSL 36.1 27.7 52.7 18.96 HDD -C noSSL 56.4 17.7 110.1 9.08 HDD SSL 105.4 9.5 709.7 1.41 SSD SSL 403.8 2.47 695.1 1.44 SSD noSSL 465.4 2.15 820.1 1.22 . . . + prepared 548.1 1.82 974.0 1.02 – returning 529.4 1.89 – – . . . + prepared 681.2 1.47 – – – combined 857.8 1.15 1,536.4 0.64 – SQL func 940.3 1.06 1,818.1 0.55 . . . + prepared 957.9 1.04 2,144.7 0.46 – PL func 1,279.4 0.78 2,778.0 0.36 . . . + prepared 1,323.2 0.75 3,040.4 0.33 localhost 1,907.6 0.52 10,006.8 0.10 socket 2,273.1 0.44 11,545.5 0.09

connection HDD to SSD SSL to none simple to prepared

  • combinations. . .

remote to local ×3 to ×4

38 / 40

slide-109
SLIDE 109

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Wrap-up pgbench -j 1 -c 1 ...

TPC-B-like Read-Only 3 tps ms tps ms HDD -C SSL 36.1 27.7 52.7 18.96 HDD -C noSSL 56.4 17.7 110.1 9.08 HDD SSL 105.4 9.5 709.7 1.41 SSD SSL 403.8 2.47 695.1 1.44 SSD noSSL 465.4 2.15 820.1 1.22 . . . + prepared 548.1 1.82 974.0 1.02 – returning 529.4 1.89 – – . . . + prepared 681.2 1.47 – – – combined 857.8 1.15 1,536.4 0.64 – SQL func 940.3 1.06 1,818.1 0.55 . . . + prepared 957.9 1.04 2,144.7 0.46 – PL func 1,279.4 0.78 2,778.0 0.36 . . . + prepared 1,323.2 0.75 3,040.4 0.33 localhost 1,907.6 0.52 10,006.8 0.10 socket 2,273.1 0.44 11,545.5 0.09

connection HDD to SSD SSL to none simple to prepared

  • combinations. . .

remote to local ×1.7 to ×3.7

38 / 40

slide-110
SLIDE 110

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Wrap-up pgbench -j 1 -c 1 ...

TPC-B-like Read-Only 3 tps ms tps ms HDD -C SSL 36.1 27.7 52.7 18.96 HDD -C noSSL 56.4 17.7 110.1 9.08 HDD SSL 105.4 9.5 709.7 1.41 SSD SSL 403.8 2.47 695.1 1.44 SSD noSSL 465.4 2.15 820.1 1.22 . . . + prepared 548.1 1.82 974.0 1.02 – returning 529.4 1.89 – – . . . + prepared 681.2 1.47 – – – combined 857.8 1.15 1,536.4 0.64 – SQL func 940.3 1.06 1,818.1 0.55 . . . + prepared 957.9 1.04 2,144.7 0.46 – PL func 1,279.4 0.78 2,778.0 0.36 . . . + prepared 1,323.2 0.75 3,040.4 0.33 localhost 1,907.6 0.52 10,006.8 0.10 socket 2,273.1 0.44 11,545.5 0.09

connection HDD to SSD SSL to none simple to prepared

  • combinations. . .

remote to local × 63 to × 219 and scaling effects

38 / 40

slide-111
SLIDE 111

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Lessons

Things to Bring Home in-memory OLTP load NoTPS not only TPS latency matters! latency-throughput compromise Performance experiment and measure do not assume! pgbench is improving. . . Postgres version 9.6! sorted and flushed checkpoints High costs network, parse & plan RW load ACID SSD ≫ HDD RO load pg as a cache manager SSD = HDD

39 / 40

slide-112
SLIDE 112

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Lessons

Things to Bring Home in-memory OLTP load NoTPS not only TPS latency matters! latency-throughput compromise Performance experiment and measure do not assume! pgbench is improving. . . Postgres version 9.6! sorted and flushed checkpoints High costs network, parse & plan RW load ACID SSD ≫ HDD RO load pg as a cache manager SSD = HDD

39 / 40

slide-113
SLIDE 113

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Lessons

Things to Bring Home in-memory OLTP load NoTPS not only TPS latency matters! latency-throughput compromise Performance experiment and measure do not assume! pgbench is improving. . . Postgres version 9.6! sorted and flushed checkpoints High costs network, parse & plan RW load ACID SSD ≫ HDD RO load pg as a cache manager SSD = HDD

39 / 40

slide-114
SLIDE 114

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Lessons

Things to Bring Home in-memory OLTP load NoTPS not only TPS latency matters! latency-throughput compromise Performance experiment and measure do not assume! pgbench is improving. . . Postgres version 9.6! sorted and flushed checkpoints High costs network, parse & plan RW load ACID SSD ≫ HDD RO load pg as a cache manager SSD = HDD

39 / 40

slide-115
SLIDE 115

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Lessons

Things to Bring Home in-memory OLTP load NoTPS not only TPS latency matters! latency-throughput compromise Performance experiment and measure do not assume! pgbench is improving. . . Postgres version 9.6! sorted and flushed checkpoints High costs network, parse & plan RW load ACID SSD ≫ HDD RO load pg as a cache manager SSD = HDD

39 / 40

slide-116
SLIDE 116

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Lessons

Things to Bring Home in-memory OLTP load NoTPS not only TPS latency matters! latency-throughput compromise Performance experiment and measure do not assume! pgbench is improving. . . Postgres version 9.6! sorted and flushed checkpoints High costs network, parse & plan RW load ACID SSD ≫ HDD RO load pg as a cache manager SSD = HDD

39 / 40

slide-117
SLIDE 117

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Contributions provided or provoked

About Core

& Andres Freund

sorted checkpoints flushed checkpoints About pgbench

& Robert Haas

expressions \set ... mixed and weighted scripts and builtins

  • b/-f ...@...

better statistics stddev, per script. . . improved usability

  • c/-j -P. . .

rate and limit load

  • R -L
  • debug. . .

40 / 40

slide-118
SLIDE 118

Postgres Latency

  • F. Coelho

Introduction

Subject Application Definitions pgbench

Performance

Connection Latency Rate & Limit Storage Protocol Combinations Distance Scalability Miscellaneous

Conclusion

Wrap-Up Lessons Contributions

Contributions provided or provoked

About Core

& Andres Freund

sorted checkpoints flushed checkpoints About pgbench

& Robert Haas

expressions \set ... mixed and weighted scripts and builtins

  • b/-f ...@...

better statistics stddev, per script. . . improved usability

  • c/-j -P. . .

rate and limit load

  • R -L
  • debug. . .

40 / 40

slide-119
SLIDE 119

Measuring and Reducing Postgres Transaction Latency

Fabien Coelho

MINES ParisTech, PSL Research University

pgDay Paris – March 23, 2017

1 / 1