SlideShare a Scribd company logo
Scaling with SkyTools
                 & More
      Scaling-Out Postgres with Skype’s Open-Source Toolset




Gavin M. Roy
September 14th, 2011
About Me
• PostgreSQL ~ 6.5
• CTO @myYearbook.com
 • Scaled initial infrastructure
 • Not as involved day-to-day database
    operational and development
• Twitter: @Crad
Scaling?
Concurrency
Requests per Second




                      6am   8am 10am 12pm 2pm 4pm 6pm 8pm 10pm 12am 2am   4am   6am
                                             Hourly breakdown
Increasing Size-On-Disk
Size in GB




             Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
Scaling and
PostgreSQL Behavior
Size on Disk
Tuples, Indexes,
  Overhead
Table Size
               +
Size of all combined Indexes




  Relations   Indexes
Constraints

      •   Available Memory

      •   Disk Speed

      •   IO Bus Speed
Keep it in memory.
Get Fast Disks & I/O.
Process Forking
      +
    Locks
Client Connections
One Connection per
Concurrent Request
Apache+PHP
One connection per backend for each pg_connect
Python
One connection per connection*
ODBC
One connection to Postgres per ODBC connection
Master Process




     Lock                                           Stats
                                                   Collector




  Contention?                                     Autovacuum




Each backend for a connected                      Wall Writer


 client has to check for locks
                                                  Wall Writer




                                                  Connection
                                                                Client Connection
                                                   Backend
Master Process




New Client                                Stats
                                         Collector




Connection?
                                        Autovacuum




                                        Wall Writer

    Access Share
   Access Exclusive                     Wall Writer

      Exclusive
        Share                           Connection
                                                      Client Connection
                                         Backend
 Share Row Exclusive
    Share Update                        Connection
                                                      Client Connection
     Row Share
                                         Backend


    Row Exclusive
Master Process




                                       Stats
                                      Collector




 Too many                            Autovacuum




connections?                         Wall Writer




                                     Wall Writer


 Slow performance                    Connection
                                                   Client Connection
                                      Backend



                                     Connection
                                                   Client Connection
                                      Backend




                                 ...
                                     Connection
                                                   Client Connection
                                      Backend
250 Apache Backends
            x
1 Connection per Backend
            x
       250 Servers
            =
   62,500 Connections
Solvable Problems!
The Trailblazers
Solving Concurrency
pgBouncer
Session Pooling
Transactional Pooling
Statement Pooling
Connection Pooling
   Clients                Clients                Clients



              Hundreds   Hundreds    Hundreds


                         pgBouncer



                Tens       Tens        Tens


  Postgres               Postgres               Postgres
  Server #1              Server #2              Server #3
Add Local Pooling
     Clients                  Clients                  Clients



   Hundreds                 Hundreds                 Hundreds


 Local pgBouncer          Local pgBouncer          Local pgBouncer



                   Tens       Tens          Tens


                            pgBouncer



                   Tens        Tens         Tens


    Postgres                 Postgres                 Postgres
    Server #1                Server #2                Server #3
Easy to run
Usage: pgbouncer [OPTION]... config.ini
  -d, --daemon           Run in background (as a daemon)
  -R, --restart          Do a online restart
  -q, --quiet            Run quietly
  -v, --verbose          Increase verbosity
  -u, --user=<username> Assume identity of <username>
  -V, --version          Show version
  -h, --help             Show this help screen and exit
userlist.txt

“username” “password”
“foo” “bar”
pgbouncer.ini
Specifying Connections
[databases]
; foodb over unix socket
foodb =

; redirect bardb to bazdb on localhost
bardb = host=localhost dbname=bazdb

; access to dest database will go with single user
forcedb = host=127.0.0.1 port=300 user=baz password=foo
client_encoding=UNICODE datestyle=ISO connect_query='SELECT
1'
Base Daemon Config
[pgbouncer]
logfile = pgbouncer.log
pidfile = pgbouncer.pid
; ip address or * which means all ip-s
listen_addr = 127.0.0.1
listen_port = 6432
; unix socket is also used for -R.
;unix_socket_dir = /tmp
Authentication

