Network Programming
   with AnyEvent
PtPW’08 - {mailto,xmpp}:melo@simplicidade.org
Contenders

• POE
• Event
• Danga::Socket
• AnyEvent
Overhead
  10k servers, 20k sockets, 1% active
15,000

11,250

 7,500

 3,750

    0
               create             req...
Overhead
      10k servers, 20k sockets
300

225

150

 75

  0
             create          request

        EV          ...
Overhead
           8 servers, 16 sockets
300

225

150

 75

  0
              create             request

      EV     P...
Overhead
            8 servers, 16 sockets
90.0

67.5

45.0

22.5

  0
               create             request

       E...
AnyEvent
• framework for event driven programming
• thin layer above several event loops
 • EV, Event, Gtk, Tk, POE
• deal...
Watchers and
         Condvars
• AnyEvent has two basic concepts
 • Watchers
 • Condvars
• Watchers wait for externals eve...
IO Watchers

• Covers file handles, sockets, unix domain
  sockets
• Deals with buffered reads and writes
• Can also deal w...
Timers

• Execute callback sometime in the future
• Single shot timers only
• Common uses: timeouts
Condvars

• Provide syncronization inside your program
• A simple broadcast service
 • Multiple interested parties
 • Anyb...
Read a line

$| = 1; print quot;enter your name> quot;;

my $name = <STDIN>;
Read a line, take II
use AnyEvent;
$| = 1; print quot;enter your name> quot;;
my $name;
my $wait_for_input = AnyEvent->io ...
Demo

• A simple broadcast server
• Multiple clients
• Broadcasts lines sent by one client to all
  the others
• Code http...
Thanks!
Upcoming SlideShare
Loading in...5
×

Network Programming With Anyevent

3,229

Published on

A quick and dirty presentation about network programming using the Perl module AnyEvent

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

No Downloads
Views
Total Views
3,229
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
80
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Network Programming With Anyevent

  1. 1. Network Programming with AnyEvent PtPW’08 - {mailto,xmpp}:melo@simplicidade.org
  2. 2. Contenders • POE • Event • Danga::Socket • AnyEvent
  3. 3. Overhead 10k servers, 20k sockets, 1% active 15,000 11,250 7,500 3,750 0 create request EV Perl Event Glib POE
  4. 4. Overhead 10k servers, 20k sockets 300 225 150 75 0 create request EV Perl Event
  5. 5. Overhead 8 servers, 16 sockets 300 225 150 75 0 create request EV Perl Event Glib POE
  6. 6. Overhead 8 servers, 16 sockets 90.0 67.5 45.0 22.5 0 create request EV Perl Event Glib
  7. 7. AnyEvent • framework for event driven programming • thin layer above several event loops • EV, Event, Gtk, Tk, POE • deals with IO handles (incl. unix domain sockets), timers, signals, processes • thousands of sockets with proper event loop (EV)
  8. 8. Watchers and Condvars • AnyEvent has two basic concepts • Watchers • Condvars • Watchers wait for externals events: socket input, timer expiration, child process exits • Condvars are a synchronization primitive
  9. 9. IO Watchers • Covers file handles, sockets, unix domain sockets • Deals with buffered reads and writes • Can also deal with “reading lines” or “block of bytes”: callback only when we have everything
  10. 10. Timers • Execute callback sometime in the future • Single shot timers only • Common uses: timeouts
  11. 11. Condvars • Provide syncronization inside your program • A simple broadcast service • Multiple interested parties • Anybody can trigger it • All the interested parties will be notified
  12. 12. Read a line $| = 1; print quot;enter your name> quot;; my $name = <STDIN>;
  13. 13. Read a line, take II use AnyEvent; $| = 1; print quot;enter your name> quot;; my $name; my $wait_for_input = AnyEvent->io ( fh => *STDIN, poll => quot;rquot;, cb => sub { $name = <STDIN>; } );
  14. 14. Demo • A simple broadcast server • Multiple clients • Broadcasts lines sent by one client to all the others • Code http://github.com/melo/presentations/
  15. 15. Thanks!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×