Date post: | 15-Jan-2015 |
Category: |
Technology |
Upload: | joe-stump |
View: | 10,013 times |
Download: | 0 times |
Services Oriented Architecture with PHP
and MySQLJoe Stump, Lead Architect, Digg
Introductions
I’m Joe Stump, Lead Architect for Digg.
Reduce HTTP Requests
Bundle JavaScript and CSS Use sprites for images Reduce images / outside objects
This talk doesn’t cover MySQL details. The point of this discussion is how to minimize MySQL’s impact on your company’s data layer.
Old habits die hard
Data requests are sequential Data requests are blocking Tightly coupled Scaling is not abstracted
Services Oriented Architecture (SOA)
Data is requested from a service Data requests are ran in parallel Data requests are asynchronous Data layer is loosely coupled Scalability is abstracted
What are my options?
Running requests over HTTP New York Times’ DBSlayer Danga’s Gearman DIY
HTTP w/ PHP
1. Group requests for data at the top2. Open a socket for each request
1. Sockets must be non-blocking2. Make sure to TCP_NODELAY
3. Use __get() to block for results4. See Services_Digg_Request
Grouping Data Requests
Opening the Sockets
Opening the Sockets
Returning Data
HTTP Conclusions
HTTP is widely supported in all languages Easy to get up and running Lots of options for servers / tuning Lots of overhead in protocol Apache has a lot of overhead
DBSlayer
Small HTTP daemon written in C Uses JSON for communications Connection pooling Load balancing and failover Tightly coupled to MySQL (for now) Tightly coupled to SQL No intelligence
Gearman
Highly scalable queuing system Simple/Efficient binary protocol Jobs can return results (e.g. data) Sets of jobs are ran in parallel Queue can scale linearly PHP, Perl, Python, Ruby, C clients Poorly documented Not very “robust”
Do It Yourself
Highly customized solutions (Flickr) Extremely efficient for custom cases Customize your protocols Requires more resources
What goes in the Service layer?
Smart caching strategies Data mapping and distribution Intelligent grouping of data results Partitioning logic
DO WANT!
Intelligently group data into endpoints Version your endpoints Bundle and group requests
EPIC FAIL!
Don’t just send SQL over for translation Hundreds of teeny tiny endpoints Not running SOA requests in parallel
ResourcesServices_Digghttp://pear.php.net/package/Services_Digg
Danga’s Gearmanhttp://www.danga.com/gearman/
Net_Gearmanhttp://code.google.com/p/netgearman/
New York Timesʼ DBSlayerhttp://code.nytimes.com/projects/dbslayer
Questions?!