SlideShare a Scribd company logo
1 of 28
Download to read offline
Bo#om	
  to	
  Top	
  Stack	
  
   Op.miza.on	
  
 With	
  LAMP	
  +	
  CodeIgniter	
  
Server	
  side:	
  It’s	
  About	
  I/O	
  
             Network	
  I/O	
  
               Disk	
  I/O	
  
                   CPU	
  
Server/Client	
  side:	
  	
  
Minimize	
  and	
  Cache	
  Assets	
  
Op.miza.on	
  Roadmap	
  
•    System	
  
•    MySQL	
  
•    Apache	
  
•    PHP	
  
•    Framework	
  
•    Applica.on	
  
Tes.ng	
  
•  Frontend	
  
   –  Yslow	
  
•  Backend	
  
   –  `ab`	
  
   –  vmstat	
  
LAMP	
  Configura.on	
  
•  By	
  default,	
  for	
  “compa.bility”	
  
•  You’re	
  responsible	
  for	
  your	
  boxes	
  
System	
  
•  Don’t	
  swap	
  
    –  Swap	
  in	
  itself	
  isn’t	
  bad,	
  swapping	
  out	
  is	
  
•  Get	
  rid	
  of	
  non-­‐essen.al	
  processes	
  
•  a.me	
  –	
  Filesystem	
  op.on	
  to	
  write	
  ‘last-­‐
   accessed’	
  .me	
  to	
  everything	
  
    $	
  cat	
  /	
  
•  If	
  you’re	
  a	
  badass,	
  check	
  into	
  XFS	
  
a.me	
  
$ cat /etc/fstab
proc             /proc   proc    defaults    0 0
/dev/sda1        /       ext3    defaults,errors=remount-ro,noatime   0 1
/dev/sda2        none    swap    sw          0 0
MySQL	
  
•  Don’t	
  “SELECT	
  *”	
  
      –  If	
  the	
  data	
  you	
  need	
  is	
  in	
  an	
  index,	
  MySQL	
  will	
  grab	
  that	
  
•  Column	
  indexes	
  
      –  Foreign	
  key	
  type	
  matching	
  
      –  Be	
  smart	
  about	
  column	
  size	
  
      –  Integrity	
  checks?	
  Try	
  NOT	
  dele.ng	
  instead	
  
•    Batched	
  queries	
  
•    Key	
  Buffer	
  
•    Query	
  Buffer	
  
•    Engine	
  
      –  InnoDB,	
  or	
  go	
  crazy	
  and	
  use	
  Percona	
  XtraDB	
  with	
  XFS	
  
Apache	
  
•    Kill	
  unneeded	
  modules	
  
•    Tune	
  MaxClients	
  
•    Eliminate	
  .htaccess,	
  if	
  possible	
  
•    Kill	
  access	
  logs	
  
•    Disable	
  ETags	
  if	
  not	
  used	
  
•    Expires	
  Headers	
  
•    Compression	
  
•    Don’t	
  serve	
  sta.c	
  content	
  (if	
  you	
  can	
  avoid	
  it)	
  
Benchmarking	
  
•  Apache	
  bench	
  is	
  most	
  common	
  
              –  Tests	
  Requests	
  Per	
  Second	
  
•  Use	
  vmstat	
  to	
  watch	
  swap	
  usage	
  
•  Send	
  1,000	
  requests,	
  concurrency	
  of	
  10	
  
              	
  
	
  	
  	
  	
  $    ab –n 1000 –c 10 http://getsparks.org
Finished	
  10000	
  requests	
  
	
  
Server	
  Soiware:	
  	
  	
  	
  	
  	
  	
  	
  Apache/2.2.12	
  
Server	
  Hostname:	
  	
  	
  	
  	
  	
  	
  	
  getsparks.org	
  
Server	
  Port:	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  80	
  
	
  
Document	
  Path:	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  /	
  
Document	
  Length:	
  	
  	
  	
  	
  	
  	
  	
  9865	
  bytes	
  
	
  
Concurrency	
  Level:	
  	
  	
  	
  	
  	
  10	
  
Time	
  taken	
  for	
  tests:	
  	
  	
  6.040	
  seconds	
  
Complete	
  requests:	
  	
  	
  	
  	
  	
  10000	
  
…	
  
