Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cloud computing & lamp applications


Published on

How to scale with AWS web applications based on LAMP.

Published in: Technology, Business
  • Be the first to comment

Cloud computing & lamp applications

  1. 1. CLOUD COMPUTING &LAMP APPLICATIONS Gabriele Mittica - @gabrielemittica Corley srl - Cloud Conference 2013
  2. 2. LAMP & Scalability• Applications deployed on LAMP platforms are not usually designed to be scalable Disk Access MySQL Network Traffic
  3. 3. Common scalability
  4. 4. HOW TO SCALE?
  5. 5. Scalability and High Availability
  6. 6. Static filesWe can’t host static files (uploads, The goal is make our web instancesimages, css…) on the web instance full dedicated to host the logic of the application, with no relationships to static files.• Move static files to a dedicated service like S3• S3 is a scalable service that grants the 99,999999999% of file durability With AWS, you can upload files from your instances to a S3 bucket with AWS• We can use a CDN and create several SDK for php subdomains as media.mywebsite.tld, ( upload.mywebsite.tld, etc.
  7. 7. Cache and sessionsWe need a dedicate service where host • session.save_handler =cache and sessions, in order to make memcachethem always • session.save_path =• Use an hosted cache system (as "tcp:// Memcache) instead of local ones (as in.tld:11211" APC)• PHP has a native handler to use manage sessions with Memcache• We can use a Elasicache or DynamoDB to host both cache and sessions
  8. 8. Database scalability• Multi A-Z • Master / Slave (Read Replica)When you provision a Multi-AZ DB The master database is regarded as theInstance, Amazon RDS automatically authoritative source, and the slavecreates a primary DB instance and databases are synchronized to it.synchronously replicates the data to astandby instance in a different Use the master instance to write andAvailability Zone (AZ). slave ones to read data.+ easy to manage + easy to scale- pay double - hard to manage
  9. 9. Database scalability• MySQL native driver? • Available from PHP >=5.3 • Compile PHP with mysqlnd support • --with-mysqli=mysqlnd --with-pdo=mysqlnd --with-mysql=mysqlnd • WARN mysql extension is deprecated as of PHP 5.5.0• Delegate to “mysqlnd_ms” the master/slave management •
  10. 10. Database scalability{ The simple JSON configuration is divided in two main "myapp": { "master": { section "master_0": { "host": "localhost", • Master "port": "3306" } • Slaves }, "slave": { "slave_0": { “myapp” is the hostname that we use instead the real "host": "", mysql host address. "port": "3306" } } Eg. } • mysql_connect(“myapp”, “user”, “passwd”);} • new Mysqli(“myapp”, “user”, “passwd”); • new PDO(“mysql:dbname=testdb;host=myapp”);
  11. 11. Load balancing• ELB – Elastic Load Balancer • Distributed load balancer on AWS regions (eu- When a server starts, it has to create a valid west-1, 2, 3 you have to select in how many region environment in order to provides web pages. you are available) Strategies? Compile and bundle all softwares in one instance • Watch EC2 status thanks to a ping strategy image • Page check every x minutes/seconds • all software becomes old very quickly and • Turn on/off EC2 instances automatically thanks to when you have to release an update you alarms (CloudWatch raise alarms) have to compile a new image and update - It • Receive Alarms from CloudWatch and engage scale is a long and complex operation operations • You can raise CPU alarms, Network Alarms, VM status Use EC2_USER_DATA feature provided by AWS alarms and many others in order to increase or decrease • You can run a shell script when your the actual number of EC2 instances bootstraps. It is more flexible • Scale strategy is not simple and you have to because you can create a skeleton (PHP + understand how your application works libraries) and download all software runtime • CPU is the simplest way but remember that the during the boot operation bandwidth is limited by network interfaces and bottlenecks can obfuscate the CPU alarm and your application stucks in weird and strange situations.
  12. 12. Load balancing• If you ran 10 servers execute commands could be hard. You can use tools to run command on a server list • Capistrano (Ruby) no • Fabric (Python) Use CLOTH for AWS EC2 instances
  13. 13. jMeter App instances instances 1 billion of monthly pageviewsAverage 400 concurrent connections 60 $ on the cloud
  14. 14. before after
  15. 15. More code on
  16. 16. THANKYOU