DB Connection Pool

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

DB Connection Pool

for MySQL
adzmely mansor
adzmely@nexoprima.com
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
adzmely@nexoprima.com

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy