ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/eio.pod
(Generate patch)

Comparing libeio/eio.pod (file contents):
Revision 1.7 by root, Sun Jun 5 22:44:30 2011 UTC vs.
Revision 1.9 by root, Sun Jun 5 23:07:46 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines