ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-XSThreadPool/XSThreadPool.pm
(Generate patch)

Comparing AnyEvent-XSThreadPool/XSThreadPool.pm (file contents):
Revision 1.2 by root, Thu Jun 25 21:24:18 2015 UTC vs.
Revision 1.3 by root, Thu Jun 25 21:39:57 2015 UTC

42 &_destroy; 42 &_destroy;
43} 43}
44 44
45=item $pool->req (REQUEST_TYPE, [request-args], $callback) 45=item $pool->req (REQUEST_TYPE, [request-args], $callback)
46 46
47=item AnyEvent::XSThreadPool::req $pool, REQUEST_TYPE, [request-args], $callback
48
49This is the same as the C<< ->req >> method, above, except as a function
50call. If you submit many small requests, the function syntax executes much
51faster, but is less convenient than the method syntax.
52
47=item $fd = $pool->fileno 53=item $fd = $pool->fileno
48 54
49=item $nreqs = $pool->nreqs 55=item $nreqs = $pool->nreqs
50 56
51=item $nready = $pool->nready 57=item $nready = $pool->nready
66 72
67=item $pool->max_parallel ($nthreads) 73=item $pool->max_parallel ($nthreads)
68 74
69=back 75=back
70 76
77=head2 AnyEvent::XSThreadPool REQUEST TYPES DEFINED BY THIS MODULE
78
79This module defines only two rather lame request types, which can nevertheless be used to
80test out the module.
81
82=over 4
83
84=item AnyEvent::XSThreadPool::sleep $seconds, $callback->()
85
86This request type simply puts the worker thread to sleep for the given
87number of (fractional) seconds. This can be used to simulate a very slow
88request, without actually putting stress on the machine.
89
90Example: execute two 1.2 second sleeps and wait for them. Normally this
91should take only about 1.2 seconds overall, as the sleeps execute in
92parallel.
93
94 AnyEvent::XSThreadPool::cpupool->req (AnyEvent::XSThreadPool::sleep, 1.2, my $cv1 = AE::cv);
95 AnyEvent::XSThreadPool::cpupool->req (AnyEvent::XSThreadPool::sleep, 1.2, my $cv2 = AE::cv);
96 $cv1->recv;
97 $cv2->recv;
98
99=item AnyEvent::XSThreadPool::burn $seconds, $callback->($iterations)
100
101This request type burns cpu cycles by calling C<gettimeofday> (or an
102equivalent function) in a loop, for the given number of (fractional)
103seconds, counting how many times it looped.
104
105This can be used to simulate actual cpu load on your machine, or it could
106be used as a primitive benchmark (although this is not advised).
107
108Example: see how often the module can call gettimeofday within 0.1 seconds.
109
110 my $cv = AE::cv;
111 AnyEvent::XSThreadPool::cpupool->req (AnyEvent::XSThreadPool::burn => 0.1, sub {
112 printf "executed %d cycles in 0.1s\n", $_[0];
113 $cv->();
114 });
115 $cv->recv;
116
117 # outputs, on my current development box:
118 # executed 3900480 cycles in 0.1s
119
120=back
121
71=head1 AUTHOR 122=head1 AUTHOR
72 123
73 Marc Lehmann <schmorp@schmorp.de> 124 Marc Lehmann <schmorp@schmorp.de>
74 http://software.schmorp.de/pkg/AnyEvent-XSThreadPool.html 125 http://software.schmorp.de/pkg/AnyEvent-XSThreadPool.html
75 126

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines