Perlbal Tutorial Takatsugu Shigeta YAPC::Asia Tokyo 2009
重田崇嗣 Takatsugu Shigeta
http://profile.typepad.com/comewalk TypePad Profiles
Perlbal
http://www.danga.com/perlbal/
"Perlbal is a Perl-based reverse proxy load balancer and web server." Perlbal From Wikipedia, the free encyclope...
"Perlbal is a single-threaded event-based server supporting HTTP load balancing, web serving, and a mix of the two (s...
install
$ cpan Perlbal
WARNING: AIO mode disabled or not available.          Perlbal will run slowly under load if          you're doing any     ...
$ cpan IO::AIO
http://code.sixapart.com/trac/perlbal/browser/trunk/META.yml?rev=768 requires:      BSD::Resource:       0      Danga::Soc...
http://code.sixapart.com/svn/perlbal/ Subversion Repository
<ul><li>$ svn co http://code.sixapart.com/svn/perlbal/ </li></ul><ul><li>$ cd trunk </li></ul><ul><li>$ perl Makefile.PL <...
start Perlbal
# ./perlbal --help Usage: perlbal [OPTS]  --help          This usage info  --version       Print perlbal release version  ...
$ 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
<ul><li>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...
<ul><li>CREATE POOL dynamic   SET nodefile = conf/nodelist.dat CREATE SERVICE balancer2   SET listen          = 0.0.0.0:81...
<ul><li># whitespace and comments allowed 10.1.0.10     # test machine #10.1.0.10:8083    # test machine # can include por...
web server
<ul><li>CREATE SERVICE docs   SET listen         = 0.0.0.0:80   SET role           =  web_server   SET docroot        = /u...
management
<ul><li>CREATE SERVICE mgmt   SET role   =  management   SET listen = 127.0.0.1:60000 ENABLE mgmt </li></ul>
seealso http://code.sixapart.com/trac/perlbal/browser/trunk/doc /config-guide.txt
selector
<ul><li>LOAD vhosts </li></ul><ul><li>CREATE SERVICE foo   SET listen      = 0.0.0.0:8081   SET role        = web_server  ...
<ul><li>CREATE SERVICE vdemo   SET listen         = 0.0.0.0:8080   SET role           =  selector   SET plugins        = v...
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 liste...
parameters
<ul><li>CREATE POOL  poolname </li></ul><ul><li>   POOL  poolname  ADD  0.0.0.0:8080 </li></ul><ul><li>CREATE POOL  poolna...
<ul><li>CREATE SERVICE  foo </li></ul><ul><li>   SET role =  reverse_proxy </li></ul><ul><li>   SET listen = 192 .168.0.1:...
<ul><li>   SET buffer_upload_threshold_rate =  0   </li></ul><ul><li>   SET buffer_upload_threshold_size =  250k </li></ul...
<ul><li>   SET pool </li></ul><ul><li>   SET queue_relief_chance =  0 </li></ul><ul><li>   SET queue_relief_size =  0 </li...
<ul><li>CREATE SERVICE  foo </li></ul><ul><li>   SET role =  web_server </li></ul><ul><li>   SET listen = 192 .168.0.1:81 ...
<ul><li>   SET max_put_size =  0 </li></ul><ul><li>   SET min_put_directory =  0 </li></ul><ul><li>   SET client_sndbuf_si...
<ul><li>CREATE SERVICE  foo </li></ul><ul><li>   SET role =  selector </li></ul><ul><li>   SET listen = 192 .168.0.1:81 </...
<ul><li>CREATE SERVICE  mgmt   SET role   =  management   SET listen =  127.0.0.1:60000 </li></ul><ul><li>  </li></ul><ul>...
architecture
Perlbal Classes <ul><li>Perlbal Perlbal::AIO Perlbal::BackendHTTP Perlbal::Cache Perlbal::ChunkedUploadState Perlbal::Clie...
class diagram
Created by GraphViz
how to work
<ul><li>call ENABLE  servicename,  start to listen on Perlbal::TCPListener </li></ul><ul><li>                {{ INTERNET }...
plugins
Perlbal::Plugin <ul><li>AccessControl AtomInject AtomStream AutoRemoveLeadingDir Cgilike Cgilike::Request EchoService Echo...
hooks
seealso http://code.sixapart.com/trac/perlbal/browser/trunk/doc/hacking/hooks.txt
writing plugins
<ul><li>package  Perlbal::Plugin ::MyPlugin; </li></ul><ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><...
<ul><li>LOAD MyPlugin </li></ul><ul><li>LOAD OtherPlugin </li></ul><ul><li>CREATE SERVICE hogehoge </li></ul><ul><li>     ...
<ul><li>$ telnet localhost 60000 </li></ul><ul><li>plugins </li></ul><ul><li>hogehoge OtherPlugin  MyPlugin </li></ul>
This slide introduced Perlbal to you. If you are interested in Perlbal, please try again later!
BTW, JFYI ,  
AnyEvent  
Danga::Socket::AnyEvent <ul><li>From: Martin Atkins </li></ul><ul><li>Date: Mon, 17 Aug 2009 16:26:09 -0700 </li></ul><ul>...
Try Danga::Socket::AnyEvent, if you are interested in AnyEvent! http://search.cpan.org/dist/Danga-Socket-AnyEvent/
Resources <ul><li>Perlbal </li></ul><ul><li>http://www.danga.com/perlbal/ </li></ul><ul><li>  </li></ul><ul><li>Six Apart ...
<ul><li>Thank you! </li></ul>
Upcoming SlideShare
Loading in...5
×

Perlbal Tutorial

6,328

Published on

Published in: Technology, Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,328
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
52
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Perlbal Tutorial

  1. 1. Perlbal Tutorial Takatsugu Shigeta YAPC::Asia Tokyo 2009
  2. 2. 重田崇嗣 Takatsugu Shigeta
  3. 3. http://profile.typepad.com/comewalk TypePad Profiles
  4. 4. Perlbal
  5. 5. http://www.danga.com/perlbal/
  6. 6. &quot;Perlbal is a Perl-based reverse proxy load balancer and web server.&quot; Perlbal From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Perlbal
  7. 7. &quot;Perlbal is a single-threaded event-based server supporting HTTP load balancing, web serving, and a mix of the two (see below).&quot; Perlbal http://www.danga.com/perlbal/
  8. 8. install
  9. 9. $ cpan Perlbal
  10. 10. 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.
  11. 11. $ cpan IO::AIO
  12. 12. 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
  13. 13. http://code.sixapart.com/svn/perlbal/ Subversion Repository
  14. 14. <ul><li>$ svn co http://code.sixapart.com/svn/perlbal/ </li></ul><ul><li>$ cd trunk </li></ul><ul><li>$ perl Makefile.PL </li></ul><ul><li>$ make </li></ul><ul><li>$ sudo make install </li></ul>
  15. 15. start Perlbal
  16. 16. # ./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
  17. 17. $ perlbal > --config=/path/to/foo.conf > --daemon
  18. 18. $ perlbal > -c /path/to/foo.conf > -d
  19. 19. roles
  20. 20. reverse_proxy web_server management selector upload_tracker
  21. 21. reverse proxy
  22. 22. <ul><li>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 </li></ul>
  23. 23. <ul><li>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 </li></ul><ul><li>ENABLE balancer2 </li></ul>
  24. 24. <ul><li># 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 </li></ul><ul><li>In node file, you should list IP addresses. </li></ul><ul><li>It's a comment after &quot;#&quot;. </li></ul>
  25. 25. web server
  26. 26. <ul><li>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 </li></ul>
  27. 27. management
  28. 28. <ul><li>CREATE SERVICE mgmt   SET role   = management   SET listen = 127.0.0.1:60000 ENABLE mgmt </li></ul>
  29. 29. seealso http://code.sixapart.com/trac/perlbal/browser/trunk/doc /config-guide.txt
  30. 30. selector
  31. 31. <ul><li>LOAD vhosts </li></ul><ul><li>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 </li></ul>
  32. 32. <ul><li>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 </li></ul><ul><li>#  VHOST * = foo ENABLE vdemo </li></ul>
  33. 33. upload_tracker
  34. 34. I'm sorry. I have never used it. I omitted upload_tracker. But...
  35. 35. http://code.sixapart.com/trac/perlbal/browser/trunk/lib/Perlbal/Service.pm?rev=806#L1431 # create UDP upload tracker listener if ($self->{role} eq &quot;upload_tracker&quot;) {     $listener = Perlbal::UploadListener->new($self->{listen}, $self); }
  36. 36. parameters
  37. 37. <ul><li>CREATE POOL poolname </li></ul><ul><li>  POOL poolname ADD 0.0.0.0:8080 </li></ul><ul><li>CREATE POOL poolname </li></ul><ul><li>  SET nodefile = /path/to/file </li></ul><ul><li>  SET balance_method = random </li></ul>
  38. 38. <ul><li>CREATE SERVICE foo </li></ul><ul><li>  SET role = reverse_proxy </li></ul><ul><li>  SET listen = 192 .168.0.1:81 </li></ul><ul><li>  SET persist_client = false </li></ul><ul><li>  SET persist_client_timeout = 30 </li></ul><ul><li>  </li></ul><ul><li>  SET enable_ssl = false </li></ul><ul><li>  SET ssl_cert_file = certs/server-cert.pem </li></ul><ul><li>  SET ssl_key_file  = certs/server-key.pem </li></ul><ul><li>  SET ssl_cipher_list = ALL:!LOW:!EXP </li></ul><ul><li>  SET always_trusted = false </li></ul><ul><li>  SET backend_persist_cache = 2 </li></ul><ul><li>  SET buffer_backend_connect = 100k   </li></ul><ul><li>  SET buffer_size = 256k </li></ul><ul><li>  SET buffer_size_reproxy_url = 50k </li></ul>
  39. 39. <ul><li>  SET buffer_upload_threshold_rate = 0 </li></ul><ul><li>  SET buffer_upload_threshold_size = 250k </li></ul><ul><li>  SET buffer_upload_threshold_time = 5 </li></ul><ul><li>  SET buffer_uploads = false </li></ul><ul><li>  SET buffer_uploads_path = /path/to </li></ul><ul><li>  SET connect_ahead = 0 </li></ul><ul><li>  SET enable_reproxy = false </li></ul><ul><li>  SET enable_error_retries = false </li></ul><ul><li>  SET error_retry_schedule = 0,.25,.50,1,1,1,1,1 </li></ul><ul><li>  SET high_priority_cookie </li></ul><ul><li>  SET high_priority_cookie_contents </li></ul><ul><li>  SET max_backend_uses = 0 </li></ul><ul><li>  SET persist_backend = false </li></ul>
  40. 40. <ul><li>  SET pool </li></ul><ul><li>  SET queue_relief_chance = 0 </li></ul><ul><li>  SET queue_relief_size = 0 </li></ul><ul><li>  SET trusted_upstream_proxies = 10.0.0.0/24 </li></ul><ul><li>  SET upload_status_listeners = &quot;&quot; </li></ul><ul><li>  SET verify_backend = false </li></ul><ul><li>  SET verify_backend_path = * </li></ul><ul><li>  SET blind_proxy = 0 </li></ul><ul><li>  SET reproxy_cache_maxsize = 0 </li></ul><ul><li>  SET max_chunked_request_size = 209715200 </li></ul>
  41. 41. <ul><li>CREATE SERVICE foo </li></ul><ul><li>  SET role = web_server </li></ul><ul><li>  SET listen = 192 .168.0.1:81 </li></ul><ul><li>  SET persist_client = false </li></ul><ul><li>  SET persist_client_timeout = 30 </li></ul><ul><li>  </li></ul><ul><li>  SET enable_ssl = false </li></ul><ul><li>  SET ssl_cert_file = certs/server-cert.pem </li></ul><ul><li>  SET ssl_key_file  = certs/server-key.pem </li></ul><ul><li>  SET ssl_cipher_list = ALL:!LOW:!EXP </li></ul><ul><li>  SET dirindexing = false </li></ul><ul><li>  SET docroot = /path/to </li></ul><ul><li>  SET index_files = index.html </li></ul>
  42. 42. <ul><li>  SET max_put_size = 0 </li></ul><ul><li>  SET min_put_directory = 0 </li></ul><ul><li>  SET client_sndbuf_size = 0 </li></ul><ul><li>  SET always_trusted = false </li></ul><ul><li>  SET enable_concatenate_get = 0 </li></ul><ul><li>  SET enable_delete = 0 </li></ul><ul><li>  SET enable_put = 0 </li></ul><ul><li>  SET max_chunked_request_size = 209715200 </li></ul>
  43. 43. <ul><li>CREATE SERVICE foo </li></ul><ul><li>  SET role = selector </li></ul><ul><li>  SET listen = 192 .168.0.1:81 </li></ul><ul><li>  SET persist_client = false </li></ul><ul><li>  SET persist_client_timeout = 30 </li></ul><ul><li>  </li></ul><ul><li>  SET enable_ssl = false </li></ul><ul><li>  SET ssl_cert_file = certs/server-cert.pem </li></ul><ul><li>  SET ssl_key_file  = certs/server-key.pem </li></ul><ul><li>  SET ssl_cipher_list = ALL:!LOW:!EXP </li></ul><ul><li>  SET default_service </li></ul><ul><li>  SET latency = 0 </li></ul><ul><li>  SET always_trusted = false </li></ul><ul><li>  SET max_chunked_request_size = 209715200 </li></ul>
  44. 44. <ul><li>CREATE SERVICE mgmt   SET role   = management   SET listen = 127.0.0.1:60000 </li></ul><ul><li>  </li></ul><ul><li>  SET persist_client = false </li></ul><ul><li>  SET persist_client_timeout = 30 </li></ul><ul><li>  </li></ul><ul><li>  SET enable_ssl = false </li></ul><ul><li>  SET ssl_cert_file = certs/server-cert.pem </li></ul><ul><li>  SET ssl_key_file  = certs/server-key.pem </li></ul><ul><li>  SET ssl_cipher_list = ALL:!LOW:!EXP </li></ul><ul><li>  SET always_trusted = false </li></ul><ul><li>  SET max_chunked_request_size = 209715200 </li></ul>
  45. 45. architecture
  46. 46. Perlbal Classes <ul><li>Perlbal Perlbal::AIO Perlbal::BackendHTTP Perlbal::Cache Perlbal::ChunkedUploadState Perlbal::ClientHTTP Perlbal::ClientHTTPBase Perlbal::ClientManage Perlbal::ClientProxy Perlbal::CommandContext </li></ul><ul><li>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 </li></ul>
  47. 47. class diagram
  48. 48. Created by GraphViz
  49. 49. how to work
  50. 50. <ul><li>call ENABLE servicename, start to listen on Perlbal::TCPListener </li></ul><ul><li>               {{ INTERNET }}                       |                       v   [Service]<===>[TCPListener]               ___/    |    __              v        v        v   [ClientManage]  [ClientHTTP] [ClientProxy]                                      ^                                      |                                      v                                [BackendHTTP] </li></ul>http://code.sixapart.com/trac/perlbal/browser/trunk/doc/hacking/classes.txt
  51. 51. plugins
  52. 52. Perlbal::Plugin <ul><li>AccessControl AtomInject AtomStream AutoRemoveLeadingDir Cgilike Cgilike::Request EchoService EchoService::Client </li></ul><ul><li>Highpri Include LazyCDN </li></ul><ul><li>MaxContentLength NotModified Palimg Queues Redirect Stats Stats::Storage Vhosts Vpaths </li></ul>http://code.sixapart.com/trac/perlbal/browser/trunk/lib/Perlbal/Plugin
  53. 53. hooks
  54. 54. seealso http://code.sixapart.com/trac/perlbal/browser/trunk/doc/hacking/hooks.txt
  55. 55. writing plugins
  56. 56. <ul><li>package Perlbal::Plugin ::MyPlugin; </li></ul><ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li># when &quot;LOAD&quot; directive loads us up </li></ul><ul><li>sub load { </li></ul><ul><li>     return 1; </li></ul><ul><li>} </li></ul><ul><li># unload our global commands, clear our service object </li></ul><ul><li>sub unload { </li></ul><ul><li>     return 1; </li></ul><ul><li>} </li></ul><ul><li># called when we're being added to a service </li></ul><ul><li>sub register { </li></ul><ul><li>     return 1; </li></ul><ul><li>} </li></ul><ul><li># called when we're no longer active on a service </li></ul><ul><li>sub unregister { </li></ul><ul><li>     return 1; </li></ul><ul><li>} </li></ul><ul><li>1; </li></ul><ul><li>__END__ </li></ul>
  57. 57. <ul><li>LOAD MyPlugin </li></ul><ul><li>LOAD OtherPlugin </li></ul><ul><li>CREATE SERVICE hogehoge </li></ul><ul><li>    plugins = OtherPlugin, MyPlugin </li></ul><ul><li>ENABLE hogehoge </li></ul>
  58. 58. <ul><li>$ telnet localhost 60000 </li></ul><ul><li>plugins </li></ul><ul><li>hogehoge OtherPlugin MyPlugin </li></ul>
  59. 59. This slide introduced Perlbal to you. If you are interested in Perlbal, please try again later!
  60. 60. BTW, JFYI ,  
  61. 61. AnyEvent  
  62. 62. Danga::Socket::AnyEvent <ul><li>From: Martin Atkins </li></ul><ul><li>Date: Mon, 17 Aug 2009 16:26:09 -0700 </li></ul><ul><li>Subject: AnyEvent implementation of Danga::Socket </li></ul><ul><li>  </li></ul><ul><li>&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; </li></ul><ul><li>  </li></ul><ul><li>http://groups.google.com/group/perlbal/browse_thread/thread/3a275de028d1a04b </li></ul>
  63. 63. Try Danga::Socket::AnyEvent, if you are interested in AnyEvent! http://search.cpan.org/dist/Danga-Socket-AnyEvent/
  64. 64. Resources <ul><li>Perlbal </li></ul><ul><li>http://www.danga.com/perlbal/ </li></ul><ul><li>  </li></ul><ul><li>Six Apart Code </li></ul><ul><li>http://code.sixapart.com/svn/perlbal/ </li></ul><ul><li>  </li></ul><ul><li>Google Code </li></ul><ul><li>http://code.google.com/p/perlbal/ </li></ul><ul><li>  </li></ul><ul><li>Google Groups </li></ul><ul><li>http://groups.google.com/group/perlbal </li></ul>
  65. 65. <ul><li>Thank you! </li></ul>
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×