DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)

Post on 08-May-2015

1.664 views 1 download

description

Dutch PHP Conference 2007

Transcript of DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)

Sander van de GraafIDG Nederland

Web 2.0

Topics

• Webwereld / Zoom

• Bottlenecks

• PHP

• MySQL

• Apache

• Caching

• Vragen

Webwereld / Zoom

Webwereld

• 4,5 miljoen pageviews per maand

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Webwereld

• 4,5 miljoen pageviews per maand

• 99% dynamisch

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Webwereld

• 4,5 miljoen pageviews per maand

• 99% dynamisch

• Virtualhost

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Webwereld

• 4,5 miljoen pageviews per maand

• 99% dynamisch

• Virtualhost

• PHP 4

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Webwereld

• 4,5 miljoen pageviews per maand

• 99% dynamisch

• Virtualhost

• PHP 4

• scripts

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Webwereld

• 4,5 miljoen pageviews per maand

• 99% dynamisch

• Virtualhost

• PHP 4

• scripts

• Smarty

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Zoom.nl

• 5+ miljoen pageviews

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Zoom.nl

• 5+ miljoen pageviews

• 100% dynamisch

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Zoom.nl

• 5+ miljoen pageviews

• 100% dynamisch

• 2 webservers

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Zoom.nl

• 5+ miljoen pageviews

• 100% dynamisch

• 2 webservers

• 3,8TB data

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Zoom.nl

• 5+ miljoen pageviews

• 100% dynamisch

• 2 webservers

• 3,8TB data

• ImageMagick ipv GD

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Zoom.nl

• 5+ miljoen pageviews

• 100% dynamisch

• 2 webservers

• 3,8TB data

• ImageMagick ipv GD

• Smarty

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Bottlenecks

Bottlenecks

• Applicatie

• Database

• NAS

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

PHP

PHP

• Optimalisaties

• APD

• Intermediate Code Caching

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties

for($foo=0;$foo<count($bar);$foo++)

{

// do something

}

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties

$barCount = count($bar);

for($foo=0;$foo<$barCount;++$foo)

{

// do something

}

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

APD

PProf

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

APD

apd_set_pprof_trace();

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Intermediate code caching

• eAccelerator

• Zend Optimizer

• APC

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

MySQL

MySQL

• Background

• Optimalisaties

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Background

• MySQL 4.1.10

• 2 database servers

• MyISAM

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

ORDER BY RAND()

SELECT * FROM images ORDER BY RAND() LIMIT 10;

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

ORDER BY RAND()

SELECT * FROM images

WHERE id IN (1243,34234,2341,135465,123,653);

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

WHERE 1

SELECT * FROM images WHERE 1 ORDER BY id DESC LIMIT 10;

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

WHERE 1

SELECT * FROM images ORDER BY id DESC LIMIT 10;

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

• Indexes

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Force Index

SELECT * FROM images FORCE INDEX(user_id)

WHERE user_id = “12”

ORDER BY created_on DESC

LIMIT 10

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

• Indexes

• EXPLAIN

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

EXPLAIN SELECT * FROM images LIMIT 10;

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

EXPLAIN SELECT * FROM images LIMIT 10;

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

EXPLAIN SELECT I.* FROM images I, zoom_profile.users U WHERE I.user_id = U.id AND I.user_id = 1244 LIMIT 10;

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

• Indexes

• EXPLAIN

• Connection types

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

• Indexes

• EXPLAIN

• Connection types

• Table optimalisaties

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

• Indexes

• EXPLAIN

• Connection types

• Table optimalisaties

• PROCESSLIST

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

• Indexes

• EXPLAIN

• Connection types

• Table optimalisaties

• PROCESSLIST

• MTOP

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

• Indexes

• EXPLAIN

• Connection types

• Table optimalisaties

• PROCESSLIST

• MTOP

• SLOW Query LogWebwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Optimalisaties• Valkuilen

• Indexes

• EXPLAIN

• Connection types

• Table optimalisaties

• PROCESSLIST

• MTOP

• SLOW Query Log

• De-normalisatieWebwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Apache

Apache

• Apache 2.0

• htaccess

• mod_expires

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

.htaccess

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} ^.*public_images.*$

RewriteRule ^public_images/([0-9]*)/([0-9]*)/(.*)$

/do_some_magic_stuff.php?user_id=$1&width=$2&filename=$

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

.htaccess

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} ^.*public_images.*$

RewriteRule ^public_images/([0-9]*)/([0-9]*)/(.*)$

/do_some_magic_stuff.php?user_id=$1&width=$2&filename=$

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

mod_expires

<IfModule mod_expires.c> ExpiresActive ON ExpiresByType image/gif "now plus 1 week" ExpiresByType image/png "now plus 1 week" ExpiresByType image/jpeg "now plus 1 week" ExpiresByType text/css "now plus 15 minute" ExpiresByType application/x-javascript "now plus 15 min" ExpiresDefault "now" </IfModule>

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Caching

Caching

• (intermediate) Code Caching

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Caching

• (intermediate) Code Caching

• Page caching

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Caching

• (intermediate) Code Caching

• Page caching

• Fragment caching

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Caching

• (intermediate) Code Caching

• Page caching

• Fragment caching

• Object caching

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Caching

• (intermediate) Code Caching

• Page caching

• Fragment caching

• Object caching

• Content caching

Webwereld / ZoomBottlenecks

PHPMySQLApache

CachingVragen

Vragen?