20130714 php matsuri - highly available php
-
Upload
graham-weldon -
Category
Technology
-
view
163 -
download
2
Transcript of 20130714 php matsuri - highly available php
![Page 1: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/1.jpg)
High availability PHPBuilding scalable PHP systems
Graham Weldon
Platform as a Service Development & Operations GroupArchitecture Committee OfficeRakuten, Inc.
![Page 2: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/2.jpg)
About me
• PHP Developer (15 years)
• Game Developer
• Dev Ops
• CakePHP Contributor
• Public Speaker for PHP
• Public Speaker for Open Source
• Used to live in Australia
• Moved to Tokyo, Japan to work for Rakuten, Inc.
• I love Tokyo (and Sapporo!)
![Page 3: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/3.jpg)
(CakeMatsuri) PHP Matsuri
![Page 4: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/4.jpg)
(CakeMatsuri) PHP Matsuri
2009
![Page 5: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/5.jpg)
(CakeMatsuri) PHP Matsuri
2009 2010
![Page 6: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/6.jpg)
(CakeMatsuri) PHP Matsuri
2009 2010 2011
![Page 7: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/7.jpg)
(CakeMatsuri) PHP Matsuri
2009 20122010 2011
![Page 8: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/8.jpg)
(CakeMatsuri) PHP Matsuri
2009 201320122010 2011
![Page 9: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/9.jpg)
![Page 10: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/10.jpg)
What I do at work
![Page 11: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/11.jpg)
Rakuten’s PaaS
![Page 12: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/12.jpg)
Rakuten’s PaaS
• We build on top of Cloud Foundry
• Build new services
• Build new runtimes
• Support application developers
• Ensure a stable, forward-thinking platform is available
• Internal use only
• Highly available
• Easily scalable
![Page 13: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/13.jpg)
By the way ...
• We’re hiring!
• If you’re interested in:
• large systems
• scalable architecture
• solving challenging problems
• Ask me for information!
• @predominant
![Page 14: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/14.jpg)
We’re Hiring!
• RakutenPlatform as a Service
• http://bit.ly/rakutenpaas
• RakutenPublic Cloud Section
• http://bit.ly/rakutenpcs
![Page 15: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/15.jpg)
What does “Highly available” mean?
• No “single point of failure”
• Redundancy
• Failover systems
![Page 16: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/16.jpg)
What does “Highly available” mean?
• In the event of a system failure there are backup / alternative systems available to take over
• No system failure should result in applications being “down” or offline
• The system is designed to continue operating in the event of failure
![Page 17: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/17.jpg)
What does “scalable” mean?
• Easy to add more servers
• Distribute the load of users amongst many servers
• Transparently add to the compute pool to provide faster response times
+
+
+
![Page 18: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/18.jpg)
System design / architecture
![Page 19: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/19.jpg)
Simple Web Setup
Internet
![Page 20: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/20.jpg)
Simple Web Setup
Internet Limited Limited BandwidthBandwidth
![Page 21: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/21.jpg)
Simple Web Setup
Internet Limited Limited BandwidthBandwidth
Single Single WebserverWebserver
![Page 22: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/22.jpg)
Simple Web Setup
Internet Limited Limited BandwidthBandwidth
Single Single WebserverWebserver
Single Single DatabaseDatabase
![Page 23: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/23.jpg)
Simple Web Setup
Internet Limited Limited BandwidthBandwidth
Single Single WebserverWebserver
Single Single DatabaseDatabase
No Failover No Failover solutionsolution
![Page 24: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/24.jpg)
Simple Web Setup
Internet Limited Limited BandwidthBandwidth
Single Single WebserverWebserver
Single Single DatabaseDatabase
No Failover No Failover solutionsolution
No scalingNo scaling
![Page 25: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/25.jpg)
Simple Setup
• We have all done this before
• It works well for very small sites
• You will encounter problems when the number of users grows
• There is no way to recover from system failure
• Any failure will produce extensive downtime
![Page 26: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/26.jpg)
A better solution
Internet
![Page 27: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/27.jpg)
A better solution
Internet
PrimaryPrimary
Backup / Backup / FailoverFailover
Traffic goes to the primary server
![Page 28: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/28.jpg)
A better solution
Internet
PrimaryPrimary
Backup / Backup / FailoverFailover
When a failure occurs on theprimary server...
![Page 29: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/29.jpg)
A better solution
Internet
PrimaryPrimary
Backup / Backup / FailoverFailover
Traffic is redirected to thebackup server
![Page 30: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/30.jpg)
A better solution
Internet
PrimaryPrimary
Backup / Backup / FailoverFailover
FailoverFailoveravailableavailable
![Page 31: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/31.jpg)
A better solution
Internet
PrimaryPrimary
Backup / Backup / FailoverFailover
FailoverFailoveravailableavailableFailover Failover
relies on relies on DNSDNS
![Page 32: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/32.jpg)
A better solution
Internet
PrimaryPrimary
Backup / Backup / FailoverFailover
FailoverFailoveravailableavailableFailover Failover
relies on relies on DNSDNS
NotNotscalablescalable
![Page 33: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/33.jpg)
A better solution
Internet
PrimaryPrimary
Backup / Backup / FailoverFailover
FailoverFailoveravailableavailableFailover Failover
relies on relies on DNSDNS
NotNotscalablescalable
Database Database Sync Sync
problems?problems?
![Page 34: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/34.jpg)
A better solution
• A backup is now available
• We can switch traffic to the backup server in case of failure
• Highly available?
• A little bit
• Scalable?
• No
• Its a better solution than the previous example
• But its not ideal
![Page 35: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/35.jpg)
An even better solution
Internet
Load Load BalancersBalancers
Load balancers distribute the load
![Page 36: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/36.jpg)
An even better solution
Internet
Load Load BalancersBalancers
WebWebServersServers
A pool of webservers are availableto handle the incoming traffic
![Page 37: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/37.jpg)
An even better solution
Internet
Load Load BalancersBalancers
WebWebServersServers
DBDBServersServers
Webservers connect to a database clusterto distribute load
![Page 38: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/38.jpg)
An even better solution
Internet
Load Load BalancersBalancers
WebWebServersServers
DBDBServersServers
LoadLoadbalancedbalanced
![Page 39: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/39.jpg)
An even better solution
Internet
Load Load BalancersBalancers
WebWebServersServers
DBDBServersServers
ScalableScalableLoadLoadbalancedbalanced
![Page 40: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/40.jpg)
An even better solution
Internet
Load Load BalancersBalancers
WebWebServersServers
DBDBServersServers
FailoverFailoveravailableavailable
ScalableScalableLoadLoadbalancedbalanced
![Page 41: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/41.jpg)
A perfect solution?
• There are good solutions available
• No solution is perfect
• Consider the parts of the system that can fail
• Build it in a highly available way
• Allow additional servers / services to be added through configuration
• Or.. through auto detection
![Page 42: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/42.jpg)
Scaling PHP
A Case Study of the Rakuten Platform
![Page 43: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/43.jpg)
Web Server
• Nginx
• Why?
• Fast
• Reliable
• Stable
• Low resource usage
• Designed for high speed
• Easy configuration
![Page 44: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/44.jpg)
Optimization
• PageSpeed
• Optimization tool from Google
• Open Source
• Easy to install
• Lots of options
• Optimizes your pages
• Image processing
• JS/CSS compression
![Page 45: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/45.jpg)
PHP
• PHP-FPM
• “Fast Process Manager”
• Easy to configure
• Fast when configured right
• Process pooling
• Simple to setup
![Page 46: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/46.jpg)
Databases
• A range of options
• Redis
• MongoDB
• Clusterix (MySQL Compatible)
• Each in a clustered setup
• Highly available
• Scalable
![Page 47: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/47.jpg)
Database considerations
• Optimize queries
• Use fast disks!
• Large memory
• Lots of CPU
• Database is often a bottleneck
• Make sure you have enough resources
![Page 48: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/48.jpg)
Content Delivery
• Use a Content Delivery Network for static content
• Or.. use a separate server for delivering static content to ensure PHP has the processing power it needs
• Speeds up browser requests for static files
• Allows concurrent requests with less work / effort
![Page 49: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/49.jpg)
Varnish
• HTTP accelerator
• In-memory caching
• Huge performance increases
• 300-1000x speed increase
![Page 50: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/50.jpg)
Special considerations
![Page 51: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/51.jpg)
Session Storage
• You need a common place for all servers to access for session storage
• We recommend Redis
• Common storage ensures that sessions will be maintained
• Without common storage, users will lose their session data between page requests.
![Page 52: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/52.jpg)
Session Storage
Web Servers Session Store
![Page 53: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/53.jpg)
Session Storage
• php.ini
• session.save_handler = ‘redis’
• session.save_path = ‘tcp://host:port, ...’
![Page 54: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/54.jpg)
Opcode Caching
• OpCache (Extension)
• Bundled with PHP 5.5+
• Available as an extension for earlier versions
• Faster than XCache
• Simple to setup
• OpCache will cache per-server
• You might want to pre-warm the cache for all servers
• I don’t have a better solution for this yet
![Page 55: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/55.jpg)
Thankyou!
Any questions?
![Page 56: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/56.jpg)
• We’re looking for talented engineers!
• Interested in DevOps?
• Interested in highly available systems?
• Contact me!
• @predominant
• RakutenPlatform as a Servicehttp://bit.ly/rakutenpaas
• RakutenPublic Cloud Sectionhttp://bit.ly/rakutenpcs
![Page 57: 20130714 php matsuri - highly available php](https://reader034.fdocuments.net/reader034/viewer/2022052411/557a0637d8b42a1c0a8b4cc3/html5/thumbnails/57.jpg)