Requests	
  per	
  second:	
  	
  	
  	
  1655.63	
  [#/sec]	
  (mean)	
  
Time	
  per	
  request:	
  	
  	
  	
  	
  	
  	
  6.040	
  [ms]	
  (mean)	
  
Time	
  per	
  request:	
  	
  	
  	
  	
  	
  	
  0.604	
  [ms]	
  (mean,	
  across	
  all	
  concurrent	
  requests)	
  
Transfer	
  rate:	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  16260.41	
  [Kbytes/sec]	
  received	
  
	
  
Percentage	
  of	
  the	
  requests	
  served	
  within	
  a	
  certain	
  .me	
  (ms)	
  
	
  	
  50%	
  	
  	
  	
  	
  10	
  
	
  	
  …	
  
100%	
  	
  	
  	
  	
  60	
  (longest	
  request)	
  
$ vmstat 5

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r b    swpd   free   buff cache    si   so    bi    bo   in   cs us sy id wa
 0 0 55152 53212 15128 69172         0    0     0     1    0    1 0 0 100 0
 1 0 55152 54428 15132 69172         0    0     0    20   56   48 0 0 100 0
Killing	
  Apache	
  Modules	
  
$ a2dismod
Your choices are: alias auth_basic
authn_file authz_default authz_groupfile
authz_host authz_user autoindex cgi deflate
dir env expires mime negotiation php5
rewrite setenvif status
Tuning	
  MaxClients	
  
“You	
  can,	
  and	
  should,	
  control	
  the	
  MaxClients	
  se5ng	
  so	
  that	
  your	
  server	
  does	
  
not	
  spawn	
  so	
  many	
  children	
  it	
  starts	
  swapping.”	
  
       	
   	
    	
     	
     	
   	
         	
   	
     	
   	
   	
  -­‐	
  Apache.org	
  
	
  
Usually	
  in	
  h#pd.conf	
  or	
  apache2.conf	
  
	
  
Find	
  average	
  size	
  of	
  h#p	
  process	
  with	
  `top`	
  (x).	
  
How	
  much	
  RAM	
  to	
  dedicate	
  to	
  Apache?	
  (n).	
  
	
  
MaxClients	
  =	
  floor(n	
  /	
  x)	
  
	
  
Play	
  around	
  with	
  that	
  and	
  Apache	
  Bench	
  `ab`	
  
Adding	
  Expires	
  Headers	
  
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif "access plus X days"
ExpiresByType image/jpeg "access plus X days"
ExpiresByType image/png "access plus X days"
ExpiresByType text/css "access plus X days"
ExpiresByType text/js "access plus X days"
ExpiresByType text/javascript "access plus X days"
ExpiresByType application/javascript "access plus X
days"
ExpiresByType application/x-javascript "access plus
X days"
ExpiresDefault "access plus X days"
</IfModule>
mod_deflate	
  
•  Compress	
  your	
  stuff,	
  comes	
  with	
  Apache	
  

$ a2enmod deflate
# … configure in global or vhost config …
AddOutputFilterByType DEFLATE text/html text/plain text/xml
# … restart Apache
$ apache2ctl -k restart
Killing	
  ETags	
  
$	
  a2enmod	
  header	
  
#	
  open	
  apache.conf	
  or	
  h#pd.conf,	
  add:	
  
Header	
  unset	
  ETag	
  
FileETag	
  None	
  
$	
  apache2ctl	
  –k	
  restart	
  
	
  
HTTP	
  Accelerators	
  
•  Serving	
  sta.c	
  content	
  is	
  VERY	
  expensive	
  for	
  
   Apache	
  
•  Varnish,	
  Squid	
  

$	
  apt-­‐get	
  install	
  varnish	
  
#	
  go	
  to	
  varnish-­‐cache.org	
  
PHP	
  
•  APC	
  
    –  Caches	
  PHP	
  Op-­‐code,	
  can	
  use	
  as	
  cache	
  
    –  Faster	
  than	
  memcache	
  for	
  one	
  box	
  
•  PHP	
  5.3	
  
•  mysqlnd	
  	
  
•  Output	
  buffering	
  tuning,	
  send	
  data	
  to	
  client	
  
   more	
  frequently	
  
APC	
  Install	
  
$	
  apt-­‐get	
  install	
  php-­‐pear	
  
…	
  
$	
  pecl	
  install	
  apc	
  
	
  
	
  
Then	
  take	
  a	
  look	
  at	
  cache	
  size:	
  apc.shm_size	
  
Framework	
  (CodeIgniter)	
  
•  Page	
  Caching	
  
   –  Personalized	
  info,	
  uh	
  oh.	
  
•  Query	
  Result	
  Caching	
  
•  Configura.on	
  
   –  Disable	
  verbose	
  logging	
  
   –  Output	
  compression	
  
   –  config/database.php:	
  autoinit?	
  
•  Minifying,	
  combining	
  assets	
  
   –  ‘assets’	
  Spark	
  
Applica.on	
  
•    Most	
  op.miza.on	
  does	
  not	
  occur	
  within	
  code	
  
•    Use	
  built-­‐in	
  PHP	
  func.ons	
  
•    Use	
  associa.ve	
  arrays	
  (hashes,	
  dic.onaries)	
  
•    Batch	
  DB	
  Inserts,	
  Selects	
  
•    Don’t	
  use	
  references	
  unless	
  it	
  makes	
  sense	
  
     –  Like…	
  $CI	
  =	
  &	
  get_instance();	
  
•  require_once	
  is	
  expensive	
  
•  count()	
  elements	
  before	
  start	
  ‘for’	
  loop	
  
Applica.on	
  (cont’d)	
  
•  Don’t	
  copy	
  variables	
  if	
  you	
  don’t	
  have	
  to	
  
        	
  foreach($db_result	
  as	
  $row)	
  {	
  
        	
   	
  $content	
  =	
  $row[‘content’];	
  
        	
   	
  $content	
  =	
  word_limited($content,	
  100);	
  
        	
  }	
  
    	
  
    And	
  the	
  usual:	
  require_once,	
  etc.	
  
Find	
  one	
  or	
  two	
  numbers	
  in	
  an	
  array	
  that	
  add	
  to	
  10.	
  
	
  
The	
  gross	
  way	
  —	
  n2	
  
	
  
$set	
  =	
  array(1,	
  6,	
  7,	
  2,	
  5,	
  0,	
  8);	
  
	
  
foreach($set	
  as	
  $a)	
  {	
  
      	
  foreach($set	
  as	
  $b)	
  {	
  
      	
   	
  if($a	
  +	
  $b	
  ==	
  10)	
  
      	
   	
   	
  exit(“Found	
  $a	
  and	
  $b”);	
  
      	
  }	
  
}	
  
	
  
	
  
Find	
  one	
  or	
  two	
  numbers	
  in	
  an	
  array	
  that	
  add	
  to	
  10.	
  
	
  
The	
  real	
  way	
  —	
  n	
  
	
  
$set	
  =	
  array(1,	
  6,	
  7,	
  2,	
  5,	
  0,	
  8);	
  
$flipped	
  =	
  array_flip($a);	
  
	
  
foreach($set	
  as	
  $el)	
  {	
  
      	
  $needed	
  =	
  10	
  -­‐	
  $el;	
  
      	
  if(array_key_exists($needed,	
  $flipped))	
  
      	
   	
  exit(“Found	
  $el	
  and	
  $needed”);	
  
}	
  
	
  
	
  
When	
  You	
  Get	
  Big	
  
•  More	
  machines!	
  with	
  load	
  balancing	
  
•  memcached	
  
•  Master-­‐slave	
  db	
  setup	
  
   –  Writes	
  to	
  master,	
  reads	
  to	
  slave	
  
Takeaways	
  
•  GetSpark’s	
  APC-­‐based	
  Output	
  override	
  
•  These	
  slides	
  


          	
  	
  	
  	
  codefury.net/cicon2011	
  

                   Kenny	
  Katzgrau	
  
                    	
  @_kennyk_	
  
	
  

More Related Content

What's hot

A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webWallace Reis
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webclkao
 
Nuvola: a tale of migration to AWS
Nuvola: a tale of migration to AWSNuvola: a tale of migration to AWS
Nuvola: a tale of migration to AWSMatteo Moretti
 
Declarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformDeclarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformRadek Simko
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricksbcoca
 
Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Jonathon Brouse
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices Nebulaworks
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015Fernando Hamasaki de Amorim
 
[2D1]Elasticsearch 성능 최적화
[2D1]Elasticsearch 성능 최적화[2D1]Elasticsearch 성능 최적화
[2D1]Elasticsearch 성능 최적화NAVER D2
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartHenry Stamerjohann
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2Elizabeth Smith
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRShinji Tanaka
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHPJonathan Klein
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...confluent
 

What's hot (20)

A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
Nuvola: a tale of migration to AWS
Nuvola: a tale of migration to AWSNuvola: a tale of migration to AWS
Nuvola: a tale of migration to AWS
 
Php on Windows
Php on WindowsPhp on Windows
Php on Windows
 
Memcached
MemcachedMemcached
Memcached
 
Declarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformDeclarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with Terraform
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
 
[2D1]Elasticsearch 성능 최적화
[2D1]Elasticsearch 성능 최적화[2D1]Elasticsearch 성능 최적화
[2D1]Elasticsearch 성능 최적화
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / Quickstart
 
Follow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHPFollow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHP
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMR
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
 

Viewers also liked

Luciano Fiandesio - Docker 101 | Codemotion Milan 2015
Luciano Fiandesio - Docker 101 | Codemotion Milan 2015Luciano Fiandesio - Docker 101 | Codemotion Milan 2015
Luciano Fiandesio - Docker 101 | Codemotion Milan 2015Codemotion
 
Codemotion rome 2015 bluemix lab tutorial -- Codemotion Rome 2015
Codemotion rome 2015   bluemix lab tutorial -- Codemotion Rome 2015Codemotion rome 2015   bluemix lab tutorial -- Codemotion Rome 2015
Codemotion rome 2015 bluemix lab tutorial -- Codemotion Rome 2015Codemotion
 
Tool Up Your LAMP Stack
Tool Up Your LAMP StackTool Up Your LAMP Stack
Tool Up Your LAMP StackLorna Mitchell
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack OptimizationDave Ross
 
High Availability for the LAMP Stack
High Availability for the LAMP StackHigh Availability for the LAMP Stack
High Availability for the LAMP StackJason Cannon
 
From single lamp server to high availability stack
From single lamp server to high availability stackFrom single lamp server to high availability stack
From single lamp server to high availability stackStayman Hou
 
The Evolution of Application Release Automation
The Evolution of Application Release AutomationThe Evolution of Application Release Automation
The Evolution of Application Release AutomationJules Pierre-Louis
 
User Centered Design
User Centered DesignUser Centered Design
User Centered DesignShawn Calvert
 
Basics of Web Navigation
Basics of Web NavigationBasics of Web Navigation
Basics of Web NavigationShawn Calvert
 
Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)Kousuke Ebihara
 