; any, trust, plain, crypt, md5
auth_type = trust
#auth_file = 8.0/main/global/pg_auth
auth_file = etc/userlist.txt
admin_users = user2, someadmin, otheradmin
stats_users = stats, root
Stats Users?
       SHOW HELP|CONFIG|DATABASES|POOLS|CLIENTS|SERVERS|VERSION
       SHOW FDS|SOCKETS|ACTIVE_SOCKETS|LISTS|MEM

pgbouncer=# SHOW CLIENTS;
 type | user | database | state |      addr    | port | local_addr | local_port |     connect_time
------+-------+-----------+--------+-----------+-------+------------+------------+---------------------
 C    | stats | pgbouncer | active | 127.0.0.1 | 47229 | 127.0.0.1 |        6000 | 2011-09-13 17:55:46

* Truncated columns for display purposes
psql 9.0+ Problem?
psql -U stats -p 6432 pgbouncer
psql: ERROR:  Unknown startup parameter

Add to pgbouncer.ini:

ignore_startup_parameters = application_name
Pooling Behavior
pool_mode = statement

server_check_query = select 1
server_check_delay = 10

max_client_conn = 1000
default_pool_size = 20

server_connect_timeout = 15
server_lifetime = 1200
server_idle_timeout = 60
Skytools
Scale-Out Reads
    Clients          Clients                      Clients          Clients




                                  pgBouncer




                               Load Balancer




Read Only Copy   Read Only Copy               Read Only Copy   Read Only Copy




                                  Canonical
                                  Database
PGQ
The Ticker
ticker.ini
[pgqadm]
job_name = pgopen_ticker
db = dbname=pgopen

# how often to run maintenance [seconds]
maint_delay = 600

# how often to check for activity [seconds]
loop_delay = 0.1
logfile = ~/Source/pgopen_skytools/%(job_name)s.log
pidfile = ~/Source/pgopen_skytools/%(job_name)s.pid
Getting PGQ Running
Setup our ticker:
      pgqadm.py ticker.ini install

Run the ticker daemon:
      pgqadm.py ticker.ini ticker -d
Londiste
replication.ini
[londiste]
job_name = pgopen_to_destination

provider_db = dbname=pgopen
subscriber_db = dbname=destination

# it will be used as sql ident so no dots/spaces
pgq_queue_name = pgopen

logfile = ~/Source/pgopen_skytools/%(job_name)s.log
pidfile = ~/Source/pgopen_skytools/%(job_name)s.pid
Install Londiste

londiste.py replication.ini provider install

londiste.py replication.ini subscriber install
Start Replication Daemon


londiste.py replication.ini replay -d
DDL?
Add the Provider
         Tables and Sequences

londiste.py replication.ini provider add public.auth_user
Add the Subscriber
         Tables and Sequences

londiste.py replication.ini subscriber add public.auth_user
Great Success!
PL/Proxy
Scale-Out Reads & Writes

                             plProxy Server




   A-F Server   G-L Server                    M-R Server   S-Z Server
How does it work?
Simple Remote
              Connection
CREATE FUNCTION get_user_email(username text)
RETURNS SETOF text AS $$
    CONNECT 'dbname=remotedb';
    SELECT email FROM users WHERE username = $1;
$$ LANGUAGE plproxy;
Sharded Request

CREATE FUNCTION get_user_email(username text)
RETURNS SETOF text AS $$
    CLUSTER “usercluster”;
    RUN ON hashtext(username);
$$ LANGUAGE plproxy;
Sharding Setup
• Need 3 Functions:
 •   plproxy.get_cluster_partitions(cluster_name
     text)

 •   plproxy.get_cluster_version(cluster_name text)

 •   plproxy.get_cluster_config(in cluster_name text,
                               out key text,
                               out val text)
get_cluster_partitions
CREATE OR REPLACE FUNCTION
plproxy.get_cluster_partitions(cluster_name text)
RETURNS SETOF text AS $$
BEGIN
     IF cluster_name = 'usercluster' THEN
         RETURN NEXT 'dbname=part00 host=127.0.0.1';
         RETURN NEXT 'dbname=part01 host=127.0.0.1';
         RETURN;
     END IF;
     RAISE EXCEPTION 'Unknown cluster';
