SlideShare a Scribd company logo
Highly Available PHP/MySQL
Applications with mysqlnd
Jervin Real
PHP-UGPH, June 2014
Highly Available Applications
• … how much your application is able to serve its end users
within a time period
Highly Available Applications
• … how much your application is able to serve its end users
within a time period
• Usually referred to as 99[..]% uptime
Highly Available Applications
• … how much your application is able to serve its end users
within a time period
• Usually referred to as 99[..]% uptime
• It actually depends on whose perspective
Highly Available Applications
Keep PHP<>MySQL downtime to a minimum
WTF are you saying? I’m a “devloper"!
No no no no no no!
Lack of knowledge
Limited resources
How?
MySQL
MySQL HA
• MySQL Native Replication (Single Primary)
MySQL HA
• MySQL Native Replication (Single Primary)
• MySQL Native Replication (Multi-Master)
MySQL HA
• MySQL Native Replication (Single Primary)
• MySQL Native Replication (Multi-Master)
• MySQL NDB Cluster
MySQL HA
• MySQL Native Replication (Single Primary)
• MySQL Native Replication (Multi-Master)
• MySQL NDB Cluster
• Galera based
MySQL HA
• MySQL Native Replication (Single Primary)
• MySQL Native Replication (Multi-Master)
• MySQL NDB Cluster
• Galera based
• Percona XtraDB Cluster
• MariaDB Galera Cluster
• MySQL+Galera
MySQL HA
• MySQL Native Replication (Single Primary)
• MySQL Native Replication (Multi-Master)
• MySQL NDB Cluster
• Galera based
• Percona XtraDB Cluster
• MariaDB Galera Cluster
• MySQL+Galera
• Tungsten Replicator
MySQL HA
• MySQL Native Replication (Single Primary)
• MySQL Native Replication (Multi-Master)
• MySQL NDB Cluster
• Galera based
• Percona XtraDB Cluster
• MariaDB Galera Cluster
• MySQL+Galera
• Tungsten Replicator
• … and many more
• MySQL Master HA
MySQL HA (External Support)
MySQL HA (External Support)
• MySQL Master HA
• Percona Replication Manager (Pacemaker)
MySQL HA (External Support)
• MySQL Master HA
• Percona Replication Manager (Pacemaker)
• Haproxy
MySQL HA (External Support)
• MySQL Master HA
• Percona Replication Manager (Pacemaker)
• Haproxy
• Load Balancers
MySQL HA (External Support)
• MySQL Master HA
• Percona Replication Manager (Pacemaker)
• Haproxy
• Load Balancers
• MySQL Multi Master
MySQL HA (External Support)
• MySQL Master HA
• Percona Replication Manager (Pacemaker)
• Haproxy
• Load Balancers
• MySQL Multi Master
PHP (Application)
HA via Application
• Traditionally complex to implement
• Unnecessary overhead
• No single point of failure
mysqlnd
mysqlnd
• MySQL Native Driver
mysqlnd
• MySQL Native Driver
• Written C (as all extensions should be!)
mysqlnd
• MySQL Native Driver
• Written C (as all extensions should be!)
• MySQL Client Libraries no more
mysqlnd
• MySQL Native Driver
• Written C (as all extensions should be!)
• MySQL Client Libraries no more
• Smaller memory footprint in many cases
mysqlnd
• MySQL Native Driver
• Written C (as all extensions should be!)
• MySQL Client Libraries no more
• Smaller memory footprint in many cases
• Performance statistics
mysqlnd
• MySQL Native Driver
• Written C (as all extensions should be!)
• MySQL Client Libraries no more
• Smaller memory footprint in many cases
• Performance statistics
• Compression
mysqlnd
• MySQL Native Driver
• Written C (as all extensions should be!)
• MySQL Client Libraries no more
• Smaller memory footprint in many cases
• Performance statistics
• Compression
• Plugins
mysqlnd Plugins
• mysqlnd_qc - query result cache
mysqlnd Plugins
• mysqlnd_qc - query result cache
• mysqlnd_mux - connection multiplexing
mysqlnd Plugins
• mysqlnd_qc - query result cache
• mysqlnd_mux - connection multiplexing
• mysqlnd_uh - user handler
mysqlnd Plugins
• mysqlnd_qc - query result cache
• mysqlnd_mux - connection multiplexing
• mysqlnd_uh - user handler
• mysqlnd_memcache - Memcache (MySQL interface)
mysqlnd Plugins
• mysqlnd_qc - query result cache
• mysqlnd_mux - connection multiplexing
• mysqlnd_uh - user handler
• mysqlnd_memcache - Memcache (MySQL interface)
• mysqlnd_ms - replication and load balancing
mysqlnd_ms
mysqlnd_ms Supported Clusters
• All previously mentioned with few limitations
Limitations (Master-Slave)
• Master is a single point of failure
• Need external help for failover
• . . or, shoot the other node in the foot, this is still HA!
Limitations (Master-Slave)
Limitations (Master-Slave)
Limitations (Master-Slave)
Limitations (Master-Master)
• Risky, even if you try segregating writes per master you
can still lose data
Limitations (Master-Master)
db1
db1
Limitations (Master-Master)
db1
db1
Limitations (Master-Master)
db2
db1
Limitations (Master-Master)
db1 + db2
• Not good if sync_binlog = 0 AND/OR innodb_flush_log_at_trx_commit <> 1
• Not really recommended in general, use appropriate technologies
instead
Some More Limitations
• Lazy connections is on by default
• Each request will create its own connections when needed,
persistent connections may be required
• https://bugs.php.net/bug.php?id=67564
• https://bugs.php.net/bug.php?id=67565
• https://bugs.php.net/bug.php?id=67574
• Be careful with multi-statements and read-write splitting,
they are likely to be executed on slave!
SELECT  *  FROM  tbl;  DELETE  FROM  tbl;
• Single Primary - one writable node
• Multiple Primary - all nodes writable
mysqlnd_ms Supported Clusters
• Master-Slave
mysqlnd_ms Supported Clusters
• Master-Slave
• Declare 2 clusters
mysqlnd_ms Supported Clusters
• Master-Slave
• Declare 2 clusters
• When primary fails, mark it permanently dead and switch
to secondary
mysqlnd_ms Supported Clusters
• Master-Slave
• Declare 2 clusters
• When primary fails, mark
it permanently dead and
switch to secondary
{  
    "primary":  {  
        "master":  {  
            "master_1":  {  
                "host":  "127.0.0.1",  
                "port":  33001  
            }  
        },  
        "slave":  {  
            "slave_0":  {  
                "host":  "127.0.0.1",  
                "port":  33002  
            }  
        }  
    },  
    "standby":  {  
        "master":  {  
            "master_1":  {  
                "host":  "127.0.0.1",  
                "port":  33002  
            }  
        },  
        "slave":  {  
        }  
    }  
}
mysqlnd_ms Supported Clusters
• Master-Slave
• Declare 2 clusters
• When primary fails, mark
it permanently dead and
switch to secondary
• Works better with
master-master!
{  
    "primary":  {  
        "master":  {  
            "master_1":  {  
                "host":  "127.0.0.1",  
                "port":  33001  
            }  
        },  
        "slave":  {  
            "slave_0":  {  
                "host":  "127.0.0.1",  
                "port":  33002  
            }  
        }  
    },  
    "standby":  {  
        "master":  {  
            "master_1":  {  
                "host":  "127.0.0.1",  
                "port":  33002  
            }  
        },  
        "slave":  {  
        }  
    }  
}
mysqlnd_ms Supported Clusters
• Master-Slave Demo
• https://github.com/dotmanila/demo-me/phpugph201407/
• master-slave.ini
• mysqlnd_ms_ms.ini
• master-slave.php
mysqlnd_ms Supported Clusters
• Multi-Masters (NDB, Galera)
• Declare all nodes as masters
mysqlnd_ms Supported Clusters
• Multi-Masters (NDB, Galera)
mysqlnd_ms Supported Clusters
• Multi-Masters (NDB,
Galera)
• Declare all nodes as
masters
mysqlnd_ms Supported Clusters
  {  
      "primary":  {  
          "master":  {  
              "master_1":  {  
                  "host":  "192.168.56.44",  
                  "port":  "3306"  
              },  
              "master_2":  {  
                  "host":  "192.168.56.43",  
                  "port":  "3306"  
              },  
              "master_3":  {  
                  "host":  "192.168.56.42",  
                  "port":  "3306"  
              }  
          },  
          "slave":  {  },  
          "filters":  {  "random":  [  ]  },  
          "failover":  {    
              "strategy":  "loop_before_master",    
              "remember_failed":  true    
          }  
      }  
  }
