POE
Phil
Whelan
POE
Perl
   OBJECT
       Environment
POE
Perl
   OBJECT
       Environment
     “POE is a framework for creating
         event-driven cooperative
       multi...
POE
Perl
   OBJECT
       Environment
     “POE is a framework for creating
         event-driven cooperative
       multi...
Why POE ?
Why POE ?

Perl does this...

       A            B   C
Why POE ?

          o two things
Ho w to d
      at  once??
Why POE ?
Mulitple processes do this...

        A        B        C
        A        B        C
Why POE ?
POE does this...

        A          B   C
        A          B   C
Why POE ?
POE does this like this...

        A        B           C
        A        B           C
Why POE ?
POE makes it easy to do this...

       HTTP      A   B   C
      Server     A   B   C

      SMTP       A   B  ...
Why POE ?
                               one
                             proc
                                  ess
POE m...
POE Hates
POE Hates

    Blocking
A      B       C
POE Hates

    Blocking
A      B       C
                      $%!@
                   blocking!!!!
POE Hates

Blocking
POE Hates

Blocking causes
    queuing
POE Hates

 Nobody likes
   queuing
POE Hates
Blocking
One event stops, everything stops

      HTTP      A   B   C
     Server     A   B   C

     SMTP       A   B   C...
Non-Blocking

Everything in a POE application
should be non-blocking
Non-Blocking
Non-Blocking
Reading from a socket?
Non-Blocking
Reading from a socket?
   - get POE to notify you when it’s ready
Non-Blocking
Reading from a socket?
   - get POE to notify you when it’s ready
Non-Blocking
Reading from a socket?
   - get POE to notify you when it’s ready
Waiting for more data?
Non-Blocking
Reading from a socket?
   - get POE to notify you when it’s ready
Waiting for more data?
   - get POE to noti...
Non-Blocking
Reading from a socket?
   - get POE to notify you when it’s ready
Waiting for more data?
   - get POE to noti...
Non-Blocking
Reading from a socket?
   - get POE to notify you when it’s ready
Waiting for more data?
   - get POE to noti...
Non-Blocking
Reading from a socket?
   - get POE to notify you when it’s ready
Waiting for more data?
   - get POE to noti...
Non-Blocking
Reading from a socket?
   - get POE to notify you when it’s ready
Waiting for more data?
   - get POE to noti...
Non-Blocking
Non-Blocking
Every system call should be
broken into...
Non-Blocking
Every system call should be
broken into...
     - Request
Non-Blocking
Every system call should be
broken into...
     - Request
         &
     - Callback
The POE Queue
Your
Code
         e nt     nt
       ev     eve
                  event
                 event    POE
     ...
The POE Queue
Your        Non-blocking
Code
         e nt     nt
       ev     eve
                  event
               ...
The POE Queue
Your
Code
         e nt     nt
       ev     eve
                  event
                 event    POE
     ...
The POE Queue
                system calls             POE’s
Your
                            Blocking    System
Code     ...
The POE Queue
                   system calls                   POE’s
Your     event                     event

          ...
POE Components
POE Components
It’s like CPAN for POE!
POE Components
It’s like CPAN for POE!
 Example...
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS


   What’s
 wrong with
 Net::DNS ??
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS


   What’s
 wrong with
 Net::DNS ??
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS
               Net::DNS request & respo...
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS
               Net::DNS request & respo...
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS
               Net::DNS request & respo...
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS
               Net::DNS request & respo...
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS
POE Components
It’s like CPAN for POE!
 Example...
    POE::Component::Client::DNS

       Allows multiple DNS requests
  ...
Show us
the code!!
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
                        tick...
use POE;

