Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Network Programming With Anyevent

4.209 Aufrufe

Veröffentlicht am

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

Veröffentlicht in: Technologie, Business
  • Als Erste(r) kommentieren

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!

×