END;
$$ LANGUAGE plpgsql;
get_cluster_version
CREATE OR REPLACE FUNCTION
plproxy.get_cluster_version(cluster_name text)
RETURNS int4 AS $$
BEGIN
     IF cluster_name = 'usercluster' THEN
         RETURN 1;
     END IF;
     RAISE EXCEPTION 'Unknown cluster';
END;
$$ LANGUAGE plpgsql;
get_cluster_config
CREATE OR REPLACE FUNCTION plproxy.get_cluster_config(
     in cluster_name text,
     out key text,
     out val text)
RETURNS SETOF record AS $$
BEGIN
     -- lets use same config for all clusters
     key := 'connection_lifetime';
     val := 30*60; -- 30m
     RETURN NEXT;
     RETURN;
END;
$$ LANGUAGE plpgsql;
get_cluster_config
          values
• connection_lifetime
• query_timeout
• disable_binary
• keepalive_idle
• keepalive_interval
• keepalive_count
SQL/MED
SQL/Med Cluster
             Definition
CREATE SERVER a_cluster FOREIGN DATA WRAPPER plproxy
        OPTIONS (
                connection_lifetime '1800',
                disable_binary '1',
                p0 'dbname=part00 hostname=127.0.0.1',
                p1 'dbname=part01 hostname=127.0.0.1',
                p2 'dbname=part02 hostname=127.0.0.1',
                p3 'dbname=part03 hostname=127.0.0.1'
                );
PLProxy + SQL/Med
        Behavior

• PL/Proxy will prefer SQL/Med cluster
  definitions over the plproxy.get_* functions
• PL/Proxy will fallback to plproxy.get_*
  functions if there are no SQL/Med clusters
SQL/MED User Mapping

CREATE USER MAPPING FOR bob
     SERVER a_cluster
     OPTIONS (user 'bob', password 'secret');

CREATE USER MAPPING FOR public
     SERVER a_cluster
     OPTIONS (user 'plproxy', password 'foo');
plproxyrc
• plpgsql based api for table based
  management of PL/Proxy
• Used to manage complicated PL/Proxy
  infrastructure @myYearbook
• BSD Licensed
 https://github.com/myYearbook/plproxyrc
“Server-to-Server”

  Postgres    Postgres    Postgres
  Server #1   Server #2   Server #3




              pgBouncer
Scaling PostgreSQL with Skytools
Complex PL/Proxy and pgBouncer
         Environment
  Clients    Local pgBouncer                Load Balancer




  Clients    Local pgBouncer




  Clients    Local pgBouncer    pgBouncer                   pgBouncer




 Postgres                      plProxy Server           plProxy Server
 Server #1

               pgBouncer

 Postgres
                                            Load Balancer
 Server #3

               pgBouncer

 Postgres
 Server #3
Other Tools and
  Methods?
Questions?
Ad

Recommended

Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer
Sameer Kumar
 
Database Tools by Skype
Database Tools by Skype
elliando dias
 
Web Performance Optimization with HTTP/3
Web Performance Optimization with HTTP/3
SangJin Kang
 
Nginx Internals
Nginx Internals
Joshua Zhu
 
Shootout at the AWS Corral
Shootout at the AWS Corral
PostgreSQL Experts, Inc.
 
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
Open Source Consulting
 
초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기
OnGameServer
 
PHP Performance with APC + Memcached
PHP Performance with APC + Memcached
Ford AntiTrust
 
Proxysql ha plam_2016_2_keynote
Proxysql ha plam_2016_2_keynote
Marco Tusa
 
Improving PHP Application Performance with APC
Improving PHP Application Performance with APC
vortexau
 
Velocity 2010 - ATS
Velocity 2010 - ATS
Leif Hedstrom
 
Apache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling Up
Sander Temme
 
Oscon 2010 - ATS
Oscon 2010 - ATS
Leif Hedstrom
 