POE::Session->create(
    inline_states => {
       _start => sub {...
POE Sessions
                        tick...
use POE;

POE::Session->create(
    inline_states => {
       _start => sub {...
POE Sessions
                        tick...
                        tick...
use POE;

POE::Session->create(
    inline_st...
POE Sessions
                        tick...
                        tick...
use POE;

POE::Session->create(
    inline_st...
POE Sessions
                        tick...
                        tick...
use POE;                tick...

POE::Session...
POE Sessions
                        tick...
                        tick...
use POE;                tick...

POE::Session...
POE Sessions
                        tick...
                        tick...
use POE;                tick...
             ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Sessions
use POE;

POE::Session->create(
    inline_states => {
       _start => sub { $_[KERNEL]->yield("next") },
  ...
POE Scope
POE Scope
POE handles
 - Event context
POE Scope
POE handles
 - Event context
 - Event scope
POE Scope
POE handles
 - Event context
 - Event scope
 - Signal scope
POE Scope



Kernel (Root Session)
POE Scope
   Kernel (Root Session)
Session
POE Scope
    Kernel (Root Session)
Session 1      Session 2
POE Scope
    Kernel (Root Session)
Session 1      Session 2
Session 3
POE Scope
    Kernel (Root Session)
Session 1      Session 2
Session 3
POE Scope
    Kernel (Root Session)
Session 1      Session 2
Session 3



Component
POE Scope
    Kernel (Root Session)
Session 1      Session 2
Session 3       HTTP Server
                 Component


Comp...
POE Scope
    Kernel (Root Session)
                                   “e
                                     ve
Session ...
POE Scope
          CALLING
     Kernel (Root Session)
Session 1         Session 2

 ( 2 , “event”)
POE Scope
             CALLING
       Kernel (Root Session)
 Session 1              Session 2

($session2 , “event”)
POE Scope
            CALLING
      Kernel (Root Session)
Session 1             Session 2

( “Bond” , “event”)

          ...
POE Scope
POE Scope

POE Kernel
Session
POE Scope
Perl process
 POE Kernel
 Session
POE Scope
Perl process
 POE Kernel
 Session
   POE::Wheel::Run
POE Scope
Perl process
                            Perl process
 POE Kernel
                             POE Kernel
 Sessi...
POE Scope
Perl process
                           Perl process
 POE Kernel
                            POE Kernel
 Session...
POE Scope
Perl process
                Logging
 POE Kernel
 Session
                 DBI


                 DBI


        ...
POE Scope
12.40.45.26

 POE::Component::IKC::Server


              “event”

22.1.122.6

 POE::Component::IKC::Client
Conclusion
Conclusion
- Great for doing many things concurrently,
even if they are unrelated
Conclusion
- Great for doing many things concurrently,
even if they are unrelated

- Good management of scope
Conclusion
- Great for doing many things concurrently,
even if they are unrelated

- Good management of scope

- Non-block...
Conclusion
- Great for doing many things concurrently,
even if they are unrelated

- Good management of scope

- Non-block...
POE - Perl Object Environment
POE - Perl Object Environment
POE - Perl Object Environment
POE - Perl Object Environment
POE - Perl Object Environment
POE - Perl Object Environment
POE - Perl Object Environment
POE - Perl Object Environment
Upcoming SlideShare
Loading in …5
×

POE - Perl Object Environment

906 views

Published on

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

No Downloads
Views
Total views
906
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
13
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

POE - Perl Object Environment

  1. 1. POE Phil Whelan
  2. 2. POE Perl OBJECT Environment
  3. 3. POE Perl OBJECT Environment “POE is a framework for creating event-driven cooperative multitasking programs in Perl” --- Poe.Perl.Org
  4. 4. POE Perl OBJECT Environment “POE is a framework for creating event-driven cooperative multitasking programs in Perl” --- Poe.Perl.Org
  5. 5. Why POE ?
  6. 6. Why POE ? Perl does this... A B C
  7. 7. Why POE ? o two things Ho w to d at once??
  8. 8. Why POE ? Mulitple processes do this... A B C A B C
  9. 9. Why POE ? POE does this... A B C A B C
  10. 10. Why POE ? POE does this like this... A B C A B C
  11. 11. Why POE ? POE makes it easy to do this... HTTP A B C Server A B C SMTP A B C Server A B C
  12. 12. Why POE ? one proc ess POE makes it easy to do this... only !! HTTP A B C Server A B C SMTP A B C Server A B C
  13. 13. POE Hates
  14. 14. POE Hates Blocking A B C
  15. 15. POE Hates Blocking A B C $%!@ blocking!!!!
  16. 16. POE Hates Blocking
  17. 17. POE Hates Blocking causes queuing
  18. 18. POE Hates Nobody likes queuing
  19. 19. POE Hates
  20. 20. Blocking One event stops, everything stops HTTP A B C Server A B C SMTP A B C Server A B C
  21. 21. Non-Blocking Everything in a POE application should be non-blocking
  22. 22. Non-Blocking
  23. 23. Non-Blocking Reading from a socket?
  24. 24. Non-Blocking Reading from a socket? - get POE to notify you when it’s ready
  25. 25. Non-Blocking Reading from a socket? - get POE to notify you when it’s ready
  26. 26. Non-Blocking Reading from a socket? - get POE to notify you when it’s ready Waiting for more data?
  27. 27. Non-Blocking Reading from a socket? - get POE to notify you when it’s ready Waiting for more data? - get POE to notify you when more data is available to read
  28. 28. Non-Blocking Reading from a socket? - get POE to notify you when it’s ready Waiting for more data? - get POE to notify you when more data is available to read
  29. 29. Non-Blocking Reading from a socket? - get POE to notify you when it’s ready Waiting for more data? - get POE to notify you when more data is available to read SQL Request?
  30. 30. Non-Blocking Reading from a socket? - get POE to notify you when it’s ready Waiting for more data? - get POE to notify you when more data is available to read SQL Request? - get POE to notify you when the response comes back
  31. 31. Non-Blocking Reading from a socket? - get POE to notify you when it’s ready Waiting for more data? - get POE to notify you when more data is available to read SQL Request? - get POE to notify you when the response comes back
  32. 32. Non-Blocking
  33. 33. Non-Blocking Every system call should be broken into...
  34. 34. Non-Blocking Every system call should be broken into... - Request
  35. 35. Non-Blocking Every system call should be broken into... - Request & - Callback
  36. 36. The POE Queue Your Code e nt nt ev eve event event POE Queue event event event event event
  37. 37. The POE Queue Your Non-blocking Code e nt nt ev eve event event POE Queue event event event event event
  38. 38. The POE Queue Your Code e nt nt ev eve event event POE Queue event event event event event
  39. 39. The POE Queue system calls POE’s Your Blocking System Code Resources e nt nt ev eve event event POE Queue event event event event event
  40. 40. The POE Queue system calls POE’s Your event event System Code ev ev nt en Resources nt ev en ve en t e ve t e t event event POE Queue event event event event event
  41. 41. POE Components
  42. 42. POE Components It’s like CPAN for POE!
  43. 43. POE Components It’s like CPAN for POE! Example...
  44. 44. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS
  45. 45. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS What’s wrong with Net::DNS ??
  46. 46. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS What’s wrong with Net::DNS ??
  47. 47. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS Net::DNS request & response What’s happen inline. wrong with Net::DNS ??
  48. 48. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS Net::DNS request & response What’s happen inline. wrong with So it blocks. Net::DNS ??
  49. 49. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS Net::DNS request & response What’s happen inline. wrong with So it blocks. Net::DNS ??
  50. 50. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS Net::DNS request & response What’s happen inline. wrong with So it blocks. Net::DNS ?? Only one DNS request can occur at a time
  51. 51. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS
  52. 52. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS
  53. 53. POE Components It’s like CPAN for POE! Example... POE::Component::Client::DNS Allows multiple DNS requests to occur simultaneously.
  54. 54. Show us the code!!
  55. 55. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  56. 56. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  57. 57. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  58. 58. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  59. 59. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  60. 60. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; “ next” event POE $_[KERNEL]->delay(next => 1); }, Queue }, event ); event POE::Kernel->run(); event exit;
  61. 61. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; “ next” event POE $_[KERNEL]->delay(next => 1); }, Queue }, event ); event POE::Kernel->run(); event exit;
  62. 62. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; “ next” event POE $_[KERNEL]->delay(next => 1); }, Queue }, event ); event POE::Kernel->run(); “next” exit;
  63. 63. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; “ next” event POE $_[KERNEL]->delay(next => 1); }, Queue }, event ); event POE::Kernel->run(); “next” exit;
  64. 64. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; “ next” event POE $_[KERNEL]->delay(next => 1); }, Queue }, event ); event POE::Kernel->run(); “next” exit;
  65. 65. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; “ next” event POE $_[KERNEL]->delay(next => 1); }, Queue }, event ); event POE::Kernel->run(); “ne exit; xt”
  66. 66. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  67. 67. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  68. 68. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  69. 69. POE Sessions tick... use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  70. 70. POE Sessions tick... use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, “next” ); POE::Kernel->run(); exit;
  71. 71. POE Sessions tick... tick... use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  72. 72. POE Sessions tick... tick... use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  73. 73. POE Sessions tick... tick... use POE; tick... POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  74. 74. POE Sessions tick... tick... use POE; tick... POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  75. 75. POE Sessions tick... tick... use POE; tick... tick... tick... POE::Session->create( inline_states => { tick... tick... _start => sub { $_[KERNEL]->yield("next") }, next => sub { tick... print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, tick... ); POE::Kernel->run(); exit; tick.
  76. 76. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  77. 77. POE Sessions use POE; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...n"; $_[KERNEL]->delay(next => 1); }, }, ); POE::Kernel->run(); exit;
  78. 78. POE Scope
  79. 79. POE Scope POE handles - Event context
  80. 80. POE Scope POE handles - Event context - Event scope
  81. 81. POE Scope POE handles - Event context - Event scope - Signal scope
  82. 82. POE Scope Kernel (Root Session)
  83. 83. POE Scope Kernel (Root Session) Session
  84. 84. POE Scope Kernel (Root Session) Session 1 Session 2
  85. 85. POE Scope Kernel (Root Session) Session 1 Session 2 Session 3
  86. 86. POE Scope Kernel (Root Session) Session 1 Session 2 Session 3
  87. 87. POE Scope Kernel (Root Session) Session 1 Session 2 Session 3 Component
  88. 88. POE Scope Kernel (Root Session) Session 1 Session 2 Session 3 HTTP Server Component Component DBI Component
  89. 89. POE Scope Kernel (Root Session) “e ve Session 1 nt”Session 2 nt “eve ” Session 3 HTTP Server Component Component DBI Component “event”
  90. 90. POE Scope CALLING Kernel (Root Session) Session 1 Session 2 ( 2 , “event”)
  91. 91. POE Scope CALLING Kernel (Root Session) Session 1 Session 2 ($session2 , “event”)
  92. 92. POE Scope CALLING Kernel (Root Session) Session 1 Session 2 ( “Bond” , “event”) The name’s “Bond”
  93. 93. POE Scope
  94. 94. POE Scope POE Kernel Session
  95. 95. POE Scope Perl process POE Kernel Session
  96. 96. POE Scope Perl process POE Kernel Session POE::Wheel::Run
  97. 97. POE Scope Perl process Perl process POE Kernel POE Kernel Session Session POE::Wheel::Run FORK
  98. 98. POE Scope Perl process Perl process POE Kernel POE Kernel Session “event” Session POE::Wheel::Run “event” IO Wheel
  99. 99. POE Scope Perl process Logging POE Kernel Session DBI DBI DBI
  100. 100. POE Scope 12.40.45.26 POE::Component::IKC::Server “event” 22.1.122.6 POE::Component::IKC::Client
  101. 101. Conclusion
  102. 102. Conclusion - Great for doing many things concurrently, even if they are unrelated
  103. 103. Conclusion - Great for doing many things concurrently, even if they are unrelated - Good management of scope
  104. 104. Conclusion - Great for doing many things concurrently, even if they are unrelated - Good management of scope - Non-blocking nature makes it relatively high performance
  105. 105. Conclusion - Great for doing many things concurrently, even if they are unrelated - Good management of scope - Non-blocking nature makes it relatively high performance - Requires non-blocking POE Modules, which limits CPAN usage

×