100% found this document useful (1 vote)
243 views25 pages

DB Connection Pool

This document discusses database connection pools and their benefits. It provides an introduction to database connection pools and demonstrates their use with ProxySQL and MariaDB. The key benefits of connection pools are that they reuse existing database connections and reduce overhead by establishing persistent connections rather than opening a new connection for each query. This allows web applications to handle many more requests without being limited by the maximum number of connections allowed by the database. The demonstration shows how connection pooling with ProxySQL improves performance on sysbench tests compared to making direct connections to the database for each query.

Uploaded by

Adzmely Mansor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
243 views25 pages

DB Connection Pool

This document discusses database connection pools and their benefits. It provides an introduction to database connection pools and demonstrates their use with ProxySQL and MariaDB. The key benefits of connection pools are that they reuse existing database connections and reduce overhead by establishing persistent connections rather than opening a new connection for each query. This allows web applications to handle many more requests without being limited by the maximum number of connections allowed by the database. The demonstration shows how connection pooling with ProxySQL improves performance on sysbench tests compared to making direct connections to the database for each query.

Uploaded by

Adzmely Mansor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

DB Connection Pool

for MySQL
adzmely mansor
[email protected]
About Me
adzmely mansor
founder & employee @

sdn. bhd.
and Myths
About Me

X
i Introductory

• benefit of having DB connection pool

• not covering installation/configuration


of systems/apps used in this
presentation

• a simple introduction to DB Connection


Pool + Demo in 25 mins
Connection Pool?
1 Connection Pool

• Traditionally without connection pool,


dynamic web pages:

• open connection to DB as required

• close the connection when done


1 Connection Pool

• With connection pool:

• reuse existing connection from the


pool

• establishes new connection when no


connections pool are available
1 Connection Pool
• Is a cache of database connections

• Reusable : reuse for future requests

• reduce overhead of initiating connection for


each individual request

• Why ? Initiating a DB connection is:

• costly

• resource intensive
2 Direct DB Connection
SQL
SQL SQL
SQL
SQL DB
SQL
Application(s)

SQL
SQL SQL SQL

SQL
SQL
SQL
SQL

}
}

Application side making Connection


direct connections Threads
to DB
2 Direct DB Connection
• busy web site/application will suffer

• opening & closing connection + thread


initiation on DB side is EXPENSIVE

• threads created are not persistent across


web application / HTTP requests

• your DB has limits

• max connections
2 Direct DB Connection

• example of direct DB connection:

• sysbench demo:

• each sql having it s own


connection thread
3 DB Connection Pool
SQL
SQL SQL
SQL
SQL DB
SQL
Application(s)

SQL
SQL SQL SQL SQL SQL SQL SQL SQL SQL

SQL SQL SQL SQL SQL SQL

SQL SQL SQL SQL SQL SQL

SQL
SQL
SQL
SQL
}

}
Application making ProxySQL ProxySQL to DB
connection via SQLProxy Connection Threads Persistent Threads
(green threads)
3 Green Threads

• Green threads emulate multi-threaded


environments

• without relying on any native OS


capabilities,

• and they are managed in user space


instead of kernel space
3 DB Connection Pool
• using connection proxy such as ProxySQL

• lightweight - green threads (user space


instead of kernel)

• easily can handle hundreds of


thousands connections and beyond

• persistent connections to DB
3 DB Connection Pool

• example of DB Connection Pool using


ProxySQL

• sysbench demo:

• sysbench test via ProxySQL


4 Demo/Tools Used

DB: DB Pool:
mariaDB 5.5.52 proxySQL 1.4.2
http://mariadb.org http://proxysql.com
GPL Licence GPL License

OS: Bench/Perf Tool:


Centos 7.2.1511 sysbench 1.0.8
http://centos.org
GPL License
GPL Licence
4 Demo VMs/Net Layout

mariaDB proxySQL

172.16.1.1 172.16.1.2
mariadb proxySQL
port: 3306 internal network port: 6602 - management
inside VM port: 6603 - proxy port
4 Demo VMs/Net Layout

mariaDB proxySQL

port 3306 port 6603


proxy to
MariaDB

port 6602
proxySQL Admin
i Load Balance ProxySQL

mariaDB proxySQL

port 3306 port 6603


proxy to
t 3 3 06
po r MariaDB

3 06
t3 port 6602
por
proxySQL Admin
4 Demo: proxySQL Admin
• advance configuration with 0
downtime
• set backend max_connections=1
• run sysbench
• set backend max_connections=50
• run sysbench
• monitoring
4 Demo: Sysbench 01
mariaDB proxySQL
port 3306
Single DB thread for all SQLs

SQL

mariaDB SQL
proxySQL
SQL

port 3306 SQL

DB initiation
for each SQL SQL
SQL
4 Demo: sysbench

• running more than 1 sysbench


thread directly to mariaDB with
connection initiation for each SQL
event
4 Demo: Sysbench 02/03
mariaDB proxySQL SQL
SQL

port 3306 port 6033 SQL

SQL SQL SQL SQL


SQL
single persistent
db conn

SQL
SQL

mariaDB proxySQL SQL

port 3306 SQL

SQL SQL SQL SQL


SQL SQL SQL SQL
port 6033 SQL

SQL SQL SQL SQL


SQL

SQL SQL SQL SQL

50 persistent
SQL
db conns
SQL
4 Demo: sysbench

• running more than 1 sysbench


thread via ProxySQL with
connection initiation for each SQL
event
Thank You
adzmely mansor
[email protected]

You might also like