PostgreSQL: meet your queue
PostgreSQL: meet your queue
Theo Schlossnagle
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
Denish Patel
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
Derek Downey
 
Proxysql sharding
Proxysql sharding
Marco Tusa
 
Proxysql use case scenarios plam 2016
Proxysql use case scenarios plam 2016
Alkin Tezuysal
 
Introduction to memcached
Introduction to memcached
Jurriaan Persyn
 
HBase at Xiaomi
HBase at Xiaomi
HBaseCon
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
Jiangjie Qin
 
Transaction Support in Pulsar 2.5.0
Transaction Support in Pulsar 2.5.0
StreamNative
 
Kafka: Internals
Kafka: Internals
Knoldus Inc.
 
Give Your Site a Boost with Memcache
Give Your Site a Boost with Memcache
Ben Ramsey
 
Real-time, Exactly-once Data Ingestion from Kafka to ClickHouse at eBay
Real-time, Exactly-once Data Ingestion from Kafka to ClickHouse at eBay
Altinity Ltd
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
Ji-Woong Choi
 
Apache Kafka: A high-throughput distributed messaging system @ JCConf 2014
Apache Kafka: A high-throughput distributed messaging system @ JCConf 2014
Chen-en Lu
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
confluent
 
Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQL
elliando dias
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru
Nikolay Samokhvalov
 

More Related Content

What's hot (20)

Proxysql ha plam_2016_2_keynote
Proxysql ha plam_2016_2_keynote
Marco Tusa
 
Improving PHP Application Performance with APC
Improving PHP Application Performance with APC
vortexau
 
Velocity 2010 - ATS
Velocity 2010 - ATS
Leif Hedstrom
 
Apache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling Up
Sander Temme
 
Oscon 2010 - ATS
Oscon 2010 - ATS
Leif Hedstrom
 
PostgreSQL: meet your queue
PostgreSQL: meet your queue
Theo Schlossnagle
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
Denish Patel
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
Derek Downey
 
Proxysql sharding
Proxysql sharding
Marco Tusa
 
Proxysql use case scenarios plam 2016
Proxysql use case scenarios plam 2016
Alkin Tezuysal
 
Introduction to memcached
Introduction to memcached
Jurriaan Persyn
 
HBase at Xiaomi
HBase at Xiaomi
HBaseCon
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
Jiangjie Qin
 
Transaction Support in Pulsar 2.5.0
Transaction Support in Pulsar 2.5.0
StreamNative
 
Kafka: Internals
Kafka: Internals
Knoldus Inc.
 
Give Your Site a Boost with Memcache
Give Your Site a Boost with Memcache
Ben Ramsey
 
Real-time, Exactly-once Data Ingestion from Kafka to ClickHouse at eBay
Real-time, Exactly-once Data Ingestion from Kafka to ClickHouse at eBay
Altinity Ltd
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
Ji-Woong Choi
 
Apache Kafka: A high-throughput distributed messaging system @ JCConf 2014
Apache Kafka: A high-throughput distributed messaging system @ JCConf 2014
Chen-en Lu
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
confluent
 
Proxysql ha plam_2016_2_keynote
Proxysql ha plam_2016_2_keynote
Marco Tusa
 
Improving PHP Application Performance with APC
Improving PHP Application Performance with APC
vortexau
 
Apache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling Up
Sander Temme
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
Denish Patel
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
Derek Downey
 
Proxysql sharding
Proxysql sharding
Marco Tusa
 
Proxysql use case scenarios plam 2016
Proxysql use case scenarios plam 2016
Alkin Tezuysal
 
Introduction to memcached
Introduction to memcached
Jurriaan Persyn
 
HBase at Xiaomi
HBase at Xiaomi
HBaseCon
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
Jiangjie Qin
 
Transaction Support in Pulsar 2.5.0
Transaction Support in Pulsar 2.5.0
StreamNative
 
Give Your Site a Boost with Memcache
Give Your Site a Boost with Memcache
Ben Ramsey
 
Real-time, Exactly-once Data Ingestion from Kafka to ClickHouse at eBay
Real-time, Exactly-once Data Ingestion from Kafka to ClickHouse at eBay
Altinity Ltd
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
Ji-Woong Choi
 
Apache Kafka: A high-throughput distributed messaging system @ JCConf 2014
Apache Kafka: A high-throughput distributed messaging system @ JCConf 2014
Chen-en Lu
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
confluent
 

Viewers also liked (20)

Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQL
elliando dias
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru
Nikolay Samokhvalov
 
Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011
Lennin Caro
 
PostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidad
Santiago Zarate
 
Go replicator
Go replicator
Command Prompt., Inc
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
Command Prompt., Inc
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with Tungsten
Command Prompt., Inc
 
Backup and-recovery2
Backup and-recovery2
Command Prompt., Inc
 
Pg migrator
Pg migrator
Command Prompt., Inc
 
configuring a warm standby, the easy way
configuring a warm standby, the easy way
Command Prompt., Inc
 
Python utilities for data presentation
Python utilities for data presentation
Command Prompt., Inc
 
A Practical Multi-Tenant Cluster
A Practical Multi-Tenant Cluster
Command Prompt., Inc
 
Replicacion Postgresql
Replicacion Postgresql
jockbrera
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
Command Prompt., Inc
 
PostgreSQL replication
PostgreSQL replication
NTT DATA OSS Professional Services
 
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Command Prompt., Inc
 
Dba PostgreSQL desde básico a avanzado parte2
Dba PostgreSQL desde básico a avanzado parte2
EQ SOFT EIRL
 
Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014
EDB
 
Presentación Live CDs - 2005
Presentación Live CDs - 2005
Lenin Hernandez
 
Alta disponibilidad-postgres
Alta disponibilidad-postgres
Lenin Hernandez
 
Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQL
elliando dias
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru
Nikolay Samokhvalov
 
Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011
Lennin Caro
 
PostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidad
Santiago Zarate
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
Command Prompt., Inc
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with Tungsten
Command Prompt., Inc
 
configuring a warm standby, the easy way
configuring a warm standby, the easy way
Command Prompt., Inc
 
Python utilities for data presentation
Python utilities for data presentation
Command Prompt., Inc
 
Replicacion Postgresql
Replicacion Postgresql
jockbrera
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
Command Prompt., Inc
 
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Command Prompt., Inc
 
Dba PostgreSQL desde básico a avanzado parte2
Dba PostgreSQL desde básico a avanzado parte2
EQ SOFT EIRL
 
Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014
EDB
 
Presentación Live CDs - 2005
Presentación Live CDs - 2005
Lenin Hernandez
 
Alta disponibilidad-postgres
Alta disponibilidad-postgres
Lenin Hernandez
 
Ad

Similar to Scaling PostgreSQL with Skytools (20)

My Sql Proxy
My Sql Proxy
Liu Lizhi
 
MySQL Proxy
MySQL Proxy
Manikanda kumar
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
elliando dias
 
Galera Multi Master Synchronous My S Q L Replication Clusters
Galera Multi Master Synchronous My S Q L Replication Clusters
PerconaPerformance
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Moskva Architecture Highload
Moskva Architecture Highload
Ontico
 
Scalable Architecture 101
Scalable Architecture 101
ConFoo
 
Small Overview of Skype Database Tools
Small Overview of Skype Database Tools
elliando dias
 
ALOHA Load Balancer - Virtual Appliance
ALOHA Load Balancer - Virtual Appliance
EXCELIANCE
 
"Spin-up pgbouncer for fun and profit", Vitaliy Kharytonskiy
"Spin-up pgbouncer for fun and profit", Vitaliy Kharytonskiy
Fwdays
 
EOUG95 - Client Server Very Large Databases - Presentation
EOUG95 - Client Server Very Large Databases - Presentation
David Walker
 
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
Rakuten Group, Inc.
 
Creating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at Scale
Sean Chittenden
 
ALOHA Load Balancer - Rackable Appliance
ALOHA Load Balancer - Rackable Appliance
EXCELIANCE
 
