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



                                        Disk
                                       Access
                          MySQL                    Network


                                       Traffic
Common scalability
HOW TO SCALE?
Scalability and High Availability
Static files
We can’t host static files (uploads,            The goal is make our web instances
images, 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,          (http://aws.amazon.com/sdkforphp/)
    upload.mywebsite.tld, etc.
Cache and sessions
We need a dedicate service where host     •   session.save_handler =
cache and sessions, in order to make          memcache
them always
                                          •   session.save_path =
•   Use an hosted cache system (as            "tcp://1.cache.group.doma
    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
Database scalability
•   Multi A-Z                            •   Master / Slave (Read Replica)
When you provision a Multi-AZ DB         The master database is regarded as the
Instance, Amazon RDS automatically       authoritative source, and the slave
creates a primary DB instance and        databases are synchronized to it.
synchronously replicates the data to a
standby instance in a different          Use the master instance to write and
Availability Zone (AZ).                  slave ones to read data.


+ easy to manage                         + easy to scale

- pay double                             - 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
{                                         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": "192.168.2.27",   mysql host address.
                "port": "3306"
            }
        }                                 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-                 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.
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/capistra
        no
    •   Fabric (Python)
        https://github.com/fabric/fabric
        Use CLOTH for AWS EC2
        instanceshttps://github.com/garethr/cloth
jMeter              App
  instances          instances




  1 billion of monthly pageviews
Average 400 concurrent connections
     60 $ on the cloud
before   after
More code on
http://www.slideshare.net/corleycloud/corl
ey-scalability-19163383
THANKYOU
http://www.corley.it

Cloud computing & lamp applications

  • 1.
    CLOUD COMPUTING & LAMPAPPLICATIONS Gabriele Mittica www.gabrielemittica.com - @gabrielemittica Corley srl - www.corley.it Cloud Conference 2013
  • 2.
    LAMP & Scalability • Applications deployed on LAMP platforms are not usually designed to be scalable Disk Access MySQL Network Traffic
  • 3.
  • 4.
  • 5.
  • 7.
    Static files We can’thost static files (uploads, The goal is make our web instances images, 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, (http://aws.amazon.com/sdkforphp/) upload.mywebsite.tld, etc.
  • 9.
    Cache and sessions Weneed a dedicate service where host • session.save_handler = cache and sessions, in order to make memcache them always • session.save_path = • Use an hosted cache system (as "tcp://1.cache.group.doma 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
  • 11.
    Database scalability • Multi A-Z • Master / Slave (Read Replica) When you provision a Multi-AZ DB The master database is regarded as the Instance, Amazon RDS automatically authoritative source, and the slave creates a primary DB instance and databases are synchronized to it. synchronously replicates the data to a standby instance in a different Use the master instance to write and Availability Zone (AZ). slave ones to read data. + easy to manage + easy to scale - pay double - hard to manage
  • 12.
    Database scalability • MySQLnative 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
  • 13.
    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": "192.168.2.27", mysql host address. "port": "3306" } } Eg. } • mysql_connect(“myapp”, “user”, “passwd”); } • new Mysqli(“myapp”, “user”, “passwd”); • new PDO(“mysql:dbname=testdb;host=myapp”);
  • 15.
    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.
  • 16.
    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/capistra no • Fabric (Python) https://github.com/fabric/fabric Use CLOTH for AWS EC2 instanceshttps://github.com/garethr/cloth
  • 18.
    jMeter App instances instances 1 billion of monthly pageviews Average 400 concurrent connections 60 $ on the cloud
  • 19.
    before after
  • 20.
  • 21.