aws re:invent 2016: how citus enables scalable postgresql on aws (dat207)

70
HOW CITUS ENABLES SCALABLE POSTGRES ON AWS

Upload: amazon-web-services

Post on 24-Jan-2018

562 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

HOW CITUS ENABLESSCALABLE POSTGRES

ON AWS

Page 2: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

WILL LEINWEBER@LEINWEBER

CITUSDATA.COM

Page 3: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 4: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 5: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

ORCHESTRATION

Page 6: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

CITUS

Page 7: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

OPEN SOURCE POSTGRES EXTENSION

github.com/citusdata/citus

citusdata.com

Page 8: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

DISTRIBUTED POSTGRES

Page 9: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

WORKER NODES AND SHARDS

Worker 0

Shard 0

Shard 1

Shard 2

Worker 1

Shard 3

Shard 4

Shard 5

Page 10: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

POSTGRES AND TABLES

PG Server 0

Table 0

Table 1

Table 2

PG Server 1

Table 3

Table 4

Shard 5

Page 11: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

citus (coordinator node)=# \d

List of relations

Schema | Name | Type | Owner

--------+---------------+-------+----------

public | cw_metrics | table | citus

public | events | table | citus

Page 12: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

citus (worker node)=# \d

List of relations

Schema | Name | Type | Owner

--------+---------------------+-------+----------

public | cw_metrics_102008 | table | citus

public | cw_metrics_102012 | table | citus

public | cw_metrics_102016 | table | citus

public | cw_metrics_102064 | table | citus

public | cw_metrics_102068 | table | citus

public | events_102104 | table | citus

public | events_102108 | table | citus

public | events_102112 | table | citus

public | events_102116 | table | citus

Page 13: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

WRITES

Page 14: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

citus=> select * from pg_dist_shard limit 10;

logicalrelid | shardid | shardstorage | shardalias | shardminvalue | shardmaxvalue

--------------+---------+--------------+------------+---------------+---------------

19395 | 102040 | t | (null) | -2147483648 | -2013265921

19395 | 102041 | t | (null) | -2013265920 | -1879048193

19395 | 102042 | t | (null) | -1879048192 | -1744830465

19395 | 102043 | t | (null) | -1744830464 | -1610612737

19395 | 102044 | t | (null) | -1610612736 | -1476395009

19395 | 102045 | t | (null) | -1476395008 | -1342177281

19395 | 102046 | t | (null) | -1342177280 | -1207959553

19395 | 102047 | t | (null) | -1207959552 | -1073741825

19395 | 102048 | t | (null) | -1073741824 | -939524097

19395 | 102049 | t | (null) | -939524096 | -805306369

Page 15: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 16: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

MULTI-TENANT MODEL

System of record for

B2B SaSS apps scaling from

1 to 100,000s of tenants

Page 17: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

MULTI-TENANT MODEL

easy to migrate

easy to maintain (HA/DR/Backup/etc)

easy to scale vertically and horizontally

Page 18: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

MULTI-TENANT MODEL

shard all tables on

same column e.g. tenant_id

Page 19: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

MULTI-TENANT MODEL

where org_id=3

Page 20: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

MULTI-TENANT MODEL

where org_id=3

Page 21: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

MULTI-TENANT MODEL

Page 22: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

SQL on trillions of events for

high-value, real-time analytics

PARALLEL MODEL

Page 23: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

postgres

lower cost

extendable & flexible

PARALLEL MODEL

Page 24: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

PARALLEL MODEL

Page 25: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

PARALLEL MODEL

Page 26: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

PARALLEL MODEL

Page 27: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

CITUS MX

https://www.citusdata.com/blog/2016/09/22/announcing-citus-mx/

>500,000 writes/second (YCSB benchmark)

>7 million bulk loading with COPY

32 node cluster

Page 28: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 29: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 30: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

RUN YOURSELF OR HOSTED

Page 31: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

HOSTED TRADEOFFS

Page 32: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 33: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

HEROKU

Page 34: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

SINATRA & SEQUEL

Page 35: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

INTERACTIVE CONSOLE

[1] pry(main)> Resource.all

Page 36: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

(MOSTLY) IMMUTABLE SERVERS

Page 37: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

OUTSIDE-IN SSH&PSQL

Page 38: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