PHP projects beyond the LAMP stack
PHP projects beyond the LAMP stackPHP projects beyond the LAMP stack
PHP projects beyond the LAMP stackCodemotion
 
Leading DevOps Application Release and Deployment - Best Practices for Organi...
Leading DevOps Application Release and Deployment - Best Practices for Organi...Leading DevOps Application Release and Deployment - Best Practices for Organi...
Leading DevOps Application Release and Deployment - Best Practices for Organi...IBM UrbanCode Products
 
XL Deploy Demo Slides: Agentless Application Release Automation
XL Deploy Demo Slides: Agentless Application Release AutomationXL Deploy Demo Slides: Agentless Application Release Automation
XL Deploy Demo Slides: Agentless Application Release AutomationXebiaLabs
 
Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...
Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...
Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...Codemotion
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Codemotion
 
Instant LAMP Stack with Vagrant and Puppet
Instant LAMP Stack with Vagrant and PuppetInstant LAMP Stack with Vagrant and Puppet
Instant LAMP Stack with Vagrant and PuppetPatrick Lee
 
Vision and Roadmap: Learn How Application Release Solutions Help You Lead th...
Vision and Roadmap: Learn How Application Release Solutions Help You Lead th...Vision and Roadmap: Learn How Application Release Solutions Help You Lead th...
Vision and Roadmap: Learn How Application Release Solutions Help You Lead th...CA Technologies
 