• Multi-Masters (NDB,
Galera)
mysqlnd_ms Supported Clusters
  {  
      "primary":  {  
          "master":  {  
              "master_1":  {  
                  "host":  "192.168.56.44",  
                  "port":  "3306"  
              },  
              "master_2":  {  
                  "host":  "192.168.56.43",  
                  "port":  "3306"  
              },  
              "master_3":  {  
                  "host":  "192.168.56.42",  
                  "port":  "3306"  
              }  
          },  
          "slave":  {  },  
          "filters":  {  "random":  [  ]  },  
          "failover":  {    
              "strategy":  "loop_before_master",    
              "remember_failed":  true    
          }  
      }  
  }
• Multi-Masters (NDB,
Galera)
• Declare all nodes as
masters
• roundrobin - single node
writer (first node in
config)
mysqlnd_ms Supported Clusters
  {  
      "primary":  {  
          "master":  {  
              "master_1":  {  
                  "host":  "192.168.56.44",  
                  "port":  "3306"  
              },  
              "master_2":  {  
                  "host":  "192.168.56.43",  
                  "port":  "3306"  
              },  
              "master_3":  {  
                  "host":  "192.168.56.42",  
                  "port":  "3306"  
              }  
          },  
          "slave":  {  },  
          "filters":  {  "random":  [  ]  },  
          "failover":  {    
              "strategy":  "loop_before_master",    
              "remember_failed":  true    
          }  
      }  
  }
