Upload
leo-lapworth
View
5.923
Download
0
Embed Size (px)
DESCRIPTION
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.
Citation preview
Evolving architecturemake development easy and your site faster
Leo Lapworth @ YAPC::EU 2007http://leo.cuckoo.org/
Covering
Covering
How running websites has evolved
Covering
How running websites has evolved
Servers improved
Covering
How running websites has evolved
Servers improved
Architecture improved
Covering
How running websites has evolved
Servers improved
Architecture improved
Development tools improved
Covering
How running websites has evolved
Servers improved
Architecture improved
Development tools improved
Code (and code libraries) got better
but not...
but not...
Covering anything in depth
Concepts stolen from
Concepts stolen from
Mod_perl guide
Concepts stolen from
Mod_perl guide
Léon Brocard
Concepts stolen from
Mod_perl guide
Léon Brocard
Six Apart
Concepts stolen from
Mod_perl guide
Léon Brocard
Six Apart
Yahoo!
Concepts stolen from
Mod_perl guide
Léon Brocard
Six Apart
Yahoo!
+ many other people...
Concepts stolen from
Mod_perl guide
Léon Brocard
Six Apart
Yahoo!
+ many other people...
... this is social Perl
Templates
TemplatesAn example of how things have improved...
Recognise this?
Recognise this?use CGI;$q = CGI->new();$name = $q->param('name');print $q->header('text/html');$link = 'http://foo.com/';print "<html><head><title>HTML and code together</title></head><body>";print "<a href=\"$link/$name\">";print "Click here $name</a><br />\n";print "<table>" . join("\n", map { "<tr><td>$_</td></tr>"} qw(this is hard to maintain));print "</table>";
How about...
How about...
Now, was it cellspacing, or cellpadding I need for ie4.02?
and...
and...
I'm a developer, not a designer. I shouldn't have to know this £@$%!
Use templates...
Use templates...
use Template;
Code, not HTML
Code, not HTMLuse 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);
I just code, I have clean code and I don't
have to know HTML or browser compatibility
issues
Simple changes make a huge difference
Servers
Single server
Single server
Internet
Web server
(static & dynamic)
Database server
All editing
Lots of...
and...
I thought I only changed one thing, but
it's still broken
1 live server 1 development server
1 live server 1 development server
Internet
Live server
Web server
(static & dynamic)
Database server
All editing
Development server
Web server
(static & dynamic)
Database server
Does not solve:
What did I change last?
Who changed what / when?
You need...
You need...
Version control & docs
Version control & docs
Use SVK with Subversion
Version control & docs
Use SVK with Subversion
Version control & docs
Clkao - SVK
Use SVK with Subversion
Version control & docs
Clkao - SVK
Use Trac (http://trac.edgewall.org)
Use SVK with Subversion
Version control & docs
Clkao - SVK
Use Trac (http://trac.edgewall.org) - wiki
Use SVK with Subversion
Version control & docs
Clkao - SVK
Use Trac (http://trac.edgewall.org) - wiki- task tracker
Use SVK with Subversion
Version control & docs
Clkao - SVK
Use Trac (http://trac.edgewall.org) - wiki- task tracker- web interface to Subversion
Use SVK with Subversion
Tests - all you need on one slide
Tests - all you need on one slide
Write tests, write tests often
Tests - all you need on one slide
Write tests, write tests often
Run tests, run tests often
Tests - all you need on one slide
Write tests, write tests often
Run tests, run tests often
Tests are good
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
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!
Making your site faster
mod_perl
mod_perl
Code caching (loaded/compiled once)
mod_perl
Code caching (loaded/compiled once)
Server only spends time running the code
mod_perl
Code caching (loaded/compiled once)
Server only spends time running the code
Apache::Registry for old/existing code
mod_perl
Code caching (loaded/compiled once)
Server only spends time running the code
Apache::Registry for old/existing code
Apache::SizeLimit (safety net)
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
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
Front/back end split
Front/back end split
Internet
Front end
Web server
(static & proxy to
application server)
Development
server
Back end
(application server)
Web server
(dynamic)
Database server
Slow
Fast
or put another way...
or put another way...
Internetslow and
demanding kids
(users)
or put another way...
Internetslow and
demanding kids
(users)
Front endDinner-ladies - good at
serving precooked (static) food. Can order from à la carte chefs
and then serve
Canteen
or put another way...
Internetslow and
demanding kids
(users)
Back endChefs - good at
making à la carte (dynamic) food
Kitchen
Front endDinner-ladies - good at
serving precooked (static) food. Can order from à la carte chefs
and then serve
Canteen
Internet
Front end
Web server
(static & proxy to
application server)
Development
server
Back end
(application server)
Web server
(dynamic)
Database server
Slow
Fast
Internet
Front end
Web server
(static & proxy to
application server)
Development
server
Back end
(application server)
Web server
(dynamic)
Database server
Slow
Fast
Speed up the frequent...
Speed up the frequent...
Are you re-creating the same objects/data structures again and again?
Speed up the frequent...
Are you re-creating the same objects/data structures again and again?
Can this information persist for a period of time?
Add caching
Add caching
Persisting data for a period of time
Add caching
Persisting data for a period of time
Simple to implement:
Add caching
Persisting data for a period of time
Simple to implement:
Does cache exist?
Add caching
Persisting data for a period of time
Simple to implement:
Does cache exist?
YES -> retrieve it and return it
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
Things you might cache
Things you might cache
Search result sets (a list of ids)
Things you might cache
Search result sets (a list of ids)
Individual items
Things you might cache
Search result sets (a list of ids)
Individual items
Look-ups of information from a database
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
Centralise
Centralise
Put caching methods in one package
Centralise
Put caching methods in one package
Put any generic methods in a package
We now have a cache
Internet
Front end
Web server
(static & proxy to
application server)
Development
server
Back end
(application server)
Web server
(dynamic)
Database server
Slow
Fast
Cache
We now have a cache
Internet
Front end
Web server
(static & proxy to
application server)
Development
server
Back end
(application server)
Web server
(dynamic)
Database server
Slow
Fast
CacheCache
Adding in the cache...
Adding in the cache...
InternetKids
Adding in the cache...
InternetKids
Front endDinner-ladies
Adding in the cache...
InternetKids
Back endChefs
Front endDinner-ladies
Adding in the cache...
CacheMagic
freezer
InternetKids
Back endChefs
Front endDinner-ladies
Coping with more traffic
Coping with more traffic
Internet
Front end
Web server
(static & proxy
to application
server)
Stage server
Back end
(application server)
Web server
(dynamic)
Development
server (in the
office)
Database
server
Back end
(application server)
Web server
(dynamic)
Coping with more traffic
Internet
Front end
Web server
(static & proxy
to application
server)
Stage server
Back end
(application server)
Web server
(dynamic)
Development
server (in the
office)
Database
server
Back end
(application server)
Web server
(dynamic)
That's two separate disks
That's two separate disks
Internet
Front end
Web server
(static & proxy
to application
server)
Stage server
Back end
(application server)
Web server
(dynamic)
Development
server (in the
office)
Database
server
Back end
(application server)
Web server
(dynamic)Cache
Cache
Second kitchen, two freezers...
Second kitchen, two freezers...
InternetKids
Second kitchen, two freezers...
InternetKids
Front endDinner-ladies
Second kitchen, two freezers...
InternetKids
Back endChefs
Kitchen 1
Kitchen 2
Front endDinner-ladies
Second kitchen, two freezers...
InternetKids
Back endChefs
Kitchen 1
Kitchen 2
CacheFreezers
Front endDinner-ladies
We want a cache across servers...
We want a cache across servers...
EnterMemcache
We want a cache across servers...
EnterMemcache
See Léon Brocard's talkat 16:20 for the details
Internet
Front end
Web server
(static & proxy
to application
server)
Stage server
Back end
(application server)
Web server
(dynamic)
Development
server (in the
office)
Database
server
Back end
(application server)
Web server
(dynamic)
Cache
Shared freezer
Shared freezer
InternetKids
Shared freezer
InternetKids
Front endDinner-ladies
Shared freezer
InternetKids Back end
Chefs
Kitchen 1
Kitchen 2
Front endDinner-ladies
Shared freezer
InternetKids Back end
Chefs
Kitchen 1
Kitchen 2
CacheFreezer
Front endDinner-ladies
Maintaining servers
Maintaining servers
Keep all servers identical where possible
Maintaining servers
Keep all servers identical where possible
Package your code (e.g. .debs)
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)
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
Simplify further
Internet
Front end
Perlbal
load balancer /
proxy
Stage server
Back end
Web server
(static+dynamic)
Development
server (in the
office)
Database
server
Back end
Web server
(static+dynamic)
Cache
Simplify further
Internet
Front end
Perlbal
load balancer /
proxy
Stage server
Back end
Web server
(static+dynamic)
Development
server (in the
office)
Database
server
Back end
Web server
(static+dynamic)
Cache
Simplify further
Internet
Front end
Perlbal
load balancer /
proxy
Stage server
Back end
Web server
(static+dynamic)
Development
server (in the
office)
Database
server
Back end
Web server
(static+dynamic)
Cache
Waiters: cheaper, faster and less demanding
Waiters: cheaper, faster and less demanding
InternetKids
Waiters: cheaper, faster and less demanding
InternetKids
Front endWaiters - good at serving quickly and dealing with annoying customers or
Kitchens
Waiters: cheaper, faster and less demanding
InternetKids Back end
Chefs - simple and complex meals(static and dynamic)
Kitchen 1
Kitchen 2
Front endWaiters - good at serving quickly and dealing with annoying customers or
Kitchens
Waiters: cheaper, faster and less demanding
InternetKids Back end
Chefs - simple and complex meals(static and dynamic)
Kitchen 1
Kitchen 2
CacheFreezer
Front endWaiters - good at serving quickly and dealing with annoying customers or
Kitchens
More tips for faster user experience
mod_gzip
mod_gzip
HTML/css/xml
mod_gzip
HTML/css/xml
mod_gzip
HTML/css/xml gzip
mod_gzip
HTML/css/xml gzip
mod_gzip
HTML/css/xml gzip Users
mod_gzip
HTML/css/xml gzip
If a browser support compressions... compress(javascript can be tricky - at least minify)
Users
Cache headers (expiry)
Cache headers (expiry)
Cache headers (expiry)
Let web browsers know how long to cache
Cache somethings forever
Cache somethings forever
/includes/js/<VERSION>/common.js
Cache somethings forever
Ensures user has version which matches HTML (client could have cache of old HTML)
/includes/js/<VERSION>/common.js
Cache somethings forever
Ensures user has version which matches HTML (client could have cache of old HTML)
Use include file to update all pages
/includes/js/<VERSION>/common.js
Handling images: MogileFS
Handling images: MogileFS
Store images by group (replication levels)
Handling images: MogileFS
Store images by group (replication levels)
Spread IO across disks & servers
Handling images: MogileFS
Store images by group (replication levels)
Spread IO across disks & servers
Retrieve from fastest server
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
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
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
Basic rules to consider
Basic rules to consider
Centralise (code/templates/configuration/deployment etc)
Basic rules to consider
Centralise (code/templates/configuration/deployment etc)
Test, run lots of them
Basic rules to consider
Centralise (code/templates/configuration/deployment etc)
Test, run lots of them
Cache if you need it; memcache is great
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)
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)
We covered...
We covered...
perlbal
We covered...
perlbal
memcached
We covered...
perlbal
memcached
svk (subversion)
We covered...
perlbal
memcached
svk (subversion)
trac
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
gzip
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
gzip
mogileFS
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
gzip
mogileFS
server architecture
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
gzip
mogileFS
server architecture
Test::More
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
gzip
mogileFS
server architecture
Test::More
mod_perl
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
gzip
mogileFS
server architecture
Test::More
mod_perl
Template::Toolkit
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
gzip
mogileFS
server architecture
Test::More
mod_perl
Template::Toolkit
HTTP Cache headers
We covered...
perlbal
memcached
svk (subversion)
trac
rsync
gzip
mogileFS
server architecture
Test::More
mod_perl
Template::Toolkit
HTTP Cache headers
and...
...how a kitchen should run
...how a kitchen should run
...how a kitchen should run
Any questions?
Evolving architecturehttp://leo.cuckoo.org/projects/ea/
Leo Lapworthhttp://leo.cuckoo.org/