… | |
… | |
435 | interactiveness when perl is not fast enough to process all requests in |
435 | interactiveness when perl is not fast enough to process all requests in |
436 | time. |
436 | time. |
437 | |
437 | |
438 | For interactive programs, values such as C<0.01> to C<0.1> should be fine. |
438 | For interactive programs, values such as C<0.01> to C<0.1> should be fine. |
439 | |
439 | |
440 | Example: Install an Event watcher that automatically calls |
440 | Example: Install an EV watcher that automatically calls |
441 | BDB::poll_cb with low priority, to ensure that other parts of the |
441 | BDB::poll_cb with low priority, to ensure that other parts of the |
442 | program get the CPU sometimes even under high AIO load. |
442 | program get the CPU sometimes even under high load. |
443 | |
443 | |
444 | # try not to spend much more than 0.1s in poll_cb |
444 | # try not to spend much more than 0.1s in poll_cb |
445 | BDB::max_poll_time 0.1; |
445 | BDB::max_poll_time 0.1; |
446 | |
446 | |
447 | # use a low priority so other tasks have priority |
447 | my $bdb_poll = EV::io BDB::poll_fileno, EV::READ, \&BDB::poll_cb); |
448 | Event->io (fd => BDB::poll_fileno, |
|
|
449 | poll => 'r', nice => 1, |
|
|
450 | cb => &BDB::poll_cb); |
|
|
451 | |
448 | |
452 | =item BDB::poll_wait |
449 | =item BDB::poll_wait |
453 | |
450 | |
454 | If there are any outstanding requests and none of them in the result |
451 | If there are any outstanding requests and none of them in the result |
455 | phase, wait till the result filehandle becomes ready for reading (simply |
452 | phase, wait till the result filehandle becomes ready for reading (simply |
… | |
… | |
467 | |
464 | |
468 | BDB::poll_wait, BDB::poll_cb |
465 | BDB::poll_wait, BDB::poll_cb |
469 | |
466 | |
470 | =item BDB::flush |
467 | =item BDB::flush |
471 | |
468 | |
472 | Wait till all outstanding AIO requests have been handled. |
469 | Wait till all outstanding BDB requests have been handled. |
473 | |
470 | |
474 | Strictly equivalent to: |
471 | Strictly equivalent to: |
475 | |
472 | |
476 | BDB::poll_wait, BDB::poll_cb |
473 | BDB::poll_wait, BDB::poll_cb |
477 | while BDB::nreqs; |
474 | while BDB::nreqs; |
… | |
… | |
482 | |
479 | |
483 | =over 4 |
480 | =over 4 |
484 | |
481 | |
485 | =item BDB::min_parallel $nthreads |
482 | =item BDB::min_parallel $nthreads |
486 | |
483 | |
487 | Set the minimum number of AIO threads to C<$nthreads>. The current |
484 | Set the minimum number of BDB threads to C<$nthreads>. The current |
488 | default is C<8>, which means eight asynchronous operations can execute |
485 | default is C<8>, which means eight asynchronous operations can execute |
489 | concurrently at any one time (the number of outstanding requests, |
486 | concurrently at any one time (the number of outstanding requests, |
490 | however, is unlimited). |
487 | however, is unlimited). |
491 | |
488 | |
492 | BDB starts threads only on demand, when an AIO request is queued and |
489 | BDB starts threads only on demand, when an BDB request is queued and |
493 | no free thread exists. Please note that queueing up a hundred requests can |
490 | no free thread exists. Please note that queueing up a hundred requests can |
494 | create demand for a hundred threads, even if it turns out that everything |
491 | create demand for a hundred threads, even if it turns out that everything |
495 | is in the cache and could have been processed faster by a single thread. |
492 | is in the cache and could have been processed faster by a single thread. |
496 | |
493 | |
497 | It is recommended to keep the number of threads relatively low, as some |
494 | It is recommended to keep the number of threads relatively low, as some |
… | |
… | |
502 | Under most circumstances you don't need to call this function, as the |
499 | Under most circumstances you don't need to call this function, as the |
503 | module selects a default that is suitable for low to moderate load. |
500 | module selects a default that is suitable for low to moderate load. |
504 | |
501 | |
505 | =item BDB::max_parallel $nthreads |
502 | =item BDB::max_parallel $nthreads |
506 | |
503 | |
507 | Sets the maximum number of AIO threads to C<$nthreads>. If more than the |
504 | Sets the maximum number of BDB threads to C<$nthreads>. If more than the |
508 | specified number of threads are currently running, this function kills |
505 | specified number of threads are currently running, this function kills |
509 | them. This function blocks until the limit is reached. |
506 | them. This function blocks until the limit is reached. |
510 | |
507 | |
511 | While C<$nthreads> are zero, aio requests get queued but not executed |
508 | While C<$nthreads> are zero, aio requests get queued but not executed |
512 | until the number of threads has been increased again. |
509 | until the number of threads has been increased again. |
… | |
… | |
615 | |
612 | |
616 | =head2 FORK BEHAVIOUR |
613 | =head2 FORK BEHAVIOUR |
617 | |
614 | |
618 | This module should do "the right thing" when the process using it forks: |
615 | This module should do "the right thing" when the process using it forks: |
619 | |
616 | |
620 | Before the fork, IO::AIO enters a quiescent state where no requests |
617 | Before the fork, BDB enters a quiescent state where no requests |
621 | can be added in other threads and no results will be processed. After |
618 | can be added in other threads and no results will be processed. After |
622 | the fork the parent simply leaves the quiescent state and continues |
619 | the fork the parent simply leaves the quiescent state and continues |
623 | request/result processing, while the child frees the request/result queue |
620 | request/result processing, while the child frees the request/result queue |
624 | (so that the requests started before the fork will only be handled in the |
621 | (so that the requests started before the fork will only be handled in the |
625 | parent). Threads will be started on demand until the limit set in the |
622 | parent). Threads will be started on demand until the limit set in the |
626 | parent process has been reached again. |
623 | parent process has been reached again. |
627 | |
624 | |
628 | In short: the parent will, after a short pause, continue as if fork had |
625 | In short: the parent will, after a short pause, continue as if fork had |
629 | not been called, while the child will act as if IO::AIO has not been used |
626 | not been called, while the child will act as if BDB has not been used |
630 | yet. |
627 | yet. |
631 | |
628 | |
632 | =head2 MEMORY USAGE |
629 | =head2 MEMORY USAGE |
633 | |
630 | |
634 | Per-request usage: |
631 | Per-request usage: |
… | |
… | |
657 | TXN_DEADLOCK flag will be set on the transaction. See C<db_txn_finish>, |
654 | TXN_DEADLOCK flag will be set on the transaction. See C<db_txn_finish>, |
658 | above. |
655 | above. |
659 | |
656 | |
660 | =head1 SEE ALSO |
657 | =head1 SEE ALSO |
661 | |
658 | |
662 | L<Coro::AIO>. |
659 | L<Coro::BDB>, L<IO::AIO>. |
663 | |
660 | |
664 | =head1 AUTHOR |
661 | =head1 AUTHOR |
665 | |
662 | |
666 | Marc Lehmann <schmorp@schmorp.de> |
663 | Marc Lehmann <schmorp@schmorp.de> |
667 | http://home.schmorp.de/ |
664 | http://home.schmorp.de/ |