• Multi-Masters (NDB,
Galera)
• Declare all nodes as
masters
• roundrobin - single node
writer (first node in
config)
• random - all nodes
mysqlnd_ms Supported Clusters
  {  
      "primary":  {  
          "master":  {  
              "master_1":  {  
                  "host":  "192.168.56.44",  
                  "port":  "3306"  
              },  
              "master_2":  {  
                  "host":  "192.168.56.43",  
                  "port":  "3306"  
              },  
              "master_3":  {  
                  "host":  "192.168.56.42",  
                  "port":  "3306"  
              }  
          },  
          "slave":  {  },  
          "filters":  {  "random":  [  ]  },  
          "failover":  {    
              "strategy":  "loop_before_master",    
              "remember_failed":  true    
          }  
      }  
  }
• Multi-Masters (NDB,
Galera)
• Declare all nodes as
masters
• roundrobin - single node
writer (first node in
config)
• random - all nodes
• remember_failed is not
what it says it is
  {  
      "primary":  {  
          "master":  {  
              "master_1":  {  
                  "host":  "192.168.56.44",  
                  "port":  "3306"  
              },  
              "master_2":  {  
                  "host":  "192.168.56.43",  
                  "port":  "3306"  
              },  
              "master_3":  {  
                  "host":  "192.168.56.42",  
                  "port":  "3306"  
              }  
          },  
          "slave":  {  },  
          "filters":  {  "random":  [  ]  },  
          "failover":  {    
              "strategy":  "loop_before_master",    
              "remember_failed":  true    
          }  
      }  
  }
mysqlnd_ms Supported Clusters
• Master-Master Demo
• https://github.com/dotmanila/demo-me/phpugph201407/
• master-master.ini
• mysqlnd_ms_mm.ini
• master-master.php
mysqlnd_ms Supported Clusters
Am I Using mysqlnd? (rpm)
[revin@forge  ~]$  rpm  -­‐q  php-­‐mysql.x86_64  -­‐-­‐requires  
[…]  
libmysqlclient_r.so.16()(64bit)  
libmysqlclient_r.so.16(libmysqlclient_16)(64bit)  
libmysqlclient.so.16()(64bit)  
libmysqlclient.so.16(libmysqlclient_16)(64bit)  
[…]
[revin@forge  ~]$  rpm  -­‐q  php-­‐mysqlnd.x86_64  -­‐-­‐requires  
php-­‐pdo(x86-­‐64)  =  5.4.30-­‐36.el6.art  
rpmlib(VersionedDependencies)  <=  3.0.3-­‐1  
rpmlib(FileDigests)  <=  4.6.0-­‐1  
rpmlib(PayloadFilesHavePrefix)  <=  4.0-­‐1  
rpmlib(CompressedFileNames)  <=  3.0.4-­‐1  
libc.so.6()(64bit)  
libc.so.6(GLIBC_2.2.5)(64bit)  
libc.so.6(GLIBC_2.3.4)(64bit)  
libc.so.6(GLIBC_2.4)(64bit)  
libpthread.so.0()(64bit)  
libpthread.so.0(GLIBC_2.2.5)(64bit)  
rtld(GNU_HASH)  
rpmlib(PayloadIsXz)  <=  5.2-­‐1
Am I Using mysqlnd? (rpm)
[revin@forge  ~]$  php  -­‐i  
[…]  
!
mysql  
!
MySQL  Support  =>  enabled  
Active  Persistent  Links  =>  0  
Active  Links  =>  0  
Client  API  version  =>  5.1.59  
MYSQL_MODULE_TYPE  =>  external  
MYSQL_SOCKET  =>  /var/lib/mysql/mysql.sock  
MYSQL_INCLUDE  =>  -­‐I/usr/include/mysql  
MYSQL_LIBS  =>  -­‐L/usr/lib64/mysql  -­‐lmysqlclient
Am I Using mysqlnd? (phpinfo)
[revin@forge  ~]$  php  -­‐i  
[…]  
!
mysqlnd  
!
mysqlnd  =>  enabled  
Version  =>  mysqlnd  5.0.10  -­‐  20111026  -­‐  $Id:  c85105d7c6f7d70d609bb4c000257868a40840ab  $  
Compression  =>  supported  
SSL  =>  supported  
Command  buffer  size  =>  4096  
Read  buffer  size  =>  32768  
Read  timeout  =>  31536000  
Collecting  statistics  =>  Yes  
Collecting  memory  statistics  =>  No  
Tracing  =>  n/a  
Loaded  plugins  =>  mysqlnd,example,debug_trace,  
   auth_plugin_mysql_native_password,  
   auth_plugin_mysql_clear_password  
