… | |
… | |
137 | C<want_poll> you would write a single byte, in C<done_poll> you would try |
137 | C<want_poll> you would write a single byte, in C<done_poll> you would try |
138 | to read that byte, and in the callback for the read end, you would call |
138 | to read that byte, and in the callback for the read end, you would call |
139 | C<eio_poll>. The race is avoided here because the event loop should invoke |
139 | C<eio_poll>. The race is avoided here because the event loop should invoke |
140 | your callback again and again until the byte has been read (as the pipe |
140 | your callback again and again until the byte has been read (as the pipe |
141 | read callback does not read it, only C<done_poll>). |
141 | read callback does not read it, only C<done_poll>). |
142 | |
|
|
143 | =head2 CONFIGURATION |
|
|
144 | |
|
|
145 | The functions in this section can sometimes be useful, but the default |
|
|
146 | configuration will do in most case, so you should skip this section on |
|
|
147 | first reading. |
|
|
148 | |
|
|
149 | =over 4 |
|
|
150 | |
|
|
151 | =item eio_set_max_poll_time (eio_tstamp nseconds) |
|
|
152 | |
|
|
153 | This causes C<eio_poll ()> to return after it has detected that it was |
|
|
154 | running for C<nsecond> seconds or longer (this number can be fractional). |
|
|
155 | |
|
|
156 | This can be used to limit the amount of time spent handling eio requests, |
|
|
157 | for example, in interactive programs, you might want to limit this time to |
|
|
158 | C<0.01> seconds or so. |
|
|
159 | |
|
|
160 | Note that: |
|
|
161 | |
|
|
162 | a) libeio doesn't know how long your request callbacks take, so the time |
|
|
163 | spent in C<eio_poll> is up to one callback invocation longer then this |
|
|
164 | interval. |
|
|
165 | |
|
|
166 | b) this is implemented by calling C<gettimeofday> after each request, |
|
|
167 | which can be costly. |
|
|
168 | |
|
|
169 | c) at least one request will be handled. |
|
|
170 | |
|
|
171 | =item eio_set_max_poll_reqs (unsigned int nreqs) |
|
|
172 | |
|
|
173 | When C<nreqs> is non-zero, then C<eio_poll> will not handle more than |
|
|
174 | C<nreqs> requests per invocation. This is a less costly way to limit the |
|
|
175 | amount of work done by C<eio_poll> then setting a time limit. |
|
|
176 | |
|
|
177 | If you know your callbacks are generally fast, you could use this to |
|
|
178 | encourage interactiveness in your programs by setting it to C<10>, C<100> |
|
|
179 | or even C<1000>. |
|
|
180 | |
|
|
181 | =item eio_set_min_parallel (unsigned int nthreads) |
|
|
182 | |
|
|
183 | Make sure libeio can handle at least this many requests in parallel. It |
|
|
184 | might be able handle more. |
|
|
185 | |
|
|
186 | =item eio_set_max_parallel (unsigned int nthreads) |
|
|
187 | |
|
|
188 | Set the maximum number of threads that libeio will spawn. |
|
|
189 | |
|
|
190 | =item eio_set_max_idle (unsigned int nthreads) |
|
|
191 | |
|
|
192 | Libeio uses threads internally to handle most requests, and will start and stop threads on demand. |
|
|
193 | |
|
|
194 | This call can be used to limit the number of idle threads (threads without |
|
|
195 | work to do): libeio will keep some threads idle in preparation for more |
|
|
196 | requests, but never longer than C<nthreads> threads. |
|
|
197 | |
|
|
198 | In addition to this, libeio will also stop threads when they are idle for |
|
|
199 | a few seconds, regardless of this setting. |
|
|
200 | |
|
|
201 | =item unsigned int eio_nthreads () |
|
|
202 | |
|
|
203 | Return the number of worker threads currently running. |
|
|
204 | |
|
|
205 | =item unsigned int eio_nreqs () |
|
|
206 | |
|
|
207 | Return the number of requests currently handled by libeio. This is the |
|
|
208 | total number of requests that have been submitted to libeio, but not yet |
|
|
209 | destroyed. |
|
|
210 | |
|
|
211 | =item unsigned int eio_nready () |
|
|
212 | |
|
|
213 | Returns the number of ready requests, i.e. requests that have been |
|
|
214 | submitted but have not yet entered the execution phase. |
|
|
215 | |
|
|
216 | =item unsigned int eio_npending () |
|
|
217 | |
|
|
218 | Returns the number of pending requests, i.e. requests that have been |
|
|
219 | executed and have results, but have not been finished yet by a call to |
|
|
220 | C<eio_poll>). |
|
|
221 | |
|
|
222 | =back |
|
|
223 | |
142 | |
224 | |
143 | |
225 | =head1 HIGH LEVEL REQUEST API |
144 | =head1 HIGH LEVEL REQUEST API |
226 | |
145 | |
227 | Libeio has both a high-level API, which consists of calling a request |
146 | Libeio has both a high-level API, which consists of calling a request |
… | |
… | |
569 | |
488 | |
570 | These requests are specific to libeio and do not correspond to any OS call. |
489 | These requests are specific to libeio and do not correspond to any OS call. |
571 | |
490 | |
572 | =over 4 |
491 | =over 4 |
573 | |
492 | |
574 | =item eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
493 | =item eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
575 | |
494 | |
|
|
495 | Reads (C<flags == 0>) or modifies (C<flags == EIO_MT_MODIFY) the given |
|
|
496 | memory area, page-wise, that is, it reads (or reads and writes back) the |
|
|
497 | first octet of every page that spans the memory area. |
|
|
498 | |
|
|
499 | This can be used to page in some mmapped file, or dirty some pages. Note |
|
|
500 | that dirtying is an unlocked read-write access, so races can ensue when |
|
|
501 | the some other thread modifies the data stored in that memory area. |
|
|
502 | |
576 | =item eio_custom (void (*)(eio_req *) execute, int pri, eio_cb cb, void *data) |
503 | =item eio_custom (void (*)(eio_req *) execute, int pri, eio_cb cb, void *data) |
577 | |
504 | |
578 | Executes a custom request, i.e., a user-specified callback. |
505 | Executes a custom request, i.e., a user-specified callback. |
579 | |
506 | |
580 | The callback gets the C<eio_req *> as parameter and is expected to read |
507 | The callback gets the C<eio_req *> as parameter and is expected to read |
581 | and modify any request-specific members. Specifically, it should set C<< |
508 | and modify any request-specific members. Specifically, it should set C<< |
… | |
… | |
601 | req->result = open (req->data, O_RDONLY); |
528 | req->result = open (req->data, O_RDONLY); |
602 | } |
529 | } |
603 | |
530 | |
604 | eio_custom (my_open, 0, my_open_done, "/etc/passwd"); |
531 | eio_custom (my_open, 0, my_open_done, "/etc/passwd"); |
605 | |
532 | |
606 | =item eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data) |
533 | =item eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data) |
607 | |
534 | |
608 | This is a a request that takes C<delay> seconds to execute, but otherwise |
535 | This is a a request that takes C<delay> seconds to execute, but otherwise |
609 | does nothing - it simply puts one of the worker threads to sleep for this |
536 | does nothing - it simply puts one of the worker threads to sleep for this |
610 | long. |
537 | long. |
611 | |
538 | |
612 | This request can be used to artificially increase load, e.g. for debugging |
539 | This request can be used to artificially increase load, e.g. for debugging |
613 | or benchmarking reasons. |
540 | or benchmarking reasons. |
614 | |
541 | |
615 | =item eio_nop (int pri, eio_cb cb, void *data) |
542 | =item eio_nop (int pri, eio_cb cb, void *data) |
616 | |
543 | |
617 | This request does nothing, except go through the whole request cycle. This |
544 | This request does nothing, except go through the whole request cycle. This |
618 | can be used to measure latency or in some cases to simplify code, but is |
545 | can be used to measure latency or in some cases to simplify code, but is |
619 | not really of much use. |
546 | not really of much use. |
620 | |
547 | |
… | |
… | |
660 | |
587 | |
661 | zero |
588 | zero |
662 | |
589 | |
663 | #TODO |
590 | #TODO |
664 | |
591 | |
|
|
592 | =head2 CONFIGURATION |
|
|
593 | |
|
|
594 | The functions in this section can sometimes be useful, but the default |
|
|
595 | configuration will do in most case, so you should skip this section on |
|
|
596 | first reading. |
|
|
597 | |
|
|
598 | =over 4 |
|
|
599 | |
|
|
600 | =item eio_set_max_poll_time (eio_tstamp nseconds) |
|
|
601 | |
|
|
602 | This causes C<eio_poll ()> to return after it has detected that it was |
|
|
603 | running for C<nsecond> seconds or longer (this number can be fractional). |
|
|
604 | |
|
|
605 | This can be used to limit the amount of time spent handling eio requests, |
|
|
606 | for example, in interactive programs, you might want to limit this time to |
|
|
607 | C<0.01> seconds or so. |
|
|
608 | |
|
|
609 | Note that: |
|
|
610 | |
|
|
611 | a) libeio doesn't know how long your request callbacks take, so the time |
|
|
612 | spent in C<eio_poll> is up to one callback invocation longer then this |
|
|
613 | interval. |
|
|
614 | |
|
|
615 | b) this is implemented by calling C<gettimeofday> after each request, |
|
|
616 | which can be costly. |
|
|
617 | |
|
|
618 | c) at least one request will be handled. |
|
|
619 | |
|
|
620 | =item eio_set_max_poll_reqs (unsigned int nreqs) |
|
|
621 | |
|
|
622 | When C<nreqs> is non-zero, then C<eio_poll> will not handle more than |
|
|
623 | C<nreqs> requests per invocation. This is a less costly way to limit the |
|
|
624 | amount of work done by C<eio_poll> then setting a time limit. |
|
|
625 | |
|
|
626 | If you know your callbacks are generally fast, you could use this to |
|
|
627 | encourage interactiveness in your programs by setting it to C<10>, C<100> |
|
|
628 | or even C<1000>. |
|
|
629 | |
|
|
630 | =item eio_set_min_parallel (unsigned int nthreads) |
|
|
631 | |
|
|
632 | Make sure libeio can handle at least this many requests in parallel. It |
|
|
633 | might be able handle more. |
|
|
634 | |
|
|
635 | =item eio_set_max_parallel (unsigned int nthreads) |
|
|
636 | |
|
|
637 | Set the maximum number of threads that libeio will spawn. |
|
|
638 | |
|
|
639 | =item eio_set_max_idle (unsigned int nthreads) |
|
|
640 | |
|
|
641 | Libeio uses threads internally to handle most requests, and will start and stop threads on demand. |
|
|
642 | |
|
|
643 | This call can be used to limit the number of idle threads (threads without |
|
|
644 | work to do): libeio will keep some threads idle in preparation for more |
|
|
645 | requests, but never longer than C<nthreads> threads. |
|
|
646 | |
|
|
647 | In addition to this, libeio will also stop threads when they are idle for |
|
|
648 | a few seconds, regardless of this setting. |
|
|
649 | |
|
|
650 | =item unsigned int eio_nthreads () |
|
|
651 | |
|
|
652 | Return the number of worker threads currently running. |
|
|
653 | |
|
|
654 | =item unsigned int eio_nreqs () |
|
|
655 | |
|
|
656 | Return the number of requests currently handled by libeio. This is the |
|
|
657 | total number of requests that have been submitted to libeio, but not yet |
|
|
658 | destroyed. |
|
|
659 | |
|
|
660 | =item unsigned int eio_nready () |
|
|
661 | |
|
|
662 | Returns the number of ready requests, i.e. requests that have been |
|
|
663 | submitted but have not yet entered the execution phase. |
|
|
664 | |
|
|
665 | =item unsigned int eio_npending () |
|
|
666 | |
|
|
667 | Returns the number of pending requests, i.e. requests that have been |
|
|
668 | executed and have results, but have not been finished yet by a call to |
|
|
669 | C<eio_poll>). |
|
|
670 | |
|
|
671 | =back |
|
|
672 | |
665 | =head1 EMBEDDING |
673 | =head1 EMBEDDING |
666 | |
674 | |
667 | Libeio can be embedded directly into programs. This functionality is not |
675 | Libeio can be embedded directly into programs. This functionality is not |
668 | documented and not (yet) officially supported. |
676 | documented and not (yet) officially supported. |
669 | |
677 | |