21
CLOUD COMPUTING & LAMP APPLICATIONS Gabriele Mittica www.gabrielemittica.com - @gabrielemittica Corley srl - www.corley.it Cloud Conference 2013

Cloud computing & lamp applications

Embed Size (px)

DESCRIPTION

How to scale with AWS web applications based on LAMP.

Citation preview

Page 1: Cloud computing & lamp applications

CLOUD COMPUTING &

LAMP APPLICATIONS

Gabriele Mittica

www.gabrielemittica.com - @gabrielemittica

Corley srl - www.corley.it

Cloud Conference 2013

Page 2: Cloud computing & lamp applications

LAMP & Scalability

• Applications deployed on LAMP platforms are not usually designed to be scalable

Traffic

MySQL

Disk Access

Network

Gabriele Mittica
aggiungere immagine su classica immagine del
Page 3: Cloud computing & lamp applications

Common scalability

Gabriele Mittica
aggiungere immagine su classica immagine del
Page 4: Cloud computing & lamp applications

HOW TO SCALE?

Page 5: Cloud computing & lamp applications

Scalability and High Availability

Gabriele Mittica
inserire immagine su schema gestione dns e applicativo
Page 6: Cloud computing & lamp applications
Page 7: Cloud computing & lamp applications

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/)

Gabriele Mittica
inserire immagine
Page 8: Cloud computing & lamp applications
Page 9: Cloud computing & lamp applications

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" 

Gabriele Mittica
inserire codice per la gestione del caching e sessione
Page 10: Cloud computing & lamp applications
Page 11: Cloud computing & lamp applications

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

Page 12: Cloud computing & lamp applications

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 

Page 13: Cloud computing & lamp applications

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”);

Page 14: Cloud computing & lamp applications
Page 15: Cloud computing & lamp applications

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

Page 16: Cloud computing & lamp applications

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

Page 17: Cloud computing & lamp applications
Page 18: Cloud computing & lamp applications

jMeter

instances

Appinstances

1 billion of monthly pageviewsAverage 400 concurrent connections

60 $ on the cloud

Page 19: Cloud computing & lamp applications

before after

Page 20: Cloud computing & lamp applications

More code on http://www.slideshare.net/corleycloud/corley-scalability-19163383

Gabriele Mittica
inserire immagine dell'architettura con loadbalancer, macchina web, cache e static files
Page 21: Cloud computing & lamp applications

THANK YOUhttp://www.corley.it