API  Extensions  =>  mysql,mysqli,pdo_mysql
Am I Using mysqlnd? (phpinfo)
Conclusion
• Yes, we can achieve HA with mysqlnd_ms
• Not for the faint of heart
• Do not rely on for HA (writes) on critical production
systems
• Good for intended use case, rw-splitting
Highly Available MySQL/PHP Applications with mysqlnd
Q&A
• http://dotmanila.com/blog/
• http://www.mysqlperformanceblog.com/
• @dotmanila
Percona is Hiring!!
http://www.percona.com/about-us/careers/open-positions
$t  =  true  AND  false;  echo  (int)  $t;

More Related Content

What's hot (20)

ODP
Built-in query caching for all PHP MySQL extensions/APIs
Ulf Wendel
 
PDF
Best practices for MySQL High Availability
Colin Charles
 
ODP
Vote NO for MySQL
Ulf Wendel
 
PPTX
MariaDB Galera Cluster
Abdul Manaf
 
ODP
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
Ulf Wendel
 
PDF
Scaling with sync_replication using Galera and EC2
Marco Tusa
 
PDF
Introduction to Galera Cluster
Codership Oy - Creators of Galera Cluster
 
DOCX
Master master vs master-slave database
Wipro
 
PDF
DIY: A distributed database cluster, or: MySQL Cluster
Ulf Wendel
 
ODP
MySQL 5.6 Global Transaction Identifier - Use case: Failover
Ulf Wendel
 
ODP
The mysqlnd replication and load balancing plugin
Ulf Wendel
 
PDF
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Kenny Gryp
 
ODP
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
Ulf Wendel
 
ODP
PoC: Using a Group Communication System to improve MySQL Replication HA
Ulf Wendel
 
KEY
Intro to PECL/mysqlnd_ms (4/7/2011)
Chris Barber
 
PPTX
MySQL Multi Master Replication
Moshe Kaplan
 
PDF
Galera cluster for high availability
Mydbops
 
PPT
Codership's galera cluster installation and quickstart webinar march 2016
Sakari Keskitalo
 
PDF
Automate MariaDB Galera clusters deployments with Ansible
Federico Razzoli
 
PDF
Choosing a MySQL High Availability solution - Percona Live UK 2011
Henrik Ingo
 
Built-in query caching for all PHP MySQL extensions/APIs
Ulf Wendel
 
Best practices for MySQL High Availability
Colin Charles
 
Vote NO for MySQL
Ulf Wendel
 
MariaDB Galera Cluster
Abdul Manaf
 
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
Ulf Wendel
 
Scaling with sync_replication using Galera and EC2
Marco Tusa
 
Introduction to Galera Cluster
Codership Oy - Creators of Galera Cluster
 
Master master vs master-slave database
Wipro
 
DIY: A distributed database cluster, or: MySQL Cluster
Ulf Wendel
 
MySQL 5.6 Global Transaction Identifier - Use case: Failover
Ulf Wendel
 
The mysqlnd replication and load balancing plugin
Ulf Wendel
 
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Kenny Gryp
 
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
Ulf Wendel
 
PoC: Using a Group Communication System to improve MySQL Replication HA
Ulf Wendel
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Chris Barber
 
MySQL Multi Master Replication
Moshe Kaplan
 
Galera cluster for high availability
Mydbops
 
Codership's galera cluster installation and quickstart webinar march 2016
Sakari Keskitalo
 
Automate MariaDB Galera clusters deployments with Ansible
Federico Razzoli
 
Choosing a MySQL High Availability solution - Percona Live UK 2011
Henrik Ingo
 

Similar to Highly Available MySQL/PHP Applications with mysqlnd (20)

PDF
High Availability with MySQL
Thava Alagu
 
PDF
MySQL High Availability Solutions
Lenz Grimmer
 
PDF
Mysqlhacodebits20091203 1260184765-phpapp02
Louis liu
 
PDF
MySQL High Availability Solutions
Lenz Grimmer
 
