… | |
… | |
13 | |
13 | |
14 | This module implements asynchronous DBI access my forking or executing |
14 | This module implements asynchronous DBI access my forking or executing |
15 | separate "DBI-Server" processes and sending them requests. |
15 | separate "DBI-Server" processes and sending them requests. |
16 | |
16 | |
17 | It means that you can run DBI requests in parallel to other tasks. |
17 | It means that you can run DBI requests in parallel to other tasks. |
|
|
18 | |
|
|
19 | The overhead for very simple statements ("select 0") is somewhere |
|
|
20 | around 120% to 200% (single/dual core CPU) compared to an explicit |
|
|
21 | prepare_cached/execute/fetchrow_arrayref/finish combination. |
18 | |
22 | |
19 | =cut |
23 | =cut |
20 | |
24 | |
21 | package AnyEvent::DBI; |
25 | package AnyEvent::DBI; |
22 | |
26 | |
… | |
… | |
184 | } else { |
188 | } else { |
185 | $wself->_error ("read error: $!", @caller, 1); |
189 | $wself->_error ("read error: $!", @caller, 1); |
186 | } |
190 | } |
187 | }); |
191 | }); |
188 | |
192 | |
|
|
193 | $self->{ww_cb} = sub { |
|
|
194 | my $len = syswrite $client, $wself->{wbuf} |
|
|
195 | or return delete $wself->{ww}; |
|
|
196 | |
|
|
197 | substr $wself->{wbuf}, 0, $len, ""; |
|
|
198 | }; |
|
|
199 | |
189 | my $pid = fork; |
200 | my $pid = fork; |
190 | |
201 | |
191 | if ($pid) { |
202 | if ($pid) { |
192 | # parent |
203 | # parent |
193 | close $server; |
204 | close $server; |
… | |
… | |
231 | |
242 | |
232 | unless ($self->{ww}) { |
243 | unless ($self->{ww}) { |
233 | my $len = syswrite $self->{fh}, $self->{wbuf}; |
244 | my $len = syswrite $self->{fh}, $self->{wbuf}; |
234 | substr $self->{wbuf}, 0, $len, ""; |
245 | substr $self->{wbuf}, 0, $len, ""; |
235 | |
246 | |
236 | #TODO, ww_cb |
|
|
237 | # still any left? then install a write watcher |
247 | # still any left? then install a write watcher |
238 | $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $self->{ww_cb}) |
248 | $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $self->{ww_cb}) |
239 | if length $self->{wbuf}; |
249 | if length $self->{wbuf}; |
240 | } |
250 | } |
241 | } |
251 | } |