Looking at historic, current and evolving approaches, I will take you through from how we used to 'live' edit on one server with HTML in the code; to implementing Template Toolkit and 'front end / back end' servers; to the addition of version control; all the way through to distributed caching, file systems and processing (aka Six Apart worship) with 15+ servers.
28. Code, not HTML
use CGI;
use Template;
$q = CGI->new();
print $q->header('text/html');
my %vals = (
name = $q->param('name'),
);
$template =
Template->new({ INCLUDE => '/path/' });
$template->process('hello.html',%vals);
29. I just code, I have
clean code and I don't
have to know HTML or
browser compatibility
issues
37. 1 live server
1 development server
Internet
Live server Development server
Web server Web server
All editing
(static & dynamic) (static & dynamic)
Database server Database server
38. Does not solve:
What did I change last?
Who changed what / when?
51. Tests - all you need on one slide
Write tests, write tests often
52. Tests - all you need on one slide
Write tests, write tests often
Run tests, run tests often
53. Tests - all you need on one slide
Write tests, write tests often
Run tests, run tests often
Tests are good
54. Tests - all you need on one slide
Write tests, write tests often
Run tests, run tests often
Tests are good
Found a bug? - write the test that replicates it.
You know it's fixed when your test passes
55. Tests - all you need on one slide
Write tests, write tests often
Run tests, run tests often
Tests are good
Found a bug? - write the test that replicates it.
You know it's fixed when your test passes
Use Test::More, and then test some more!
59. mod_perl
Code caching (loaded/compiled once)
Server only spends time running the code
60. mod_perl
Code caching (loaded/compiled once)
Server only spends time running the code
Apache::Registry for old/existing code
61. mod_perl
Code caching (loaded/compiled once)
Server only spends time running the code
Apache::Registry for old/existing code
Apache::SizeLimit (safety net)
62. mod_perl
Code caching (loaded/compiled once)
Server only spends time running the code
Apache::Registry for old/existing code
Apache::SizeLimit (safety net)
Set it high
63. mod_perl
Code caching (loaded/compiled once)
Server only spends time running the code
Apache::Registry for old/existing code
Apache::SizeLimit (safety net)
Set it high
Check it
65. Front/back end split
Internet
Slow
Back end
Front end
(application server)
Fast
Web server
Web server
(static & proxy to
(dynamic)
application server)
Database server
Development
server
67. or put another way...
Internet
slow and
demanding
kids
(users)
68. or put another way...
Canteen
Internet Front end
slow and Dinner-ladies - good at
demanding serving precooked
kids (static) food. Can order
(users) from à la carte chefs
and then serve
69. or put another way...
Canteen Kitchen
Internet Front end Back end
slow and Dinner-ladies - good at Chefs - good at
demanding serving precooked making à la carte
kids (static) food. Can order (dynamic) food
(users) from à la carte chefs
and then serve
70. Internet
Slow
Back end
Front end
(application server)
Fast
Web server
Web server
(static & proxy to
(dynamic)
application server)
Database server
Development
server
71. Internet
Slow
Back end
Front end
(application server)
Fast
Web server
Web server
(static & proxy to
(dynamic)
application server)
Database server
Development
server
79. Add caching
Persisting data for a period of time
Simple to implement:
Does cache exist?
YES -> retrieve it and return it
80. Add caching
Persisting data for a period of time
Simple to implement:
Does cache exist?
YES -> retrieve it and return it
NO -> create data/object, store in cache
and return it
83. Things you might cache
Search result sets (a list of ids)
Individual items
84. Things you might cache
Search result sets (a list of ids)
Individual items
Look-ups of information from a database
85. Things you might cache
Search result sets (a list of ids)
Individual items
Look-ups of information from a database
Fetching of information from external sources
88. Centralise
Put caching methods in one package
Put any generic methods in a package
89. We now have a cache
Internet
Slow
Back end
Front end
(application server)
Fast
Web server
Web server
(static & proxy to Cache
(dynamic)
application server)
Database server
Development
server
90. We now have a cache
Internet
Slow
Back end
Front end
(application server)
Fast
Web server
Web server
(static & proxy to Cache
Cache
(dynamic)
application server)
Database server
Development
server
97. Coping with more traffic
Development
Internet
Stage server server (in the
office)
Front end
Back end
Web server (application server)
Database
(static & proxy
server
to application Web server
server) (dynamic)
Back end
(application server)
Web server
(dynamic)
98. Coping with more traffic
Development
Internet
Stage server server (in the
office)
Front end
Back end
Web server (application server)
Database
(static & proxy
server
to application Web server
server) (dynamic)
Back end
(application server)
Web server
(dynamic)
100. That's two separate disks
Development
Internet
Stage server server (in the
office)
Front end
Back end
Web server (application server)
Database
(static & proxy
server
to application Web server Cache
server) (dynamic)
Back end
(application server)
Web server Cache
(dynamic)
107. We want a cache across
servers...
Enter
Memcache
108. We want a cache across
servers...
Enter
Memcache
See Léon Brocard's talk
at 16:20 for the details
109. Development
Internet
Stage server server (in the
office)
Front end
Back end
Web server (application server)
Database
(static & proxy
server
to application Web server
server) (dynamic)
Cache
Back end
(application server)
Web server
(dynamic)
117. Maintaining servers
Keep all servers identical where possible
Package your code (e.g. .debs)
118. Maintaining servers
Keep all servers identical where possible
Package your code (e.g. .debs)
Centralise your crontabs and configuration files
(and put in version control)
119. Maintaining servers
Keep all servers identical where possible
Package your code (e.g. .debs)
Centralise your crontabs and configuration files
(and put in version control)
Deploy with one script: rsync + ssh + apt-get
update & apt-get upgrade (or your OS
equivalent) to each server
120. Simplify further
Development
Internet
Stage server server (in the
office)
Front end
Back end
Perlbal
Web server
load balancer /
(static+dynamic)
proxy
Database
Cache
server
Back end
Web server
(static+dynamic)
121. Simplify further
Development
Internet
Stage server server (in the
office)
Front end
Back end
Perlbal
Web server
load balancer /
(static+dynamic)
proxy
Database
Cache
server
Back end
Web server
(static+dynamic)
122. Simplify further
Development
Internet
Stage server server (in the
office)
Front end
Back end
Perlbal
Web server
load balancer /
(static+dynamic)
proxy
Database
Cache
server
Back end
Web server
(static+dynamic)
125. Waiters: cheaper, faster and
less demanding
Front end
Internet
Waiters - good at serving
Kids
quickly and dealing with
annoying customers or
Kitchens
126. Waiters: cheaper, faster and
less demanding
Kitchen 1
Kitchen 2
Front end
Internet
Waiters - good at serving
Kids Back end
quickly and dealing with
annoying customers or Chefs - simple and complex meals
(static and dynamic)
Kitchens
127. Waiters: cheaper, faster and
less demanding
Kitchen 1
Kitchen 2
Front end
Internet
Waiters - good at serving
Kids Back end
quickly and dealing with Cache
annoying customers or Chefs - simple and complex meals Freezer
(static and dynamic)
Kitchens
141. Cache somethings forever
/includes/js/<VERSION>/common.js
Ensures user has version which matches HTML
(client could have cache of old HTML)
142. Cache somethings forever
/includes/js/<VERSION>/common.js
Ensures user has version which matches HTML
(client could have cache of old HTML)
Use include file to update all pages
145. Handling images: MogileFS
Store images by group (replication levels)
Spread IO across disks & servers
146. Handling images: MogileFS
Store images by group (replication levels)
Spread IO across disks & servers
Retrieve from fastest server
147. Handling images: MogileFS
Store images by group (replication levels)
Spread IO across disks & servers
Retrieve from fastest server
Integrate with Perlbal, hidden from the user
148. Handling images: MogileFS
Store images by group (replication levels)
Spread IO across disks & servers
Retrieve from fastest server
Integrate with Perlbal, hidden from the user
Automatic resilience
149. Handling images: MogileFS
Store images by group (replication levels)
Spread IO across disks & servers
Retrieve from fastest server
Integrate with Perlbal, hidden from the user
Automatic resilience
151. Basic rules to consider
Centralise (code/templates/configuration/
deployment etc)
152. Basic rules to consider
Centralise (code/templates/configuration/
deployment etc)
Test, run lots of them
153. Basic rules to consider
Centralise (code/templates/configuration/
deployment etc)
Test, run lots of them
Cache if you need it; memcache is great
154. Basic rules to consider
Centralise (code/templates/configuration/
deployment etc)
Test, run lots of them
Cache if you need it; memcache is great
Keep is simple (perlbal especially)
155. Basic rules to consider
Centralise (code/templates/configuration/
deployment etc)
Test, run lots of them
Cache if you need it; memcache is great
Keep is simple (perlbal especially)
Sometimes it's just easier to buy another server
(this is not always true)