Master the chaos: from raw data to analytics - Andrea Pompili, Riccardo Rossi...
Master the chaos: from raw data to analytics - Andrea Pompili, Riccardo Rossi...Master the chaos: from raw data to analytics - Andrea Pompili, Riccardo Rossi...
Master the chaos: from raw data to analytics - Andrea Pompili, Riccardo Rossi...Codemotion
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS PresentationShawn Calvert
 

Viewers also liked (20)

Luciano Fiandesio - Docker 101 | Codemotion Milan 2015
Luciano Fiandesio - Docker 101 | Codemotion Milan 2015Luciano Fiandesio - Docker 101 | Codemotion Milan 2015
Luciano Fiandesio - Docker 101 | Codemotion Milan 2015
 
Codemotion rome 2015 bluemix lab tutorial -- Codemotion Rome 2015
Codemotion rome 2015   bluemix lab tutorial -- Codemotion Rome 2015Codemotion rome 2015   bluemix lab tutorial -- Codemotion Rome 2015
Codemotion rome 2015 bluemix lab tutorial -- Codemotion Rome 2015
 
Tool Up Your LAMP Stack
Tool Up Your LAMP StackTool Up Your LAMP Stack
Tool Up Your LAMP Stack
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack Optimization
 
High Availability for the LAMP Stack
High Availability for the LAMP StackHigh Availability for the LAMP Stack
High Availability for the LAMP Stack
 
