Perlbal Tutorial
Upcoming SlideShare
Loading in...5
×
 

Perlbal Tutorial

on

  • 8,651 views

 

Statistics

Views

Total Views
8,651
Views on SlideShare
8,534
Embed Views
117

Actions

Likes
3
Downloads
49
Comments
0

8 Embeds 117

http://lickck.blogspot.tw 48
http://blog.comewalk.com 21
http://www.slideshare.net 18
http://lickck.blogspot.com 16
http://comewalk.typepad.com 10
http://lickck.blogspot.hk 2
http://translate.googleusercontent.com 1
http://lickck.blogspot.no 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Perlbal Tutorial Perlbal Tutorial Presentation Transcript

  • Perlbal Tutorial Takatsugu Shigeta YAPC::Asia Tokyo 2009
  • 重田崇嗣 Takatsugu Shigeta
  • http://profile.typepad.com/comewalk TypePad Profiles View slide
  • Perlbal View slide
  • http://www.danga.com/perlbal/
  • "Perlbal is a Perl-based reverse proxy load balancer and web server." Perlbal From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Perlbal
  • "Perlbal is a single-threaded event-based server supporting HTTP load balancing, web serving, and a mix of the two (see below)." Perlbal http://www.danga.com/perlbal/
  • install
  • $ cpan Perlbal
  • WARNING: AIO mode disabled or not available.          Perlbal will run slowly under load if          you're doing any          disk operations. (e.g. web_server mode).          Install IO::AIO for better performance.
  • $ cpan IO::AIO
  • http://code.sixapart.com/trac/perlbal/browser/trunk/META.yml?rev=768 requires:      BSD::Resource:       0      Danga::Socket:       1.44      File::Find:          0      HTTP::Date:          0      HTTP::Response:      0      Sys::Syscall:        0      Test::More:          0      Time::HiRes:         0
  • http://code.sixapart.com/svn/perlbal/ Subversion Repository
    • $ svn co http://code.sixapart.com/svn/perlbal/
    • $ cd trunk
    • $ perl Makefile.PL
    • $ make
    • $ sudo make install
  • start Perlbal
  • # ./perlbal --help Usage: perlbal [OPTS]  --help          This usage info  --version       Print perlbal release version  --config=[file] Specify Perlbal config file           (default: /etc/perlbal/perlbal.conf )  --daemon        Daemonize
  • $ perlbal > --config=/path/to/foo.conf > --daemon
  • $ perlbal > -c /path/to/foo.conf > -d
  • roles
  • reverse_proxy web_server management selector upload_tracker
  • reverse proxy
    • CREATE POOL my_apaches   POOL my_apaches ADD 10.0.0.10:8080   POOL my_apaches ADD 10.0.0.11:8080   POOL my_apaches ADD 10.0.0.12   POOL my_apaches ADD 10.0.0.13:8081 CREATE SERVICE balancer   SET listen          = 0.0.0.0:80   SET role            = reverse_proxy   SET pool            = my_apaches   SET persist_client  = on   SET persist_backend = on   SET verify_backend  = on ENABLE balancer
    • CREATE POOL dynamic   SET nodefile = conf/nodelist.dat CREATE SERVICE balancer2   SET listen          = 0.0.0.0:81   SET role            = reverse_proxy   SET pool            = dynamic   SET persist_client  = on   SET persist_backend = on   SET verify_backend  = on
    • ENABLE balancer2
    • # whitespace and comments allowed 10.1.0.10    # test machine #10.1.0.10:8083    # test machine # can include port numbers, but defaults to 80 if not provided: # 10.1.0.4:80
    • In node file, you should list IP addresses.
    • It's a comment after "#".
  • web server
    • CREATE SERVICE docs   SET listen         = 0.0.0.0:80   SET role           = web_server   SET docroot        = /usr/share/doc/   SET dirindexing    = 1   SET persist_client = on ENABLE docs
  • management
    • CREATE SERVICE mgmt   SET role   = management   SET listen = 127.0.0.1:60000 ENABLE mgmt
  • seealso http://code.sixapart.com/trac/perlbal/browser/trunk/doc /config-guide.txt
  • selector
    • LOAD vhosts
    • CREATE SERVICE foo   SET listen      = 0.0.0.0:8081   SET role        = web_server   SET docroot     = /var/www/html/yapcasia2009/foo.com/   SET dirindexing = 1 ENABLE foo CREATE SERVICE bar   SET listen      = 0.0.0.0:8082   SET role        = web_server   SET docroot     = /var/www/html/yapcasia2009/bar.com/   SET dirindexing = 0 ENABLE bar
    • CREATE SERVICE vdemo   SET listen         = 0.0.0.0:8080   SET role           = selector   SET plugins        = vhosts   SET persist_client = on   VHOST *.foo.com = foo   VHOST *.bar.com = bar
    • #  VHOST * = foo ENABLE vdemo
  • upload_tracker
  • I'm sorry. I have never used it. I omitted upload_tracker. But...
  • http://code.sixapart.com/trac/perlbal/browser/trunk/lib/Perlbal/Service.pm?rev=806#L1431 # create UDP upload tracker listener if ($self->{role} eq "upload_tracker") {     $listener = Perlbal::UploadListener->new($self->{listen}, $self); }
  • parameters
    • CREATE POOL poolname
    •   POOL poolname ADD 0.0.0.0:8080
    • CREATE POOL poolname
    •   SET nodefile = /path/to/file
    •   SET balance_method = random
    • CREATE SERVICE foo
    •   SET role = reverse_proxy
    •   SET listen = 192 .168.0.1:81
    •   SET persist_client = false
    •   SET persist_client_timeout = 30
    •  
    •   SET enable_ssl = false
    •   SET ssl_cert_file = certs/server-cert.pem
    •   SET ssl_key_file  = certs/server-key.pem
    •   SET ssl_cipher_list = ALL:!LOW:!EXP
    •   SET always_trusted = false
    •   SET backend_persist_cache = 2
    •   SET buffer_backend_connect = 100k  
    •   SET buffer_size = 256k
    •   SET buffer_size_reproxy_url = 50k
    •   SET buffer_upload_threshold_rate = 0
    •   SET buffer_upload_threshold_size = 250k
    •   SET buffer_upload_threshold_time = 5
    •   SET buffer_uploads = false
    •   SET buffer_uploads_path = /path/to
    •   SET connect_ahead = 0
    •   SET enable_reproxy = false
    •   SET enable_error_retries = false
    •   SET error_retry_schedule = 0,.25,.50,1,1,1,1,1
    •   SET high_priority_cookie
    •   SET high_priority_cookie_contents
    •   SET max_backend_uses = 0
    •   SET persist_backend = false
    •   SET pool
    •   SET queue_relief_chance = 0
    •   SET queue_relief_size = 0
    •   SET trusted_upstream_proxies = 10.0.0.0/24
    •   SET upload_status_listeners = ""
    •   SET verify_backend = false
    •   SET verify_backend_path = *
    •   SET blind_proxy = 0
    •   SET reproxy_cache_maxsize = 0
    •   SET max_chunked_request_size = 209715200
    • CREATE SERVICE foo
    •   SET role = web_server
    •   SET listen = 192 .168.0.1:81
    •   SET persist_client = false
    •   SET persist_client_timeout = 30
    •  
    •   SET enable_ssl = false
    •   SET ssl_cert_file = certs/server-cert.pem
    •   SET ssl_key_file  = certs/server-key.pem
    •   SET ssl_cipher_list = ALL:!LOW:!EXP
    •   SET dirindexing = false
    •   SET docroot = /path/to
    •   SET index_files = index.html
    •   SET max_put_size = 0
    •   SET min_put_directory = 0
    •   SET client_sndbuf_size = 0
    •   SET always_trusted = false
    •   SET enable_concatenate_get = 0
    •   SET enable_delete = 0
    •   SET enable_put = 0
    •   SET max_chunked_request_size = 209715200
    • CREATE SERVICE foo
    •   SET role = selector
    •   SET listen = 192 .168.0.1:81
    •   SET persist_client = false
    •   SET persist_client_timeout = 30
    •  
    •   SET enable_ssl = false
    •   SET ssl_cert_file = certs/server-cert.pem
    •   SET ssl_key_file  = certs/server-key.pem
    •   SET ssl_cipher_list = ALL:!LOW:!EXP
    •   SET default_service
    •   SET latency = 0
    •   SET always_trusted = false
    •   SET max_chunked_request_size = 209715200
    • CREATE SERVICE mgmt   SET role   = management   SET listen = 127.0.0.1:60000
    •  
    •   SET persist_client = false
    •   SET persist_client_timeout = 30
    •  
    •   SET enable_ssl = false
    •   SET ssl_cert_file = certs/server-cert.pem
    •   SET ssl_key_file  = certs/server-key.pem
    •   SET ssl_cipher_list = ALL:!LOW:!EXP
    •   SET always_trusted = false
    •   SET max_chunked_request_size = 209715200
  • architecture
  • Perlbal Classes
    • Perlbal Perlbal::AIO Perlbal::BackendHTTP Perlbal::Cache Perlbal::ChunkedUploadState Perlbal::ClientHTTP Perlbal::ClientHTTPBase Perlbal::ClientManage Perlbal::ClientProxy Perlbal::CommandContext
    • Perlbal::HTTPHeaders Perlbal::ManageCommand Perlbal::Pool Perlbal::ReproxyManager Perlbal::Service Perlbal::Socket Perlbal::SocketSSL Perlbal::TCPListener Perlbal::Test Perlbal::Test::WebClient Perlbal::Test::WebServer Perlbal::UploadListener Perlbal::Util
  • class diagram
  • Created by GraphViz
  • how to work
    • call ENABLE servicename, start to listen on Perlbal::TCPListener
    •                {{ INTERNET }}                       |                       v   [Service]<===>[TCPListener]               ___/    |    __              v        v        v   [ClientManage]  [ClientHTTP] [ClientProxy]                                      ^                                      |                                      v                                [BackendHTTP]
    http://code.sixapart.com/trac/perlbal/browser/trunk/doc/hacking/classes.txt
  • plugins
  • Perlbal::Plugin
    • AccessControl AtomInject AtomStream AutoRemoveLeadingDir Cgilike Cgilike::Request EchoService EchoService::Client
    • Highpri Include LazyCDN
    • MaxContentLength NotModified Palimg Queues Redirect Stats Stats::Storage Vhosts Vpaths
    http://code.sixapart.com/trac/perlbal/browser/trunk/lib/Perlbal/Plugin
  • hooks
  • seealso http://code.sixapart.com/trac/perlbal/browser/trunk/doc/hacking/hooks.txt
  • writing plugins
    • package Perlbal::Plugin ::MyPlugin;
    • use strict;
    • use warnings;
    • # when &quot;LOAD&quot; directive loads us up
    • sub load {
    •      return 1;
    • }
    • # unload our global commands, clear our service object
    • sub unload {
    •      return 1;
    • }
    • # called when we're being added to a service
    • sub register {
    •      return 1;
    • }
    • # called when we're no longer active on a service
    • sub unregister {
    •      return 1;
    • }
    • 1;
    • __END__
    • LOAD MyPlugin
    • LOAD OtherPlugin
    • CREATE SERVICE hogehoge
    •     plugins = OtherPlugin, MyPlugin
    • ENABLE hogehoge
    • $ telnet localhost 60000
    • plugins
    • hogehoge OtherPlugin MyPlugin
  • This slide introduced Perlbal to you. If you are interested in Perlbal, please try again later!
  • BTW, JFYI ,  
  • AnyEvent  
  • Danga::Socket::AnyEvent
    • From: Martin Atkins
    • Date: Mon, 17 Aug 2009 16:26:09 -0700
    • Subject: AnyEvent implementation of Danga::Socket
    •  
    • &quot;This allows Perlbal to, in theory, run in any event loop supported by AnyEvent, and more interestingly allows Perlbal plugins to make use of AnyEvent protocol implementations.&quot;
    •  
    • http://groups.google.com/group/perlbal/browse_thread/thread/3a275de028d1a04b
  • Try Danga::Socket::AnyEvent, if you are interested in AnyEvent! http://search.cpan.org/dist/Danga-Socket-AnyEvent/
  • Resources
    • Perlbal
    • http://www.danga.com/perlbal/
    •  
    • Six Apart Code
    • http://code.sixapart.com/svn/perlbal/
    •  
    • Google Code
    • http://code.google.com/p/perlbal/
    •  
    • Google Groups
    • http://groups.google.com/group/perlbal
    • Thank you!