Scale Fail: How I Learned to Love the Downtime
Scale Fail: How I Learned to Love the Downtime
PostgreSQL Experts, Inc.
 
Modernización del manejo de datos con v fabric
Modernización del manejo de datos con v fabric
Software Guru
 
Asko Oja Moskva Architecture Highload
Asko Oja Moskva Architecture Highload
Ontico
 
Gmr Highload Presentation Revised
Gmr Highload Presentation Revised
Ontico
 
Gmr Highload Presentation
Gmr Highload Presentation
Ontico
 
HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18
Derek Downey
 
My Sql Proxy
My Sql Proxy
Liu Lizhi
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
elliando dias
 
Galera Multi Master Synchronous My S Q L Replication Clusters
Galera Multi Master Synchronous My S Q L Replication Clusters
PerconaPerformance
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Moskva Architecture Highload
Moskva Architecture Highload
Ontico
 
Scalable Architecture 101
Scalable Architecture 101
ConFoo
 
Small Overview of Skype Database Tools
Small Overview of Skype Database Tools
elliando dias
 
ALOHA Load Balancer - Virtual Appliance
ALOHA Load Balancer - Virtual Appliance
EXCELIANCE
 
"Spin-up pgbouncer for fun and profit", Vitaliy Kharytonskiy
"Spin-up pgbouncer for fun and profit", Vitaliy Kharytonskiy
Fwdays
 
EOUG95 - Client Server Very Large Databases - Presentation
EOUG95 - Client Server Very Large Databases - Presentation
David Walker
 
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
Rakuten Group, Inc.
 
Creating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at Scale
Sean Chittenden
 
ALOHA Load Balancer - Rackable Appliance
ALOHA Load Balancer - Rackable Appliance
EXCELIANCE
 
Scale Fail: How I Learned to Love the Downtime
Scale Fail: How I Learned to Love the Downtime
PostgreSQL Experts, Inc.
 
Modernización del manejo de datos con v fabric
Modernización del manejo de datos con v fabric
Software Guru
 
Asko Oja Moskva Architecture Highload
Asko Oja Moskva Architecture Highload
Ontico
 
Gmr Highload Presentation Revised
Gmr Highload Presentation Revised
Ontico
 
Gmr Highload Presentation
Gmr Highload Presentation
Ontico
 
HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18
Derek Downey
 
Ad

Recently uploaded (20)

Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 