From single lamp server to high availability stack
From single lamp server to high availability stackFrom single lamp server to high availability stack
From single lamp server to high availability stack
 
The Evolution of Application Release Automation
The Evolution of Application Release AutomationThe Evolution of Application Release Automation
The Evolution of Application Release Automation
 
User Centered Design
User Centered DesignUser Centered Design
User Centered Design
 
Basics of Web Navigation
Basics of Web NavigationBasics of Web Navigation
Basics of Web Navigation
 
Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)
 
PHP projects beyond the LAMP stack
PHP projects beyond the LAMP stackPHP projects beyond the LAMP stack
PHP projects beyond the LAMP stack
 
Leading DevOps Application Release and Deployment - Best Practices for Organi...
Leading DevOps Application Release and Deployment - Best Practices for Organi...Leading DevOps Application Release and Deployment - Best Practices for Organi...
Leading DevOps Application Release and Deployment - Best Practices for Organi...
 
XL Deploy Demo Slides: Agentless Application Release Automation
XL Deploy Demo Slides: Agentless Application Release AutomationXL Deploy Demo Slides: Agentless Application Release Automation
XL Deploy Demo Slides: Agentless Application Release Automation
 
Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...
Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...
Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016
 
Instant LAMP Stack with Vagrant and Puppet
Instant LAMP Stack with Vagrant and PuppetInstant LAMP Stack with Vagrant and Puppet
Instant LAMP Stack with Vagrant and Puppet
 
HTML Email
HTML EmailHTML Email
HTML Email
 
Vision and Roadmap: Learn How Application Release Solutions Help You Lead th...
Vision and Roadmap: Learn How Application Release Solutions Help You Lead th...Vision and Roadmap: Learn How Application Release Solutions Help You Lead th...
Vision and Roadmap: Learn How Application Release Solutions Help You Lead th...
 
Master the chaos: from raw data to analytics - Andrea Pompili, Riccardo Rossi...
Master the chaos: from raw data to analytics - Andrea Pompili, Riccardo Rossi...Master the chaos: from raw data to analytics - Andrea Pompili, Riccardo Rossi...
Master the chaos: from raw data to analytics - Andrea Pompili, Riccardo Rossi...
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 

