39
Peter C. Verhage June 12th 2009 Surviving a Plane Crash a NU.nl case-study

Surviving a Plane Crash, a NU.nl case-study

Embed Size (px)

DESCRIPTION

A NU.nl case-study about how to handle large amounts of traffics.

Citation preview

Page 1: Surviving a Plane Crash, a NU.nl case-study

Peter C. VerhageJune 12th 2009

Surviving a Plane Crasha NU.nl case-study

Page 2: Surviving a Plane Crash, a NU.nl case-study

Surviving a Plane Crash

NU.nl

• most popular Dutch news website

• 10th anniversary

• 4.5 million unique visitors each month

• 7-15 million page views each day

Me

The plane crash

• 20.2 million page views

• 1.83 Gbit/s traffic

2

Page 3: Surviving a Plane Crash, a NU.nl case-study

Surviving a Plane Crash

CMS

Front-end

Performance

QA

3

Page 4: Surviving a Plane Crash, a NU.nl case-study

CMS

4

Page 5: Surviving a Plane Crash, a NU.nl case-study

CMS

100% custom

PHP 5.1 / MySQL 5

ATK framework

• in-house developed

• Open Source (LGPL)

• specializes in CMS-like applications

Prototype / Scriptaculous

5

Page 6: Surviving a Plane Crash, a NU.nl case-study

CMS

6

vs

Page 7: Surviving a Plane Crash, a NU.nl case-study

CMS

7

Page 8: Surviving a Plane Crash, a NU.nl case-study

CMS

8

Page 9: Surviving a Plane Crash, a NU.nl case-study

CMS

9

Page 10: Surviving a Plane Crash, a NU.nl case-study

CMS

10

Page 11: Surviving a Plane Crash, a NU.nl case-study

CMS

11

Page 12: Surviving a Plane Crash, a NU.nl case-study

Front-end

12

Page 13: Surviving a Plane Crash, a NU.nl case-study

Front-end

Multiple sites (NU, NUvideo, NUfoto, NUsport, ...)

CodeIgniter framework

• PHP 4 :(

• lightweight MVC

• extensible

Extensions

• Snippets

• Globalization (i18n / l10n)

• Code sharing between sites

13

Page 14: Surviving a Plane Crash, a NU.nl case-study

Front-endSnippets

14

Page 15: Surviving a Plane Crash, a NU.nl case-study

Front-end: Snippets

15

Page 16: Surviving a Plane Crash, a NU.nl case-study

Front-end: Snippets

16

header

Page 17: Surviving a Plane Crash, a NU.nl case-study

Front-end: Snippets

17

navigation

Page 18: Surviving a Plane Crash, a NU.nl case-study

Front-end: Snippets

18

sidebar

Page 19: Surviving a Plane Crash, a NU.nl case-study

Front-end: Snippets

19

other news

Page 20: Surviving a Plane Crash, a NU.nl case-study

Front-end: Snippets

20

article

Page 21: Surviving a Plane Crash, a NU.nl case-study

Front-end: Snippets

snippets

• are like ZF partials, but more powerful

• contain logic that doesn’t belong in the template / view

• have full access to the model

• render a view for their result

• so a lot like a controller action

• but more re-usable

21

abstract class Snippet { public function __construct($params); protected function getParam(); protected function renderView($name, $params); public abstract function render(); public function getPath(); ...}

Page 22: Surviving a Plane Crash, a NU.nl case-study

Front-endGlobalization

22

Page 23: Surviving a Plane Crash, a NU.nl case-study

Front-end: Globalization

Dnews.de; german version of NU.nl

Same code base, different configuration

Default CodeIgniter globalization not sufficient

Custom globalization consists of:

• translations

• template overrides

• snippet overrides

• css / javascript overrides

• routing overrides

23

Page 24: Surviving a Plane Crash, a NU.nl case-study

Front-endCode Sharing

24

Page 25: Surviving a Plane Crash, a NU.nl case-study

Front-end: Code Sharing

Good developers are lazy developers

Lazy developers are good developers

Avoid code duplication

Each site has its own code base

One shared code base

Class not found in site code base? → Try shared code base

Small variations can be tweaked in the site configuration

25

Page 26: Surviving a Plane Crash, a NU.nl case-study

Performance

26

Page 27: Surviving a Plane Crash, a NU.nl case-study

Performance

Static HTML

Going more dynamic

A Layer of Varnish

Hardware setup

27

Page 28: Surviving a Plane Crash, a NU.nl case-study

PerformanceStatic HTML

28

Page 29: Surviving a Plane Crash, a NU.nl case-study

Performance: Static HTML

Nothing beats static HTML

Snippets; the problem

Task Scheduler

Degradation

29

Page 30: Surviving a Plane Crash, a NU.nl case-study

PerformanceGoing more dynamic

30

Page 31: Surviving a Plane Crash, a NU.nl case-study

Performance: Going more dynamic

NUfoto / NUvideo

Lists ordered by date

Problem

• latest photo / video is pushed on top

• pagination continuously changes

Solution

• use a proxy server

• use Memcache

• generate HTML for first few pages

31

Page 32: Surviving a Plane Crash, a NU.nl case-study

Performance: Going more dynamic

Showing the logged in user

Problem

• every page is customized for the user

Solution

• set cookie with display data

• use JavaScript to inject

• don’t cache real user specific pages

• never trust the cookie!

32

Page 33: Surviving a Plane Crash, a NU.nl case-study

PerformanceA Layer of Varnish

33

Page 34: Surviving a Plane Crash, a NU.nl case-study

Performance: A Layer of Varnish

Open Source reverse proxy server

Serves from memory

Blazingly fast

Snippets; the solution → ESI

• Edge Side Includes (W3C standard)

• In-memory

• Remember Snippet::getPath()?

• Example:<esi:include src=”/includes/site/sections/algemeen.html”/>

34

Page 35: Surviving a Plane Crash, a NU.nl case-study

PerformanceHardware setup

35

Page 36: Surviving a Plane Crash, a NU.nl case-study

Performance: Hardware setup

2 back-end servers (apache / master db), only 1 active

4 front-end servers (apache / slave db)

4 front-end Varnish proxy servers

4 media Varnish proxy servers

Juniper load balancers

36

Page 37: Surviving a Plane Crash, a NU.nl case-study

Questions ?

37

Page 38: Surviving a Plane Crash, a NU.nl case-study

Thank you!

Contact details:

E-mail: [email protected]: peter-ibuildings