… | |
… | |
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 | |
|
|
49 | This is the same as the C<< ->req >> method, above, except as a function |
|
|
50 | call. If you submit many small requests, the function syntax executes much |
|
|
51 | faster, 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 | |
|
|
79 | This module defines only two rather lame request types, which can nevertheless be used to |
|
|
80 | test out the module. |
|
|
81 | |
|
|
82 | =over 4 |
|
|
83 | |
|
|
84 | =item AnyEvent::XSThreadPool::sleep $seconds, $callback->() |
|
|
85 | |
|
|
86 | This request type simply puts the worker thread to sleep for the given |
|
|
87 | number of (fractional) seconds. This can be used to simulate a very slow |
|
|
88 | request, without actually putting stress on the machine. |
|
|
89 | |
|
|
90 | Example: execute two 1.2 second sleeps and wait for them. Normally this |
|
|
91 | should take only about 1.2 seconds overall, as the sleeps execute in |
|
|
92 | parallel. |
|
|
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 | |
|
|
101 | This request type burns cpu cycles by calling C<gettimeofday> (or an |
|
|
102 | equivalent function) in a loop, for the given number of (fractional) |
|
|
103 | seconds, counting how many times it looped. |
|
|
104 | |
|
|
105 | This can be used to simulate actual cpu load on your machine, or it could |
|
|
106 | be used as a primitive benchmark (although this is not advised). |
|
|
107 | |
|
|
108 | Example: 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 | |