Similar to Bottom to Top Stack Optimization with LAMP

Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing DaeHyung Lee
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 
(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep DiveAmazon Web Services
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebookguoqing75
 
20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasaggarrett honeycutt
 
Cassandra
CassandraCassandra
Cassandraexsuns
 
Keeping Spark on Track: Productionizing Spark for ETL
Keeping Spark on Track: Productionizing Spark for ETLKeeping Spark on Track: Productionizing Spark for ETL
Keeping Spark on Track: Productionizing Spark for ETLDatabricks
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Designing enterprise drupal
Designing enterprise drupalDesigning enterprise drupal
Designing enterprise drupalJason Burnett
 
Speed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudSpeed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudRevolution Analytics
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
Say YES to Premature Optimizations
Say YES to Premature OptimizationsSay YES to Premature Optimizations
Say YES to Premature OptimizationsMaude Lemaire
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 

Similar to Bottom to Top Stack Optimization with LAMP (20)

Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
php & performance
 php & performance php & performance
php & performance
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag
 
Cassandra
CassandraCassandra
Cassandra
 
Keeping Spark on Track: Productionizing Spark for ETL
Keeping Spark on Track: Productionizing Spark for ETLKeeping Spark on Track: Productionizing Spark for ETL
Keeping Spark on Track: Productionizing Spark for ETL
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Designing enterprise drupal
Designing enterprise drupalDesigning enterprise drupal
Designing enterprise drupal
 
Speed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudSpeed up R with parallel programming in the Cloud
Speed up R with parallel programming in the Cloud
 
Logstash
LogstashLogstash
Logstash
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
Say YES to Premature Optimizations
Say YES to Premature OptimizationsSay YES to Premature Optimizations
Say YES to Premature Optimizations
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 

Recently uploaded

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 

Bottom to Top Stack Optimization with LAMP

  • 1. Bo#om  to  Top  Stack   Op.miza.on   With  LAMP  +  CodeIgniter  
  • 2. Server  side:  It’s  About  I/O   Network  I/O   Disk  I/O   CPU  
  • 3. Server/Client  side:     Minimize  and  Cache  Assets  
  • 4. Op.miza.on  Roadmap   •  System   •  MySQL   •  Apache   •  PHP   •  Framework   •  Applica.on  
  • 5. Tes.ng   •  Frontend   –  Yslow   •  Backend   –  `ab`   –  vmstat  
  • 6. LAMP  Configura.on   •  By  default,  for  “compa.bility”   •  You’re  responsible  for  your  boxes  
  • 7. System   •  Don’t  swap   –  Swap  in  itself  isn’t  bad,  swapping  out  is   •  Get  rid  of  non-­‐essen.al  processes   •  a.me  –  Filesystem  op.on  to  write  ‘last-­‐ accessed’  .me  to  everything   $  cat  /   •  If  you’re  a  badass,  check  into  XFS  
  • 8. a.me   $ cat /etc/fstab proc /proc proc defaults 0 0 /dev/sda1 / ext3 defaults,errors=remount-ro,noatime 0 1 /dev/sda2 none swap sw 0 0
  • 9. MySQL   •  Don’t  “SELECT  *”   –  If  the  data  you  need  is  in  an  index,  MySQL  will  grab  that   •  Column  indexes   –  Foreign  key  type  matching   –  Be  smart  about  column  size   –  Integrity  checks?  Try  NOT  dele.ng  instead   •  Batched  queries   •  Key  Buffer   •  Query  Buffer   •  Engine   –  InnoDB,  or  go  crazy  and  use  Percona  XtraDB  with  XFS  
  • 10. Apache   •  Kill  unneeded  modules   •  Tune  MaxClients   •  Eliminate  .htaccess,  if  possible   •  Kill  access  logs   •  Disable  ETags  if  not  used   •  Expires  Headers   •  Compression   •  Don’t  serve  sta.c  content  (if  you  can  avoid  it)  
  • 11. Benchmarking   •  Apache  bench  is  most  common   –  Tests  Requests  Per  Second   •  Use  vmstat  to  watch  swap  usage   •  Send  1,000  requests,  concurrency  of  10            $ ab –n 1000 –c 10 http://getsparks.org
  • 12. Finished  10000  requests     Server  Soiware:                Apache/2.2.12   Server  Hostname:                getsparks.org   Server  Port:                        80     Document  Path:                    /   Document  Length:                9865  bytes     Concurrency  Level:            10   Time  taken  for  tests:      6.040  seconds   Complete  requests:            10000   …   Requests  per  second:        1655.63  [#/sec]  (mean)   Time  per  request:              6.040  [ms]  (mean)   Time  per  request:              0.604  [ms]  (mean,  across  all  concurrent  requests)   Transfer  rate:                    16260.41  [Kbytes/sec]  received     Percentage  of  the  requests  served  within  a  certain  .me  (ms)      50%          10      …   100%          60  (longest  request)  
  • 13. $ vmstat 5 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 0 0 55152 53212 15128 69172 0 0 0 1 0 1 0 0 100 0 1 0 55152 54428 15132 69172 0 0 0 20 56 48 0 0 100 0
  • 14. Killing  Apache  Modules   $ a2dismod Your choices are: alias auth_basic authn_file authz_default authz_groupfile authz_host authz_user autoindex cgi deflate dir env expires mime negotiation php5 rewrite setenvif status
  • 15. Tuning  MaxClients   “You  can,  and  should,  control  the  MaxClients  se5ng  so  that  your  server  does   not  spawn  so  many  children  it  starts  swapping.”                        -­‐  Apache.org     Usually  in  h#pd.conf  or  apache2.conf     Find  average  size  of  h#p  process  with  `top`  (x).   How  much  RAM  to  dedicate  to  Apache?  (n).     MaxClients  =  floor(n  /  x)     Play  around  with  that  and  Apache  Bench  `ab`  
  • 16. Adding  Expires  Headers   <IfModule mod_expires.c> ExpiresActive on ExpiresByType image/gif "access plus X days" ExpiresByType image/jpeg "access plus X days" ExpiresByType image/png "access plus X days" ExpiresByType text/css "access plus X days" ExpiresByType text/js "access plus X days" ExpiresByType text/javascript "access plus X days" ExpiresByType application/javascript "access plus X days" ExpiresByType application/x-javascript "access plus X days" ExpiresDefault "access plus X days" </IfModule>
  • 17. mod_deflate   •  Compress  your  stuff,  comes  with  Apache   $ a2enmod deflate # … configure in global or vhost config … AddOutputFilterByType DEFLATE text/html text/plain text/xml # … restart Apache $ apache2ctl -k restart
  • 18. Killing  ETags   $  a2enmod  header   #  open  apache.conf  or  h#pd.conf,  add:   Header  unset  ETag   FileETag  None   $  apache2ctl  –k  restart    
  • 19. HTTP  Accelerators   •  Serving  sta.c  content  is  VERY  expensive  for   Apache   •  Varnish,  Squid   $  apt-­‐get  install  varnish   #  go  to  varnish-­‐cache.org  
  • 20. PHP   •  APC   –  Caches  PHP  Op-­‐code,  can  use  as  cache   –  Faster  than  memcache  for  one  box   •  PHP  5.3   •  mysqlnd     •  Output  buffering  tuning,  send  data  to  client   more  frequently  
  • 21. APC  Install   $  apt-­‐get  install  php-­‐pear   …   $  pecl  install  apc       Then  take  a  look  at  cache  size:  apc.shm_size  
  • 22. Framework  (CodeIgniter)   •  Page  Caching   –  Personalized  info,  uh  oh.   •  Query  Result  Caching   •  Configura.on   –  Disable  verbose  logging   –  Output  compression   –  config/database.php:  autoinit?   •  Minifying,  combining  assets   –  ‘assets’  Spark  
  • 23. Applica.on   •  Most  op.miza.on  does  not  occur  within  code   •  Use  built-­‐in  PHP  func.ons   •  Use  associa.ve  arrays  (hashes,  dic.onaries)   •  Batch  DB  Inserts,  Selects   •  Don’t  use  references  unless  it  makes  sense   –  Like…  $CI  =  &  get_instance();   •  require_once  is  expensive   •  count()  elements  before  start  ‘for’  loop  
  • 24. Applica.on  (cont’d)   •  Don’t  copy  variables  if  you  don’t  have  to    foreach($db_result  as  $row)  {      $content  =  $row[‘content’];      $content  =  word_limited($content,  100);    }     And  the  usual:  require_once,  etc.  
  • 25. Find  one  or  two  numbers  in  an  array  that  add  to  10.     The  gross  way  —  n2     $set  =  array(1,  6,  7,  2,  5,  0,  8);     foreach($set  as  $a)  {    foreach($set  as  $b)  {      if($a  +  $b  ==  10)        exit(“Found  $a  and  $b”);    }   }      
  • 26. Find  one  or  two  numbers  in  an  array  that  add  to  10.     The  real  way  —  n     $set  =  array(1,  6,  7,  2,  5,  0,  8);   $flipped  =  array_flip($a);     foreach($set  as  $el)  {    $needed  =  10  -­‐  $el;    if(array_key_exists($needed,  $flipped))      exit(“Found  $el  and  $needed”);   }      
  • 27. When  You  Get  Big   •  More  machines!  with  load  balancing   •  memcached   •  Master-­‐slave  db  setup   –  Writes  to  master,  reads  to  slave  
  • 28. Takeaways   •  GetSpark’s  APC-­‐based  Output  override   •  These  slides          codefury.net/cicon2011   Kenny  Katzgrau    @_kennyk_