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!
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
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
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!
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
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)
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
Be the first to comment