📄 00000006.htm
字号:
when a normal I/O function like read() or write() completes. <BR> Available in Linux 2.3.21 or higher. <BR> To use this, you choose a realtime signal number, mask that <BR>signal and SIGIO with sigprocmask(), use fcntl(fd, <BR> F_SETSIG, signum) on each fd, write a normal poll() outer <BR>loop, and inside it, after you've handled all the fd's <BR> noticed by poll(), you loop calling sigwaitinfo(). <BR> If sigwaitinfo returns your realtime signal, siginfo.si_fd and <BR> siginfo.si_band give the same information as pollfd.fd and <BR> pollfd.revents would after a call to poll(), so you handle the <BR> i/o, and continue calling sigwaitinfo(). <BR> If sigwaitinfo returns a traditional SIGIO, the signal queue <BR>overflowed, so you flush the signal queue by temporarily <BR> changing the signal handler to SIG_DFL, and break back to <BR>the outer poll() loop. <BR> You can support older kernels by surrounding the sigwaitinfo <BR>code with #if defined(LINUX_VERSION_CODE) <BR> && (LINUX_VERSION_CODE >= KERNEL_VERSION(2.3.21)) <BR> See Zach Brown's phhttpd for example code that uses this <BR>feature, and deals with some of the gotchas, e.g. events <BR> queued before an fd is dealt with or closed, but arriving <BR>afterwards. <BR> <BR> SIGIO (see glibc doc or BSD Sockets doc) -- doesn't tell you <BR>which handle needs servicing, so it seems kind of <BR> coarse. Used by the Linux F_SETSIG/aio_ implementation as a <BR>fallback when the realtime signal queue overflows. <BR> Here's an example of its use. (Was partly broken in Linux <BR>kernels 2.2.0 - 2.2.7, fixed in 2.2.8.) <BR> <BR>Richard Gooch has written a paper discussing these options. <BR>Interesting reading. <BR> <BR>The Apache mailing lists have some interesting posts about why they <BR>prefer not to use select() (basically, they think that makes <BR>plugins harder). Still, they're planning to use <BR>select()/poll()/sendfile() for static requests in Apache 2.0. <BR> <BR>Mark Russinovich wrote an editorial and an article discussing I/O <BR>strategy issues in the 2.2 Linux kernel. Worth reading, even he <BR>seems misinformed on some points. In particular, he seems to think <BR>that Linux 2.2's asyncrhonous I/O (see F_SETSIG above) <BR>doesn't notify the user process when data is ready, only when new <BR>connections arrive. This seems like a bizarre misunderstanding. <BR>See also comments on an earlier draft, a rebuttal from Mingo, <BR>Russinovich's comments of 2 May 1999, a rebuttal from Alan Cox, <BR>and various posts to linux-kernel. I suspect he was trying to say that <BR>Linux doesn't support asynchronous disk I/O, which is <BR>somewhat true. <BR> <BR>There was an interesting discussion on linux-kernel in September 1999 <BR>titled "> 15,000 Simultaneous Connections". (second <BR>week, third week) Highlights: <BR> <BR> Ed Hall posted a few notes on his experiences; he's achieved <BR>><I>1000 connects/second on a UP P2/333 running Solaris. His </I><BR> code used a small pool of threads (1 or 2 per CPU) each managing <BR>a large number of clients using "an event-based model". <BR> Mike Jagdis posted an analysis of poll/select overhead, and said <BR>"The current select/poll implementation can be improved <BR> significantly, especially in the blocking case, but the overhead <BR>will still increase with the number of descriptors because <BR> select/poll does not, and cannot, remember what descriptors are <BR>interesting. This would be easy to fix with a new API. <BR> Suggestions are welcome..." <BR> Mike posted about his work on improving select() and poll(). <BR> Mike posted a bit about a possible API to replace poll()/select(): <BR> "How about a 'device like' API where you write 'pollfd <BR> like' structs, the 'device' listens for events and delivers 'pollfd <BR> like' structs representing them when you read it? ... " <BR> Rogier Wolff suggested using "the API that the digital guys <BR>suggested", <A HREF="http://www.cs.rice.edu/~gaurav/papers/usenix99.ps">http://www.cs.rice.edu/~gaurav/papers/usenix99.ps</A> <BR> Joerg Pommnitz pointed out that any new API along these lines <BR>should be able to wait for not just file descriptor events, but <BR> also signals and maybe SYSV-IPC. Our synchronization primitives <BR>should certainly be able to do what Win32's <BR> WaitForMultipleObjects can, at least. <BR> Stephen Tweedie asserted that the combination of F_SETSIG, queued <BR>realtime signals, and sigwaitinfo() was a superset of <BR> the API proposed in <A HREF="http://www.cs.rice.">http://www.cs.rice.</A> <BR>edu/~gaurav/papers/usenix99.ps. He also mentions that you keep the <BR>signal <BR> blocked at all times if you're interested in performance; instead <BR>of the signal being delivered asynchronously, the process <BR> grabs the next one from the queue with sigwaitinfo(). <BR> Jayson Nordwick compared completion ports with the F_SETSIG <BR>synchronous event model, and concluded they're pretty <BR> similar. <BR> Alan Cox noted that an older rev of SCT's SIGIO patch is included <BR>in 2.3.18ac. <BR> Jordan Mendelson posted some example code showing how to use <BR>F_SETSIG. <BR> Stephen C. Tweedie continued the comparison of completion ports and <BR> F_SETSIG, and noted: "With a signal dequeuing <BR> mechanism, your application is going to get signals destined for <BR>various library components if libraries are using the same <BR> mechanism," but the library can set up its own signal handler, so <BR>this shouldn't affect the program (much). <BR> Doug Royer noted that he'd gotten 100,000 connections on Solaris <BR>2.6 while he was working on the Sun calendar server. <BR> Others chimed in with estimates of how much RAM that would <BR>require on Linux, and what bottlenecks would be hit. <BR> <BR>Interesting reading! <BR> <BR>Limits on open filehandles <BR> <BR> Any Unix: the limits set by ulimit or setrlimit. <BR> Solaris: see the Solaris FAQ, question 3.45. <BR> FreeBSD: use sysctl -w kern.maxfiles=nnnn to raise limit <BR> Linux: See Bodo Bauer's /proc documentation. On current 2.2.x <BR>kernels, <BR> <BR> echo 32768 > /proc/sys/fs/file-max <BR> echo 65536 > /proc/sys/fs/inode-max <BR> <BR> increases the system limit on open files, and <BR> <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -