1AnyEvent::Loop(3) User Contributed Perl Documentation AnyEvent::Loop(3)
2
3
4
6 AnyEvent::Loop - AnyEvent's Pure-Perl event loop
7
9 use AnyEvent;
10 # use AnyEvent::Loop;
11
12 # this module gets loaded automatically when no other loop can be found
13
14 # Explicit use:
15 use AnyEvent::Loop;
16 use AnyEvent;
17
18 ...
19
20 AnyEvent::Loop::run; # run the event loop
21
23 This module provides an event loop for AnyEvent in case no other event
24 loop could be found or loaded. You don't have to do anything to make it
25 work with AnyEvent except by possibly loading it before creating the
26 first AnyEvent watcher.
27
28 This module is not some loop abstracion used by AnyEvent, but just
29 another event loop like EV or Glib, just written in pure perl and
30 delivered with AnyEvent, so AnyEvent always works, even in the absence
31 of any other backend.
32
33 If you want to use this module instead of autoloading a potentially
34 better event loop you can simply load it (and no other event loops)
35 before creating the first watcher.
36
37 As for performance, this module is on par with (and usually faster
38 than) most select/poll-based C event modules such as Event or Glib (it
39 does not even come close to EV, though), with respect to I/O watchers.
40 Timers are handled less optimally, but for many common tasks, it is
41 still on par with event loops written in C.
42
43 This event loop has been optimised for the following use cases:
44
45 monotonic clock is available
46 This module will use the POSIX monotonic clock option (if it can be
47 detected at runtime) or the POSIX "times" function (if the
48 resolution is at least 100Hz), in which case it will not suffer
49 adversely from time jumps.
50
51 If no monotonic clock is available, this module will not attempt to
52 correct for time jumps in any way.
53
54 The clock chosen will be reported if the environment variable
55 $PERL_ANYEVENT_VERBOSE is set to 8 or higher.
56
57 any number of watchers on one fd
58 Supporting a large number of watchers per fd is purely a dirty
59 benchmark optimisation not relevant in practise. The more common
60 case of having one watcher per fd/poll combo is special-cased,
61 however, and therefore fast, too.
62
63 relatively few active fds per "select" call
64 This module expects that only a tiny amount of fds is active at any
65 one time. This is relatively typical of larger servers (but not the
66 case where "select" traditionally is fast), at the expense of the
67 "dense activity case" where most of the fds are active (which suits
68 "select").
69
70 The optimal implementation of the "dense" case is not much faster,
71 though, so the module should behave very well in most cases,
72 subject to the bad scalability of "select" in the presence of a
73 large number of inactive file descriptors.
74
75 lots of timer changes/iteration, or none at all
76 This module sorts the timer list using perl's "sort", even though a
77 total ordering is not required for timers internally.
78
79 This sorting is expensive, but means sorting can be avoided unless
80 the timer list has changed in a way that requires a new sort.
81
82 This means that adding lots of timers is very efficient, as well as
83 not changing the timers. Advancing timers (e.g. recreating a
84 timeout watcher on activity) is also relatively efficient, for
85 example, if you have a large number of timeout watchers that time
86 out after 10 seconds, then the timer list will be sorted only once
87 every 10 seconds.
88
89 This should not have much of an impact unless you have hundreds or
90 thousands of timers, though, or your timers have very small
91 timeouts.
92
94 The only user-visible functions provided by this module loop related -
95 watchers are created via the normal AnyEvent mechanisms.
96
97 AnyEvent::Loop::run
98 Run the event loop, usually the last thing done in the main program
99 when you want to use the pure-perl backend.
100
101 AnyEvent::Loop::one_event
102 Blocks until at least one new event has been received by the
103 operating system, whether or not it was AnyEvent-related.
104
106 AnyEvent.
107
109 Marc Lehmann <schmorp@schmorp.de>
110 http://anyevent.schmorp.de
111
112
113
114perl v5.32.0 2020-07-28 AnyEvent::Loop(3)