Symfony e grandi numeri
Si...può...fare!

Daniel Londero
daniel.londero@sth.it
Chi sono

Daniel Londero


➢   Sviluppatore PHP dal 2005 @

➢   (s|S)ymfony framework

➢   PUG Friuli

➢   Runner
2M
         500k
5M                       300k

       10k   10M
200k

             50k        100k
Calciomercato.com: la storia

➢   Nasce nel 1996

➢   Nel 2006 arriva in STH

➢   Nel 2010 si passa a symfony 1.4

➢   12 aprile 2010 revision 1

➢   10 giugno 2010: deploy (22 ore)
I numeri

               UTENTI UNICI   PAGINE VISTE
                 AL MESE        AL MESE


AGOSTO 2010      3,6M            36M

GENNAIO 2011     3,3M            32M

MARZO 2011       2,2M            28M
Perchè symfony?

➢   Opensource

➢   Community

➢   Documentato

➢   Test

➢   Best practice (MVC / DRY / KISS / ...)
#GAC
APPLICATION

                     LOAD BALANCER


MEMCACHED     MEMCACHED
                                                            BE
  NGINX 1       NGINX N
                                   NGINX 1   NGINX N
 PHP FCGI       PHP FCGI


   APC              APC


                                                             DATA

         LOAD BALANCER

                                               NFS
MASTER      SLAVE    ...   SLAVE
  DB         DB1            DBN
LOAD BALANCER


MEMCACHED     MEMCACHED
                                                       BE
  NGINX 1       NGINX N
                                   NGINX 1   NGINX N
 PHP FCGI       PHP FCGI


   APC              APC



         LOAD BALANCER

                                               NFS
MASTER      SLAVE    ...   SLAVE
  DB         DB1            DBN
Scalare: orizzontale vs verticale

Orizzontale
➢ Aggiungo macchine

➢ Aumenta complessità

➢ Costi e rischi più bassi




Verticale
➢ Aggiungo risorse

➢ Bassa complessità

➢ Costi e rischi elevati
Gestione delle sessioni


➢   Balancer persistenti

➢   NFS (sconsigliato)

➢   Database

➢   Memcached (Redis dalla 2.4)
LOAD BALANCER


MEMCACHED     MEMCACHED
                                                       BE
  NGINX 1       NGINX N
                                   NGINX 1   NGINX N
 PHP FCGI       PHP FCGI


   APC              APC



         LOAD BALANCER

                                               NFS
MASTER      SLAVE    ...   SLAVE
  DB         DB1            DBN
Cache storage system
➢   SfFileCache (default)

➢   SfAPCCache

➢   SfEAcceleratorCache

➢   SfMemcacheCache

➢   SfSQLiteCache

➢   sfXCacheCache
“There are only two hard things in Computer
Science: cache invalidation and naming things”
                                  - Phil Karlton
Cache pagina
Cache Partial e Component
Contatori

Sfruttare la velocità di accesso alla memoria per
sollevare i database da operazioni inutili.

➢   Impression sui banner

➢   Letture articoli

➢   Voti per i sondaggi
LOAD BALANCER


MEMCACHED     MEMCACHED
                                                       BE
  NGINX 1       NGINX N
                                   NGINX 1   NGINX N
 PHP FCGI       PHP FCGI


   APC              APC



         LOAD BALANCER

                                               NFS
MASTER      SLAVE    ...   SLAVE
  DB         DB1            DBN
LOAD BALANCER


MEMCACHED     MEMCACHED
                                                       BE
  NGINX 1       NGINX N
                                   NGINX 1   NGINX N
 PHP FCGI       PHP FCGI


   APC              APC



         LOAD BALANCER

                                               NFS
MASTER      SLAVE    ...   SLAVE
  DB         DB1            DBN
sfMasterSlavePlugin
all:
 master:
   class: sfDoctrineDatabase
   param:
     dsn:    mysql:dbname=database;host:master.example.com
     username: root
     password: ~
 slave:
   class: sfDoctrineDatabase
   param:
     dsn:    mysql:dbname=database;host:slave.example.com
     username: root
     password: ~

dev:
 master: &master
  class: sfDoctrineDatabase
  param:
    dsn:    mysql:dbname=database;host=localhost
    username: root
    password: ~
 slave: *master
Strumenti utili


➢   Web debug toolbar

➢   Slow query log

➢   Explain

➢   Live on stage (and dev)
LOAD BALANCER


MEMCACHED     MEMCACHED
                                                       BE
  NGINX 1       NGINX N
                                   NGINX 1   NGINX N
 PHP FCGI       PHP FCGI


   APC              APC



         LOAD BALANCER

                                               NFS
MASTER      SLAVE    ...   SLAVE
  DB         DB1            DBN
LOAD BALANCER


MEMCACHED     MEMCACHED
                                                       BE
  NGINX 1       NGINX N
                                   NGINX 1   NGINX N
 PHP FCGI       PHP FCGI


   APC              APC



         LOAD BALANCER

                                               NFS
MASTER      SLAVE    ...   SLAVE
  DB         DB1            DBN
Credits e link
http://www.flickr.com/photos/theplanetdotcom/4879419788

http://www.php.net/manual/en/book.memcache.php

http://www.symfony-project.org/reference/1_4/en/05-Factories

http://www.symfony-project.org/gentle-introduction/1_4/en/12-Caching

http://www.symfony-project.org/jobeet/1_4/Doctrine/en/21

http://www.symfony-project.org/plugins/sfDoctrineMasterSlavePlugin

http://dev.mysql.com/doc/refman/5.6/en/slow-query-log.html

http://dev.mysql.com/doc/refman/5.6/en/explain.html
Grazie. Attendo feedback...


              Votate questo talk
              http://joind.in/3024



                Contattatemi
daniel.londero@sth.it | @dlondero | phpblog.it

Symfony e grandi numeri: si può fare!