Upload
corley-srl
View
1.706
Download
4
Embed Size (px)
DESCRIPTION
How to scale with AWS web applications based on LAMP.
Citation preview
CLOUD COMPUTING &
LAMP APPLICATIONS
Gabriele Mittica
www.gabrielemittica.com - @gabrielemittica
Corley srl - www.corley.it
Cloud Conference 2013
LAMP & Scalability
• Applications deployed on LAMP platforms are not usually designed to be scalable
Traffic
MySQL
Disk Access
Network
Common scalability
HOW TO SCALE?
Scalability and High Availability
Static files
We can’t host static files (uploads, images, css…) on the web instance
• Move static files to a dedicated service like S3
• S3 is a scalable service that grants the 99,999999999% of file durability
• We can use a CDN and create several subdomains as media.mywebsite.tld, upload.mywebsite.tld, etc.
The goal is make our web instances full dedicated to
host the logic of the application, with no
relationships to static files.
With AWS, you can upload files from your instances to a S3
bucket with AWS SDK for php (http://aws.amazon.com/
sdkforphp/)
Cache and sessions
We need a dedicate service where host cache and sessions, in order to make them always
• Use an hosted cache system (as Memcache) instead of local ones (as 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
•session.save_handler = memcache
•session.save_path = "tcp://1.cache.group.domain.tld:11211"
Database scalability
• Multi A-Z
When you provision a Multi-AZ DB Instance, Amazon RDS automatically creates a primary DB instance and synchronously replicates the data to a standby instance in a different Availability Zone (AZ).
+ easy to manage
- pay double
• Master / Slave (Read Replica)
The master database is regarded as the authoritative source, and the slave databases are synchronized to it.
Use the master instance to write and slave ones to read data.
+ easy to scale
- hard to manage
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• http://www.php.net/manual/en/book.mysqlnd-ms.php
Database scalability
{ "myapp": { "master": { "master_0": { "host": "localhost", "port": "3306" } }, "slave": { "slave_0": { "host": "192.168.2.27", "port": "3306" } } }}
The simple JSON configuration is divided in two main section
• Master• Slaves
“myapp” is the hostname that we use instead the real mysql host address.
Eg.• mysql_connect(“myapp”, “user”,
“passwd”);• new Mysqli(“myapp”, “user”, “passwd”);• new
PDO(“mysql:dbname=testdb;host=myapp”);
Load balancing• ELB – Elastic Load Balancer
• Distributed load balancer on AWS regions (eu-west-1, 2, 3 you have to select in how many region you are available)
• Watch EC2 status thanks to a ping strategy• Page check every x minutes/seconds
• Turn on/off EC2 instances automatically thanks to alarms (CloudWatch raise alarms)• Receive Alarms from CloudWatch and engage scale
operations• You can raise CPU alarms, Network Alarms, VM status
alarms and many others in order to increase or decrease the actual number of EC2
• Scale strategy is not simple and you have to understand how your application works• CPU is the simplest way but remember that the
bandwidth is limited by network interfaces and bottlenecks can obfuscate the CPU alarm and your application stucks in weird and strange situations.
When a server starts, it has to create a valid environment in order to provides web pages. Strategies?
Compile and bundle all softwares in one instance image• all software becomes old very
quickly and when you have to release an update you have to compile a new image and update - It is a long and complex operation
Use EC2_USER_DATA feature provided by AWS• You can run a shell script when your
instances bootstraps. It is more flexible because you can create a skeleton (PHP + libraries) and download all software runtime during the boot operation
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)
https://github.com/capistrano/capistrano
• Fabric (Python)https://github.com/fabric/fabric
Use CLOTH for AWS EC2 instanceshttps://github.com/garethr/cloth
jMeter
instances
Appinstances
1 billion of monthly pageviewsAverage 400 concurrent connections
60 $ on the cloud
before after
More code on http://www.slideshare.net/corleycloud/corley-scalability-19163383
THANK YOUhttp://www.corley.it