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

Comparing BDB/BDB.pm (file contents):
Revision 1.17 by root, Tue Dec 4 10:13:50 2007 UTC vs.
Revision 1.18 by root, Tue Dec 4 11:07:39 2007 UTC

435interactiveness when perl is not fast enough to process all requests in 435interactiveness when perl is not fast enough to process all requests in
436time. 436time.
437 437
438For interactive programs, values such as C<0.01> to C<0.1> should be fine. 438For interactive programs, values such as C<0.01> to C<0.1> should be fine.
439 439
440Example: Install an Event watcher that automatically calls 440Example: Install an EV watcher that automatically calls
441BDB::poll_cb with low priority, to ensure that other parts of the 441BDB::poll_cb with low priority, to ensure that other parts of the
442program get the CPU sometimes even under high AIO load. 442program 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
454If there are any outstanding requests and none of them in the result 451If there are any outstanding requests and none of them in the result
455phase, wait till the result filehandle becomes ready for reading (simply 452phase, 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
472Wait till all outstanding AIO requests have been handled. 469Wait till all outstanding BDB requests have been handled.
473 470
474Strictly equivalent to: 471Strictly 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
487Set the minimum number of AIO threads to C<$nthreads>. The current 484Set the minimum number of BDB threads to C<$nthreads>. The current
488default is C<8>, which means eight asynchronous operations can execute 485default is C<8>, which means eight asynchronous operations can execute
489concurrently at any one time (the number of outstanding requests, 486concurrently at any one time (the number of outstanding requests,
490however, is unlimited). 487however, is unlimited).
491 488
492BDB starts threads only on demand, when an AIO request is queued and 489BDB starts threads only on demand, when an BDB request is queued and
493no free thread exists. Please note that queueing up a hundred requests can 490no free thread exists. Please note that queueing up a hundred requests can
494create demand for a hundred threads, even if it turns out that everything 491create demand for a hundred threads, even if it turns out that everything
495is in the cache and could have been processed faster by a single thread. 492is in the cache and could have been processed faster by a single thread.
496 493
497It is recommended to keep the number of threads relatively low, as some 494It is recommended to keep the number of threads relatively low, as some
502Under most circumstances you don't need to call this function, as the 499Under most circumstances you don't need to call this function, as the
503module selects a default that is suitable for low to moderate load. 500module 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
507Sets the maximum number of AIO threads to C<$nthreads>. If more than the 504Sets the maximum number of BDB threads to C<$nthreads>. If more than the
508specified number of threads are currently running, this function kills 505specified number of threads are currently running, this function kills
509them. This function blocks until the limit is reached. 506them. This function blocks until the limit is reached.
510 507
511While C<$nthreads> are zero, aio requests get queued but not executed 508While C<$nthreads> are zero, aio requests get queued but not executed
512until the number of threads has been increased again. 509until the number of threads has been increased again.
615 612
616=head2 FORK BEHAVIOUR 613=head2 FORK BEHAVIOUR
617 614
618This module should do "the right thing" when the process using it forks: 615This module should do "the right thing" when the process using it forks:
619 616
620Before the fork, IO::AIO enters a quiescent state where no requests 617Before the fork, BDB enters a quiescent state where no requests
621can be added in other threads and no results will be processed. After 618can be added in other threads and no results will be processed. After
622the fork the parent simply leaves the quiescent state and continues 619the fork the parent simply leaves the quiescent state and continues
623request/result processing, while the child frees the request/result queue 620request/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
625parent). Threads will be started on demand until the limit set in the 622parent). Threads will be started on demand until the limit set in the
626parent process has been reached again. 623parent process has been reached again.
627 624
628In short: the parent will, after a short pause, continue as if fork had 625In short: the parent will, after a short pause, continue as if fork had
629not been called, while the child will act as if IO::AIO has not been used 626not been called, while the child will act as if BDB has not been used
630yet. 627yet.
631 628
632=head2 MEMORY USAGE 629=head2 MEMORY USAGE
633 630
634Per-request usage: 631Per-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
662L<Coro::AIO>. 659L<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/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines