22
Building Scalable Websites with Perl Perrin Harkins Plus Three (http://plusthree.com/)

Building Scalable Websites with Perl

Embed Size (px)

DESCRIPTION

This talk was presented at OSCON 2004, ApacheCon 2004, and YAPC::NA 2004.

Citation preview

Page 1: Building Scalable Websites with Perl

Building Scalable Websites with Perl

Perrin HarkinsPlus Three (http://plusthree.com/)

Page 2: Building Scalable Websites with Perl

Who is doing it?

• Yahoo– Overture

• Amazon– IMDB

• InterActiveCorp– Ticketmaster

– CitySearch

Page 3: Building Scalable Websites with Perl

How are they doing it?

• Not just hardware

• Basic techniques

Page 4: Building Scalable Websites with Perl

Things we won't be covering

• mod_perl tuning– http://perl.apache.org/

• DBI tuning– http://search.cpan.org/~timb/

• hardware

Page 5: Building Scalable Websites with Perl

Caching

Page 6: Building Scalable Websites with Perl

Page-Level Caching

• Best performance

• Pre-generate from batch job

clientweb

server

databatchjob

pagecache

Page 7: Building Scalable Websites with Perl

wget

wget ­­mirror ­­convert­links \

   ­­html­extension ­­reject gif,jpg,png \

   ­­no­parent \

   http://app­server/dynamic/pages/

clientweb

server data

wgetpagecache

appserver

Page 8: Building Scalable Websites with Perl

Generate-On-Demand

clientweb

server

data

appserver

mod_proxycache

Page 9: Building Scalable Websites with Perl

mod_proxy

ProxyRequests Off

ProxyPass /dynamic/stuff http://app­server/

ProxyPassReverse /dynamic/stuff http://app­server/

CacheRoot "/mnt/proxy­cache"

CacheSize 500000

CacheGcInterval 12

CacheMaxExpire 36

CacheDefaultExpire 2

Page 10: Building Scalable Websites with Perl

Intercepting 404 Errors

ErrorDocument 404 /page/generator

client pagecache

webserver

404handler data

Page 11: Building Scalable Websites with Perl

Partial-Page Caching

2 hours

5 minutes

24 hours

Page 12: Building Scalable Websites with Perl

Mason cache

  my $result = $m­>cache­>get(

                         $search_term

                             );

  if (!defined($result)) {

      $result = run_search($search_term);

      $m­>cache­>set($search_term,

                     $result,                                  '30 min');

  }

Page 13: Building Scalable Websites with Perl

Cache::FastMmap

  our $Cache = Cache::FastMmap­>new(

                    cache_size  => '500m',

                    expire_time => '30m',

                                   );

  $Cache­>set($key, $value);

  my $value = $Cache­>get($key);

Page 14: Building Scalable Websites with Perl

Memcached

our $Memd = Cache::Memcached­>new({

    'servers' => [

      "10.0.0.15:11211","10.0.0.15:11212",

      "10.0.0.17:11211",

       [ "10.0.0.17:11211", 3 ]

    ],

    'debug'   => 0,

    'compress_threshold' => 10_000,

                                 });

$Memd­>set($key, $value, 5*60 );

my $value = $Memd­>get($key);

Page 15: Building Scalable Websites with Perl

Job Queuing

Page 16: Building Scalable Websites with Perl

Get in Line

Page 17: Building Scalable Websites with Perl

“search in progress”

http://www.stonehenge.com/merlyn/WebTechniques/col20.html

clientweb

server workerredirect

fork

clientweb

server workerreload

result

doneyet?

Page 18: Building Scalable Websites with Perl

Spread::Queue client

use Spread::Queue::Sender;

my $sender = Spread::Queue::Sender­>new(

                                "myqueue"

                                       );

$sender­>submit(

    "myfunc", { name => "value" }

               );

my $response = $sender­>receive();

Page 19: Building Scalable Websites with Perl

Spread::Queue worker

use Spread::Queue::Worker;

my $worker = Spread::Queue::Worker­>new("myqueue");

$worker­>callbacks(

           myfunc => \&myfunc,

                  );

$SIG{INT} = \&signal_handler;

$worker­>run;

Page 20: Building Scalable Websites with Perl

Spread::Queue worker

sub myfunc {

    my ($worker, $originator, $input) = @_;

      

    my $result = {

        response => "I heard you!",

                 };

    $worker­>respond($originator, $result);

}

Page 21: Building Scalable Websites with Perl

Resources

• “Computer Science and Perl Programming”

• “Mastering Algorithms with Perl”

• “Patterns of Enterprise Application Architecture” by Martin Fowler

• http://oreillynet.com/

Page 22: Building Scalable Websites with Perl

Thanks!

• Craig McLane and Adam Sussman of Ticketmaster Online

• Zack Steinkamp of Yahoo