(MICRO)SERVICES

Page 39: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

ASIDE: CONWAY’S LAW

Page 40: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

DOWNSIDES OF MICROSERVICES

Page 41: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

CURRENTLY: TWO SERVICES

external console/dashboard

internal control plane

Page 42: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

CONSOLE

Customer UI

Create / Destroy

Billing

Metrics

Page 43: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

CONTROL PLANE

Server Provisioning

Monitoring

Healing

Page 44: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

COMMONALITIES

Page 45: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

CONTROL PLANE MODELS

Page 46: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

FORMATION & SERVER

Page 47: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 48: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

WAL-E

github.com/wal-e/wal-e

Page 49: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

TIMELINES

Page 50: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

REPLICAS

Page 51: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

AFTER RECOVERY

Page 52: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

SERVER REPLACEMENT

Page 53: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

VIDEO GAME DEVELOPMENT

Page 54: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

FEEL / TICK

Page 55: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

STATE MACHINES

creating available

uncertain

unavailable

deprovisioned

Page 56: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

ALWAYS CONVERGING

Page 57: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 58: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

SIDEKIQ AND REDIS

m,

`$b

.ss, $$: .,d$

`$$P,d$P' .,md$P"'

,$$$$$bmmd$$$P^'

.d$$$$$$$$$$P'

$$^' `"^$$$' ____ _ _ _ _

$: ,$$: / ___|(_) __| | ___| | _(_) __ _

`b :$$ \___ \| |/ _` |/ _ \ |/ / |/ _` |

$$: ___) | | (_| | __/ <| | (_| |

$$ |____/|_|\__,_|\___|_|\_\_|\__, |

.d$$ |_|

Page 59: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

QUEUE PROBLEMS

https://upload.wikimedia.org/wikipedia/commons/0/01/James_May's_Lego_House_a_long_queue_of_volunteers.jpg

Page 60: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

SEMAPHORES & CONCURRENCY

class Formation < Actor

def add_node

add_server

servers.each do |s|

s.sem.incr(:configure)

end

end

end

Page 61: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

SEMAPHORES & CONCURRENCY

class Server < Actor

def work_running

if sem.pos?(:configure)

self.state = :configuring

save_changes

end

end

def work_configuring

configure_stuff

sem.decr(:configure)

self.state = :running

save_changes

end

end

Page 62: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

IN-DEPTH DETAILS

www.citusdata.com/blog/2016/08/12/state-machines-to-run-databases/

Page 63: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)
Page 64: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

CUSTOMER-VISIBLE METRICS

Page 65: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

citus=> select * from cw_metrics limit 1;

-[ RECORD 1 ]+-------------------------------------

server_id | f2239a4b-7297-4b66-b9e3-851291760b70

aws_id | i-723a927805464ac8b

name | NetworkOut

timestamp | 2016-07-28 14:13:00-07

sample_count | 5

average | 127505

sum | 637525

minimum | 111888

maximum | 144385

unit | BytesIndexes:

"cw_metrics_pkey" PRIMARY KEY, btree (server_id, "timestamp", aws_id, name)

Page 66: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

ADMIN-METRICS

Page 67: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

citus=> select * from events order by created_at desc limit 2;

-[ RECORD 1 ]-

id | 9a3dfdbd-c395-40bb-8d25-45ee7c913662

name | Timeout::Error

created_at | 2016-07-28 13:18:47.289917-07

data | {"id": "5747a999-9768-429c-b13c-c7c0947dd950", "class": "Server", "message": "execution expired"}

-[ RECORD 2 ]-

id | ba9d6a13-0832-47fb-a849-02f1362c9019

name | Sequel::DatabaseConnectionError

created_at | 2016-07-28 12:58:40.506267-07

data | {"id": "232835ec-31a1-44d0-ae5b-edafb2cf6978", "class": "Timeline", "message": "PG::

Page 68: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

SELECT count(*), name, date_trunc('hour', created_at) as hour

FROM events

WHERE created_at > now()-'1 week'::interval

GROUP BY name, hour;

Page 69: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

ONE MISADVENTURE

Page 70: AWS re:Invent 2016: How Citus Enables Scalable PostgreSQL on AWS (DAT207)

WILL LEINWEBER@LEINWEBER

CITUSDATA.COMthank you