PDF
Buytaert kris my_sql-pacemaker
kuchinskaya
 
PDF
Get mysql clusterrunning-windows
JoeSg
 
PDF
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
Kenny Gryp
 
PDF
MySQL 8.0 InnoDB Cluster - Easiest Tutorial
Frederic Descamps
 
PDF
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
Kenny Gryp
 
PDF
MySQL replication & cluster
elliando dias
 
PDF
20190817 coscup-oracle my sql innodb cluster sharing
Ivan Ma
 
PDF
Mysql wp cluster_quickstart_windows
Rogério Rocha
 
PDF
Has MySQL grown up?
Mark Stanton
 
PDF
Drupal Con My Sql Ha 2008 08 29
liufabin 66688
 
PDF
20200613 my sql-ha-deployment
Ivan Ma
 
PPTX
My SQL Portal Database (Cluster)
Nicholas Adu Gyamfi
 
PDF
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
Olivier DASINI
 
PDF
MySQL InnoDB Cluster and NDB Cluster
Mario Beck
 
PDF
MySQL Database Architectures - 2020-10
Kenny Gryp
 
ODP
MySQL HA Alternatives 2010
Kris Buytaert
 
High Availability with MySQL
Thava Alagu
 
MySQL High Availability Solutions
Lenz Grimmer
 
Mysqlhacodebits20091203 1260184765-phpapp02
Louis liu
 
MySQL High Availability Solutions
Lenz Grimmer
 
Buytaert kris my_sql-pacemaker
kuchinskaya
 
Get mysql clusterrunning-windows
JoeSg
 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
Kenny Gryp
 
MySQL 8.0 InnoDB Cluster - Easiest Tutorial
Frederic Descamps
 
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
Kenny Gryp
 
MySQL replication & cluster
elliando dias
 
20190817 coscup-oracle my sql innodb cluster sharing
Ivan Ma
 
Mysql wp cluster_quickstart_windows
Rogério Rocha
 
Has MySQL grown up?
Mark Stanton
 
Drupal Con My Sql Ha 2008 08 29
liufabin 66688
 
20200613 my sql-ha-deployment
Ivan Ma
 
My SQL Portal Database (Cluster)
Nicholas Adu Gyamfi
 
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
Olivier DASINI
 
MySQL InnoDB Cluster and NDB Cluster
Mario Beck
 
MySQL Database Architectures - 2020-10
Kenny Gryp
 
MySQL HA Alternatives 2010
Kris Buytaert
 
Ad

More from Jervin Real (12)

PDF
Low Cost Transactional and Analytics with MySQL + Clickhouse
Jervin Real
 
PDF
Low Cost Transactional and Analytics with MySQL + Clickhouse
Jervin Real
 
PDF
ZFS and MySQL on Linux, the Sweet Spots
Jervin Real
 
PDF
Lock, Stock and Backup: Data Guaranteed
Jervin Real
 
PDF
Learning MySQL 5.7
Jervin Real
 
PDF
Heterogenous Persistence
Jervin Real
 
PDF
Preventing and Resolving MySQL Downtime
Jervin Real
 
PDF
TokuDB - What You Need to Know
Jervin Real
 
PDF
PLAM 2015 - Evolving Backups Strategy, Devploying pyxbackup
Jervin Real
 
PDF
Learning by Experience, Devploying pyxbackup
Jervin Real
 
PDF
AWS Users Meetup April 2015
Jervin Real
 
PDF
High Performance Rails with MySQL
Jervin Real
 
Low Cost Transactional and Analytics with MySQL + Clickhouse
Jervin Real
 
Low Cost Transactional and Analytics with MySQL + Clickhouse
Jervin Real
 
ZFS and MySQL on Linux, the Sweet Spots
Jervin Real
 
Lock, Stock and Backup: Data Guaranteed
Jervin Real
 
Learning MySQL 5.7
Jervin Real
 
Heterogenous Persistence
Jervin Real
 
Preventing and Resolving MySQL Downtime
Jervin Real
 
TokuDB - What You Need to Know
Jervin Real
 
PLAM 2015 - Evolving Backups Strategy, Devploying pyxbackup
Jervin Real
 
Learning by Experience, Devploying pyxbackup
Jervin Real
 
AWS Users Meetup April 2015
Jervin Real
 
High Performance Rails with MySQL
Jervin Real
 
Ad

Recently uploaded (20)

PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Import Data Form Excel to Tally Services
Tally xperts
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 