Scaling PostgreSQL with Skytools

  • 1. Scaling with SkyTools & More Scaling-Out Postgres with Skype’s Open-Source Toolset Gavin M. Roy September 14th, 2011
  • 2. About Me • PostgreSQL ~ 6.5 • CTO @myYearbook.com • Scaled initial infrastructure • Not as involved day-to-day database operational and development • Twitter: @Crad
  • 4. Concurrency Requests per Second 6am 8am 10am 12pm 2pm 4pm 6pm 8pm 10pm 12am 2am 4am 6am Hourly breakdown
  • 5. Increasing Size-On-Disk Size in GB Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
  • 8. Tuples, Indexes, Overhead
  • 9. Table Size + Size of all combined Indexes Relations Indexes
  • 10. Constraints • Available Memory • Disk Speed • IO Bus Speed
  • 11. Keep it in memory.
  • 12. Get Fast Disks & I/O.
  • 13. Process Forking + Locks
  • 16. Apache+PHP One connection per backend for each pg_connect
  • 18. ODBC One connection to Postgres per ODBC connection
  • 19. Master Process Lock Stats Collector Contention? Autovacuum Each backend for a connected Wall Writer client has to check for locks Wall Writer Connection Client Connection Backend
  • 20. Master Process New Client Stats Collector Connection? Autovacuum Wall Writer Access Share Access Exclusive Wall Writer Exclusive Share Connection Client Connection Backend Share Row Exclusive Share Update Connection Client Connection Row Share Backend Row Exclusive
  • 21. Master Process Stats Collector Too many Autovacuum connections? Wall Writer Wall Writer Slow performance Connection Client Connection Backend Connection Client Connection Backend ... Connection Client Connection Backend
  • 22. 250 Apache Backends x 1 Connection per Backend x 250 Servers = 62,500 Connections
  • 30. Connection Pooling Clients Clients Clients Hundreds Hundreds Hundreds pgBouncer Tens Tens Tens Postgres Postgres Postgres Server #1 Server #2 Server #3
  • 31. Add Local Pooling Clients Clients Clients Hundreds Hundreds Hundreds Local pgBouncer Local pgBouncer Local pgBouncer Tens Tens Tens pgBouncer Tens Tens Tens Postgres Postgres Postgres Server #1 Server #2 Server #3
  • 32. Easy to run Usage: pgbouncer [OPTION]... config.ini -d, --daemon Run in background (as a daemon) -R, --restart Do a online restart -q, --quiet Run quietly -v, --verbose Increase verbosity -u, --user=<username> Assume identity of <username> -V, --version Show version -h, --help Show this help screen and exit
  • 35. Specifying Connections [databases] ; foodb over unix socket foodb = ; redirect bardb to bazdb on localhost bardb = host=localhost dbname=bazdb ; access to dest database will go with single user forcedb = host=127.0.0.1 port=300 user=baz password=foo client_encoding=UNICODE datestyle=ISO connect_query='SELECT 1'
  • 36. Base Daemon Config [pgbouncer] logfile = pgbouncer.log pidfile = pgbouncer.pid ; ip address or * which means all ip-s listen_addr = 127.0.0.1 listen_port = 6432 ; unix socket is also used for -R. ;unix_socket_dir = /tmp
  • 37. Authentication ; any, trust, plain, crypt, md5 auth_type = trust #auth_file = 8.0/main/global/pg_auth auth_file = etc/userlist.txt admin_users = user2, someadmin, otheradmin stats_users = stats, root
  • 38. Stats Users? SHOW HELP|CONFIG|DATABASES|POOLS|CLIENTS|SERVERS|VERSION SHOW FDS|SOCKETS|ACTIVE_SOCKETS|LISTS|MEM pgbouncer=# SHOW CLIENTS; type | user | database | state | addr | port | local_addr | local_port | connect_time ------+-------+-----------+--------+-----------+-------+------------+------------+--------------------- C | stats | pgbouncer | active | 127.0.0.1 | 47229 | 127.0.0.1 | 6000 | 2011-09-13 17:55:46 * Truncated columns for display purposes
  • 39. psql 9.0+ Problem? psql -U stats -p 6432 pgbouncer psql: ERROR:  Unknown startup parameter Add to pgbouncer.ini: ignore_startup_parameters = application_name
  • 40. Pooling Behavior pool_mode = statement server_check_query = select 1 server_check_delay = 10 max_client_conn = 1000 default_pool_size = 20 server_connect_timeout = 15 server_lifetime = 1200 server_idle_timeout = 60
  • 42. Scale-Out Reads Clients Clients Clients Clients pgBouncer Load Balancer Read Only Copy Read Only Copy Read Only Copy Read Only Copy Canonical Database
  • 43. PGQ
  • 45. ticker.ini [pgqadm] job_name = pgopen_ticker db = dbname=pgopen # how often to run maintenance [seconds] maint_delay = 600 # how often to check for activity [seconds] loop_delay = 0.1 logfile = ~/Source/pgopen_skytools/%(job_name)s.log pidfile = ~/Source/pgopen_skytools/%(job_name)s.pid
  • 46. Getting PGQ Running Setup our ticker: pgqadm.py ticker.ini install Run the ticker daemon: pgqadm.py ticker.ini ticker -d
  • 48. replication.ini [londiste] job_name = pgopen_to_destination provider_db = dbname=pgopen subscriber_db = dbname=destination # it will be used as sql ident so no dots/spaces pgq_queue_name = pgopen logfile = ~/Source/pgopen_skytools/%(job_name)s.log pidfile = ~/Source/pgopen_skytools/%(job_name)s.pid
  • 49. Install Londiste londiste.py replication.ini provider install londiste.py replication.ini subscriber install
  • 50. Start Replication Daemon londiste.py replication.ini replay -d
  • 51. DDL?
  • 52. Add the Provider Tables and Sequences londiste.py replication.ini provider add public.auth_user
  • 53. Add the Subscriber Tables and Sequences londiste.py replication.ini subscriber add public.auth_user
  • 56. Scale-Out Reads & Writes plProxy Server A-F Server G-L Server M-R Server S-Z Server
  • 57. How does it work?
  • 58. Simple Remote Connection CREATE FUNCTION get_user_email(username text) RETURNS SETOF text AS $$ CONNECT 'dbname=remotedb'; SELECT email FROM users WHERE username = $1; $$ LANGUAGE plproxy;
  • 59. Sharded Request CREATE FUNCTION get_user_email(username text) RETURNS SETOF text AS $$ CLUSTER “usercluster”; RUN ON hashtext(username); $$ LANGUAGE plproxy;
  • 60. Sharding Setup • Need 3 Functions: • plproxy.get_cluster_partitions(cluster_name text) • plproxy.get_cluster_version(cluster_name text) • plproxy.get_cluster_config(in cluster_name text, out key text, out val text)
  • 61. get_cluster_partitions CREATE OR REPLACE FUNCTION plproxy.get_cluster_partitions(cluster_name text) RETURNS SETOF text AS $$ BEGIN IF cluster_name = 'usercluster' THEN RETURN NEXT 'dbname=part00 host=127.0.0.1'; RETURN NEXT 'dbname=part01 host=127.0.0.1'; RETURN; END IF; RAISE EXCEPTION 'Unknown cluster'; END; $$ LANGUAGE plpgsql;
  • 62. get_cluster_version CREATE OR REPLACE FUNCTION plproxy.get_cluster_version(cluster_name text) RETURNS int4 AS $$ BEGIN IF cluster_name = 'usercluster' THEN RETURN 1; END IF; RAISE EXCEPTION 'Unknown cluster'; END; $$ LANGUAGE plpgsql;
  • 63. get_cluster_config CREATE OR REPLACE FUNCTION plproxy.get_cluster_config( in cluster_name text, out key text, out val text) RETURNS SETOF record AS $$ BEGIN -- lets use same config for all clusters key := 'connection_lifetime'; val := 30*60; -- 30m RETURN NEXT; RETURN; END; $$ LANGUAGE plpgsql;
  • 64. get_cluster_config values • connection_lifetime • query_timeout • disable_binary • keepalive_idle • keepalive_interval • keepalive_count
  • 66. SQL/Med Cluster Definition CREATE SERVER a_cluster FOREIGN DATA WRAPPER plproxy OPTIONS ( connection_lifetime '1800', disable_binary '1', p0 'dbname=part00 hostname=127.0.0.1', p1 'dbname=part01 hostname=127.0.0.1', p2 'dbname=part02 hostname=127.0.0.1', p3 'dbname=part03 hostname=127.0.0.1' );
  • 67. PLProxy + SQL/Med Behavior • PL/Proxy will prefer SQL/Med cluster definitions over the plproxy.get_* functions • PL/Proxy will fallback to plproxy.get_* functions if there are no SQL/Med clusters
  • 68. SQL/MED User Mapping CREATE USER MAPPING FOR bob SERVER a_cluster OPTIONS (user 'bob', password 'secret'); CREATE USER MAPPING FOR public SERVER a_cluster OPTIONS (user 'plproxy', password 'foo');
  • 69. plproxyrc • plpgsql based api for table based management of PL/Proxy • Used to manage complicated PL/Proxy infrastructure @myYearbook • BSD Licensed https://github.com/myYearbook/plproxyrc
  • 70. “Server-to-Server” Postgres Postgres Postgres Server #1 Server #2 Server #3 pgBouncer
  • 72. Complex PL/Proxy and pgBouncer Environment Clients Local pgBouncer Load Balancer Clients Local pgBouncer Clients Local pgBouncer pgBouncer pgBouncer Postgres plProxy Server plProxy Server Server #1 pgBouncer Postgres Load Balancer Server #3 pgBouncer Postgres Server #3
  • 73. Other Tools and Methods?