Highly Available MySQL/PHP Applications with mysqlnd

  • 1. Highly Available PHP/MySQL Applications with mysqlnd Jervin Real PHP-UGPH, June 2014
  • 2. Highly Available Applications • … how much your application is able to serve its end users within a time period
  • 3. Highly Available Applications • … how much your application is able to serve its end users within a time period • Usually referred to as 99[..]% uptime
  • 4. Highly Available Applications • … how much your application is able to serve its end users within a time period • Usually referred to as 99[..]% uptime • It actually depends on whose perspective
  • 5. Highly Available Applications Keep PHP<>MySQL downtime to a minimum
  • 6. WTF are you saying? I’m a “devloper"! No no no no no no!
  • 10. MySQL
  • 11. MySQL HA • MySQL Native Replication (Single Primary)
  • 12. MySQL HA • MySQL Native Replication (Single Primary) • MySQL Native Replication (Multi-Master)
  • 13. MySQL HA • MySQL Native Replication (Single Primary) • MySQL Native Replication (Multi-Master) • MySQL NDB Cluster
  • 14. MySQL HA • MySQL Native Replication (Single Primary) • MySQL Native Replication (Multi-Master) • MySQL NDB Cluster • Galera based
  • 15. MySQL HA • MySQL Native Replication (Single Primary) • MySQL Native Replication (Multi-Master) • MySQL NDB Cluster • Galera based • Percona XtraDB Cluster • MariaDB Galera Cluster • MySQL+Galera
  • 16. MySQL HA • MySQL Native Replication (Single Primary) • MySQL Native Replication (Multi-Master) • MySQL NDB Cluster • Galera based • Percona XtraDB Cluster • MariaDB Galera Cluster • MySQL+Galera • Tungsten Replicator
  • 17. MySQL HA • MySQL Native Replication (Single Primary) • MySQL Native Replication (Multi-Master) • MySQL NDB Cluster • Galera based • Percona XtraDB Cluster • MariaDB Galera Cluster • MySQL+Galera • Tungsten Replicator • … and many more
  • 18. • MySQL Master HA MySQL HA (External Support)
  • 19. MySQL HA (External Support) • MySQL Master HA • Percona Replication Manager (Pacemaker)
  • 20. MySQL HA (External Support) • MySQL Master HA • Percona Replication Manager (Pacemaker) • Haproxy
  • 21. MySQL HA (External Support) • MySQL Master HA • Percona Replication Manager (Pacemaker) • Haproxy • Load Balancers
  • 22. MySQL HA (External Support) • MySQL Master HA • Percona Replication Manager (Pacemaker) • Haproxy • Load Balancers • MySQL Multi Master
  • 23. MySQL HA (External Support) • MySQL Master HA • Percona Replication Manager (Pacemaker) • Haproxy • Load Balancers • MySQL Multi Master
  • 25. HA via Application • Traditionally complex to implement • Unnecessary overhead • No single point of failure
  • 28. mysqlnd • MySQL Native Driver • Written C (as all extensions should be!)
  • 29. mysqlnd • MySQL Native Driver • Written C (as all extensions should be!) • MySQL Client Libraries no more
  • 30. mysqlnd • MySQL Native Driver • Written C (as all extensions should be!) • MySQL Client Libraries no more • Smaller memory footprint in many cases
  • 31. mysqlnd • MySQL Native Driver • Written C (as all extensions should be!) • MySQL Client Libraries no more • Smaller memory footprint in many cases • Performance statistics
  • 32. mysqlnd • MySQL Native Driver • Written C (as all extensions should be!) • MySQL Client Libraries no more • Smaller memory footprint in many cases • Performance statistics • Compression
  • 33. mysqlnd • MySQL Native Driver • Written C (as all extensions should be!) • MySQL Client Libraries no more • Smaller memory footprint in many cases • Performance statistics • Compression • Plugins
  • 34. mysqlnd Plugins • mysqlnd_qc - query result cache
  • 35. mysqlnd Plugins • mysqlnd_qc - query result cache • mysqlnd_mux - connection multiplexing
  • 36. mysqlnd Plugins • mysqlnd_qc - query result cache • mysqlnd_mux - connection multiplexing • mysqlnd_uh - user handler
  • 37. mysqlnd Plugins • mysqlnd_qc - query result cache • mysqlnd_mux - connection multiplexing • mysqlnd_uh - user handler • mysqlnd_memcache - Memcache (MySQL interface)
  • 38. mysqlnd Plugins • mysqlnd_qc - query result cache • mysqlnd_mux - connection multiplexing • mysqlnd_uh - user handler • mysqlnd_memcache - Memcache (MySQL interface) • mysqlnd_ms - replication and load balancing
  • 40. mysqlnd_ms Supported Clusters • All previously mentioned with few limitations
  • 41. Limitations (Master-Slave) • Master is a single point of failure • Need external help for failover • . . or, shoot the other node in the foot, this is still HA!
  • 45. Limitations (Master-Master) • Risky, even if you try segregating writes per master you can still lose data
  • 49. Limitations (Master-Master) db1 + db2 • Not good if sync_binlog = 0 AND/OR innodb_flush_log_at_trx_commit <> 1 • Not really recommended in general, use appropriate technologies instead
  • 50. Some More Limitations • Lazy connections is on by default • Each request will create its own connections when needed, persistent connections may be required • https://bugs.php.net/bug.php?id=67564 • https://bugs.php.net/bug.php?id=67565 • https://bugs.php.net/bug.php?id=67574 • Be careful with multi-statements and read-write splitting, they are likely to be executed on slave! SELECT  *  FROM  tbl;  DELETE  FROM  tbl;
  • 51. • Single Primary - one writable node • Multiple Primary - all nodes writable mysqlnd_ms Supported Clusters
  • 53. • Master-Slave • Declare 2 clusters mysqlnd_ms Supported Clusters
  • 54. • Master-Slave • Declare 2 clusters • When primary fails, mark it permanently dead and switch to secondary mysqlnd_ms Supported Clusters
  • 55. • Master-Slave • Declare 2 clusters • When primary fails, mark it permanently dead and switch to secondary {      "primary":  {          "master":  {              "master_1":  {                  "host":  "127.0.0.1",                  "port":  33001              }          },          "slave":  {              "slave_0":  {                  "host":  "127.0.0.1",                  "port":  33002              }          }      },      "standby":  {          "master":  {              "master_1":  {                  "host":  "127.0.0.1",                  "port":  33002              }          },          "slave":  {          }      }   } mysqlnd_ms Supported Clusters
  • 56. • Master-Slave • Declare 2 clusters • When primary fails, mark it permanently dead and switch to secondary • Works better with master-master! {      "primary":  {          "master":  {              "master_1":  {                  "host":  "127.0.0.1",                  "port":  33001              }          },          "slave":  {              "slave_0":  {                  "host":  "127.0.0.1",                  "port":  33002              }          }      },      "standby":  {          "master":  {              "master_1":  {                  "host":  "127.0.0.1",                  "port":  33002              }          },          "slave":  {          }      }   } mysqlnd_ms Supported Clusters
  • 57. • Master-Slave Demo • https://github.com/dotmanila/demo-me/phpugph201407/ • master-slave.ini • mysqlnd_ms_ms.ini • master-slave.php mysqlnd_ms Supported Clusters
  • 58. • Multi-Masters (NDB, Galera) • Declare all nodes as masters mysqlnd_ms Supported Clusters
  • 59. • Multi-Masters (NDB, Galera) mysqlnd_ms Supported Clusters
  • 60. • Multi-Masters (NDB, Galera) • Declare all nodes as masters mysqlnd_ms Supported Clusters  {        "primary":  {            "master":  {                "master_1":  {                    "host":  "192.168.56.44",                    "port":  "3306"                },                "master_2":  {                    "host":  "192.168.56.43",                    "port":  "3306"                },                "master_3":  {                    "host":  "192.168.56.42",                    "port":  "3306"                }            },            "slave":  {  },            "filters":  {  "random":  [  ]  },            "failover":  {                  "strategy":  "loop_before_master",                  "remember_failed":  true              }        }    }
  • 61. • Multi-Masters (NDB, Galera) mysqlnd_ms Supported Clusters  {        "primary":  {            "master":  {                "master_1":  {                    "host":  "192.168.56.44",                    "port":  "3306"                },                "master_2":  {                    "host":  "192.168.56.43",                    "port":  "3306"                },                "master_3":  {                    "host":  "192.168.56.42",                    "port":  "3306"                }            },            "slave":  {  },            "filters":  {  "random":  [  ]  },            "failover":  {                  "strategy":  "loop_before_master",                  "remember_failed":  true              }        }    }
  • 62. • Multi-Masters (NDB, Galera) • Declare all nodes as masters • roundrobin - single node writer (first node in config) mysqlnd_ms Supported Clusters  {        "primary":  {            "master":  {                "master_1":  {                    "host":  "192.168.56.44",                    "port":  "3306"                },                "master_2":  {                    "host":  "192.168.56.43",                    "port":  "3306"                },                "master_3":  {                    "host":  "192.168.56.42",                    "port":  "3306"                }            },            "slave":  {  },            "filters":  {  "random":  [  ]  },            "failover":  {                  "strategy":  "loop_before_master",                  "remember_failed":  true              }        }    }
  • 63. • Multi-Masters (NDB, Galera) • Declare all nodes as masters • roundrobin - single node writer (first node in config) • random - all nodes mysqlnd_ms Supported Clusters  {        "primary":  {            "master":  {                "master_1":  {                    "host":  "192.168.56.44",                    "port":  "3306"                },                "master_2":  {                    "host":  "192.168.56.43",                    "port":  "3306"                },                "master_3":  {                    "host":  "192.168.56.42",                    "port":  "3306"                }            },            "slave":  {  },            "filters":  {  "random":  [  ]  },            "failover":  {                  "strategy":  "loop_before_master",                  "remember_failed":  true              }        }    }
  • 64. • Multi-Masters (NDB, Galera) • Declare all nodes as masters • roundrobin - single node writer (first node in config) • random - all nodes • remember_failed is not what it says it is  {        "primary":  {            "master":  {                "master_1":  {                    "host":  "192.168.56.44",                    "port":  "3306"                },                "master_2":  {                    "host":  "192.168.56.43",                    "port":  "3306"                },                "master_3":  {                    "host":  "192.168.56.42",                    "port":  "3306"                }            },            "slave":  {  },            "filters":  {  "random":  [  ]  },            "failover":  {                  "strategy":  "loop_before_master",                  "remember_failed":  true              }        }    } mysqlnd_ms Supported Clusters
  • 65. • Master-Master Demo • https://github.com/dotmanila/demo-me/phpugph201407/ • master-master.ini • mysqlnd_ms_mm.ini • master-master.php mysqlnd_ms Supported Clusters
  • 66. Am I Using mysqlnd? (rpm) [revin@forge  ~]$  rpm  -­‐q  php-­‐mysql.x86_64  -­‐-­‐requires   […]   libmysqlclient_r.so.16()(64bit)   libmysqlclient_r.so.16(libmysqlclient_16)(64bit)   libmysqlclient.so.16()(64bit)   libmysqlclient.so.16(libmysqlclient_16)(64bit)   […]
  • 67. [revin@forge  ~]$  rpm  -­‐q  php-­‐mysqlnd.x86_64  -­‐-­‐requires   php-­‐pdo(x86-­‐64)  =  5.4.30-­‐36.el6.art   rpmlib(VersionedDependencies)  <=  3.0.3-­‐1   rpmlib(FileDigests)  <=  4.6.0-­‐1   rpmlib(PayloadFilesHavePrefix)  <=  4.0-­‐1   rpmlib(CompressedFileNames)  <=  3.0.4-­‐1   libc.so.6()(64bit)   libc.so.6(GLIBC_2.2.5)(64bit)   libc.so.6(GLIBC_2.3.4)(64bit)   libc.so.6(GLIBC_2.4)(64bit)   libpthread.so.0()(64bit)   libpthread.so.0(GLIBC_2.2.5)(64bit)   rtld(GNU_HASH)   rpmlib(PayloadIsXz)  <=  5.2-­‐1 Am I Using mysqlnd? (rpm)
  • 68. [revin@forge  ~]$  php  -­‐i   […]   ! mysql   ! MySQL  Support  =>  enabled   Active  Persistent  Links  =>  0   Active  Links  =>  0   Client  API  version  =>  5.1.59   MYSQL_MODULE_TYPE  =>  external   MYSQL_SOCKET  =>  /var/lib/mysql/mysql.sock   MYSQL_INCLUDE  =>  -­‐I/usr/include/mysql   MYSQL_LIBS  =>  -­‐L/usr/lib64/mysql  -­‐lmysqlclient Am I Using mysqlnd? (phpinfo)
  • 69. [revin@forge  ~]$  php  -­‐i   […]   ! mysqlnd   ! mysqlnd  =>  enabled   Version  =>  mysqlnd  5.0.10  -­‐  20111026  -­‐  $Id:  c85105d7c6f7d70d609bb4c000257868a40840ab  $   Compression  =>  supported   SSL  =>  supported   Command  buffer  size  =>  4096   Read  buffer  size  =>  32768   Read  timeout  =>  31536000   Collecting  statistics  =>  Yes   Collecting  memory  statistics  =>  No   Tracing  =>  n/a   Loaded  plugins  =>  mysqlnd,example,debug_trace,     auth_plugin_mysql_native_password,     auth_plugin_mysql_clear_password   API  Extensions  =>  mysql,mysqli,pdo_mysql Am I Using mysqlnd? (phpinfo)
  • 70. Conclusion • Yes, we can achieve HA with mysqlnd_ms • Not for the faint of heart • Do not rely on for HA (writes) on critical production systems • Good for intended use case, rw-splitting
  • 72. Q&A • http://dotmanila.com/blog/ • http://www.mysqlperformanceblog.com/ • @dotmanila Percona is Hiring!! http://www.percona.com/about-us/careers/open-positions
  • 73. $t  =  true  AND  false;  echo  (int)  $t;