Berkeley CSUA MOTD:Entry 28792
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/07/09 [General] UID:1000 Activity:popular
7/9     

2003/6/21 [Computer/SW/Database, Computer/SW/OS/Windows] UID:28792 Activity:high
6/20    anyone have a good reference on the advantages of nonblocking io?
        some guy i'm talking to is insisting that blocking w/ select is better
        than nonblocking. he says "if your IO is nonblocking, you're going
        to use 100% CPU." ?!!@?$#
        \_ http://tangentsoft.net/wskfaq/articles/io-strategies.html
        \_ kqueue!
        \_ Don't you have to use select/poll with both blocking and
           non-blocking fd's in order to know when you can read/write
           to the fd? How can one be better than the other?
           to the fd? How can one be better than the other? -!*nix hacker
           \_ if you use read or write on a blocking fd then those system
              calls will block too. That's the difference.
                \_ I'm confused. If I select/poll on an fd and select/poll
                   tells me that the fd is ready for reading/writing can't
                   I read/write the fd without it blocking? What is the
                   advantage of making the fd non-blocking?
                   \_ When data can't be read or written from the non-blocking
                      fd, the read/write system calls simply return instead of
                      "blocking" (I thought it was clear from the name
                      "non-blocking"). Why would you want to do that? You can
                      manage multiple I/O streams from a single process
                      without having to use threads. In fact, some people
                      argue that servers that use non-blocking IO tend to be
                      faster than either multithreaded or forking servers.
        \_ It allows var/ dev/ to interlace with the kernel so that daemons
           arent locked.
2025/07/09 [General] UID:1000 Activity:popular
7/9     

You may also be interested in these entries...
2013/4/9-5/18 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Apps, Computer/SW/Languages/Perl] UID:54650 Activity:nil
4/04    Is there a good way to diff 2 files that consist of columns of
        floating point numbers, such that it only tells me if there's a
        difference if the numbers on a given line differ by at least a given
        ratio?  Say, 1%?
        \_ Use Excel.
           1. Open foo.txt in Excel.  It should convert all numbers to cells in
	...
2010/1/22-30 [Computer/HW/Laptop, Computer/SW/OS/OsX] UID:53655 Activity:high
1/22    looking to buy a new development laptop
        needs ssdrive, >6 hr possible batt life, and runs linux reasonably
        Anyone have a recommendation? Thx.
        \_ thinkpad t23 w ssdrive and battery inplace of drive bay
        \_ Ever wondered what RICHARD STALLMAN uses for a laptop?  Well,
           wonder no more!
	...
2009/2/27-3/5 [Computer/Networking] UID:52658 Activity:nil
2/27    I need to buy a wireless router, can u guys help me out?   I need the
        following features:  wireless, G or better, PPTP dial up, PPoE dialup,
        VoIP/SIP register, DDNS, uPnP.
        I am having a such hard time to find a review site which allow me to
        select these features.   Any ideas?  There are a couple model from
        this small company Draytek has these features, I am having the hardest
	...
2008/9/22-29 [Computer/SW/Database] UID:51265 Activity:nil
9/22    In SQL, how can I do something like this:
        SELECT ip_addr, count(*) AS ct FROM table WHERE
          ct > 10 GROUP BY ip_addr?
        I can't get the conditionals to recognize 'ct'
        \_ SELECT ip_addr, count(*) AS ct FROM table HAVING
            count(*) > 10 GROUP BY ip_addr?
	...
2008/6/27-7/14 [Computer/SW/OS/Windows] UID:50396 Activity:nil
6/27    "No extension: Windows XP D-Day arrives Monday, June 30"
        http://tech.yahoo.com/blogs/null/96295
        Among all Windows versions, is XP one of the most sucessful ones?  The
        other one I can think of might be 3.1.
        \_ 2000 was pretty damn good too.
        \_ Win95? It ran the most games. XP seems better than Win2k to me, but
	...
2007/7/17 [Computer/SW/Languages/C_Cplusplus] UID:47312 Activity:nil
7/13    CSUA Life Roster
1 point each for:                                               key:
                significant other (out of county rule applies)   G
                car (Chevy Novas do count)                       C
                housing (dorms DO NOT count)                     H
                own computer running reasonable multi-tasking OS U
	...
2006/10/11-13 [Computer/SW/OS/Windows] UID:44779 Activity:nil
10/11   Are Windows CE, Windows Embedded, and Windows Mobile the same thing?
        They all sound like the Windows version for small devices.  Is it just
        a marketing thing to rename different versions of the same product?
        Thanks.
        \_ Windows CE is the generic term for Windows Mobile, which includes
           "Pocket PC" Edition, and the castrated  "Smartphone" edition.
	...
2005/1/5-7 [Computer/SW/OS/Linux, Computer/SW/OS/Solaris] UID:35563 Activity:very high
1/5     So who else thinks that Linux Kernel Development has gone haywire?
        WTF is up with this movement from an 8k to a 4k stack in the kernel
        that breaks tons of existing drivers that are ported over from
        Windows? And wtf is this crap doing on production distros like
        Fedora? Don't they realize that if you're going to have a large
        install base that you can't arbitrarily do crap like that anymore?
	...
2004/1/2 [Computer/HW/Memory, Computer/HW/CPU] UID:11644 Activity:high
1/1     I got a IBM R40e recently with windows Xp.  I'm wondering what I should
        run (if anything) to stress the computer out.  I heard that if a
        laptop is going to break it's going to break in the first few months of
        use.  Should I worry about this?  I'd much rather ship this back in
        30 days to the seller rather than deal with IBM warranty.  Thanks.
        \_ setiathome
	...
2003/11/20-21 [Computer/SW/OS/Windows] UID:11161 Activity:kinda low
11/20   What kind of Windows and Office were sold on the market between
        2/18/1995 and 12/15/2001? I'm asking because I'm filling out the
        M$ claim form and I don't want to put anything that is wrong, like
        adding WinXP or OfficeXP when it wasn't out in 12/15/01. Thanks.
        \_ I bought Windows 3.1 (retail ~$100), Word/Excel 6 (retail ~$120) both
           in early 1995.
	...
2003/2/27 [Computer/SW/OS/Windows, Computer/SW/Unix] UID:27547 Activity:high
2/26    Win32 question.  I find myself often having to email the full path
        of an MS Word to my co-workers.  Is there an easy way to create a macro
        or something like that to automatically copy the full file path to
        the clipboard?  Currently most of our docs contain the "filename /p"
        field near the top and that works OK.  But that's not appropriate for
        all docs and it's a pain to keep doing an update on it everytime
	...
2002/9/20-21 [Computer/SW/OS/Windows] UID:25961 Activity:kinda low
9/19    I dutifully installed cygwin on win95.  However, some program, like
        tex and tcsh, dumps core or stack.  What is the problem?
        \_ I read somewhere that cygwin on windows 95 doesn't
           work so well
            \_ I wrote somewhere that win95 doesn't work so well, so what
                you read is pretty certainly true.  Umm, I'm not one of
	...
2002/9/2-4 [Computer/HW/CPU, Computer/SW/OS/OsX] UID:25755 Activity:high
9/2     Is there a free X-server for M$-Windows?
        \_ Try XFree86 for cygwin.
             \_ cygwin is really slow on my pentium 133. Will X be slow too?
                I know, it's time to get a new computer, but I'm waiting to
                see what happens with osX.
                \_ Um, what's *not* gonna be slow on a p133?
	...
2001/11/22-24 [Computer/SW/OS/Windows] UID:23077 Activity:high
11/21   http://www.redhat.com/about/presscenter/2001/press_usschools.html
        happy microsoft will write off the 1 billion dollar
        cost off of their federal taxes-day. - danh
        \_ this is quite slick, it's almost as if they are just donating the
            hardware so more people can run their software.
            hardware so more people can run their software, yet they get
	...
2001/8/10-11 [Computer/SW/OS/Windows] UID:22072 Activity:very high
8/9     On Win ME, something happened.  When I copy files, the file name
        gets copied but the whole filename gets capitalized (every letter).
        What happened?  How can I fix this?
        \_ why are you using WinME?  seriously.  at least use Win2k.  Jesus.
           anyway: where were you copying from?  local HD or network share?
           were you copying via Explorer, or were you copying from the command
	...
2001/5/22-23 [Computer/SW/OS/Windows] UID:21317 Activity:very high
5/21    Is it worth buying a new wintel PC right now or should I wait until
        the Pentium4/Athlon prices drop more? I looking into buying a 1GHz
        Pentium3 or similar system, I just went and configured a Dell Dimension
        with 933MHz CPU, 256MB RAM (SDRAM) 32MB GeForce2. No monitor, with
        RedHat Linux, no windows. Came out at like $985
        \_ Sounds about right, you can probably save $100 or $200 if you
	...
Cache (8192 bytes)
tangentsoft.net/wskfaq/articles/io-strategies.html
Winsock 2's major features is that it ties sockets into Win32's unified I/O mechanism. In particular, you can now use overlapped I/O on sockets, which is intrinsically more efficient than the above options. Further confusing the issue are threads, because each of the above mechanisms changes in nature when used with threads. In trying to find an answer to the "which I/O strategy" question, it becomes apparent that there are only a few major kinds of programs, and the successful ones follow the same patterns. From those patterns and practical experience -- some personal and some borrowed -- I have derived the following set of heuristics. None of these heuristics are absolute laws, no one isolated heuristic is sufficient, and the heuristics sometimes conflict. When two heuristics conflict, you need to decide which is more important to your application and ignore the other. However, beware of ignoring a heuristic simply because violating it does not create noticeable consequences for your program. If you get into the habit of ignoring a certain heuristic, it becomes useless. The heuristics are ordered in terms of compatibility, then speed, and finally functionality. Compatibility is first, because if a given I/O strategy won't work on the platforms you need to support, it doesn't matter how fast or functional it is. Speed is next because performance requirements are easy to determine, and often important. Functionality is last, because once you decide the compatibility and speed issues, your choices become much more subjective. Heuristic 1: Narrow your choices by deciding which operating systems you need to support. Your code may also need to be compatible with POSIX-based systems. Although there are a few different network and threading APIs used by the various POSIX-based systems, I'll only talk about BSD sockets and POSIX threads in this article. None of these operating systems have exactly the same set of networking features. You can exploit this fact to rule out I/O strategies that not all of your target operating systems support. Where overlapped I/O calls work on Win9x, it is because the mechanism is emulated at the API layer. If, on the other hand, you stray into functionality that only WinNT 4+ provides, your application will fail on Win9x. One example of this is calling ReadFile() with a socket: this works fine on NT4+, but will fail on Win9x. If you only need scatter/gather I/O support, BSD sockets provides this functionality in the readv() and writev() calls. There is no standard Unix mechanism that provides similar efficiencies to Win32's overlapped I/O. Some Unixes provide the aio_*() family of functions (called asynchronous I/O, but not related to Winsock's asynchronous I/O), but this is not implemented widely at the moment. Although all current Unixes support POSIX threads, there are still a lot of older Unix machines out there with broken, nonstandard or nonexistent threading. You will have to choose a subset of all the Unixes if you want to use the same threading code on all Unixes. You'll definitely be writing different threading code for Windows, since its threading API is completely different. Most of this overhead is a linear function of the number of connections: double the number of connections, and you double the processing time. About the only time you should use select() is for compatibility reasons: it's the only non-blocking I/O strategy that works on all versions of Windows (including CE) and on virtually all POSIX-based systems. If your program only needs to work on non-CE versions of Windows, there are better alternatives. Heuristic 3: Asynchronous sockets work best with low volumes of data. Asynchronous Winsock I/O (WSAAsyncSelect isn't the most efficient I/O strategy, but it's not the least efficient, either. It's a fine way to go in a program that deals with low volumes of data. As the volume of data goes up, the overhead becomes more significant. Heuristic 4: For high-performance servers, prefer overlapped I/O. Of all the various I/O strategies, overlapped I/O has the highest performance. No other I/O strategy comes close to the scalability of overlapped I/O. Heuristic 5: To support a moderate number of connections, consider asynchronous sockets and event objects. If your server only has to support a moderate number of connections -- up to 100 or so -- you may not need overlapped I/O. Overlapped I/O is not easy to program, so if you don't need its efficiencies, you can save yourself a lot of trouble by using a simpler I/O strategy. Programmed correctly, asynchronous sockets are a reasonable choice for a dedicated server supporting a moderate number of connections. The main problem with doing this is that many servers don't have a user interface, and thus no message loop. A server without a UI using asynchronous sockets would have to create an invisible window solely to support its asynchronous sockets. If your program already has a user interface, though, asynchronous sockets can be the least painful way to add a network server feature to it. Another reasonable choice for handling a moderate number of connections is event objects. The main problem you run into with them is that you cannot block on more than 64 event objects at a time. To block on more, you need to create multiple threads, each of which blocks on a subset of the event objects. Before choosing this method, consider that handling 1024 sockets requires 16 threads. Any time you have many more active threads than you have processors in the system, you start causing serious performance problems. One caution: it's very easy to underestimate the number of simultaneous connections you will get on a public Internet server. It may make sense to design for massive scalability even if your estimates don't currently predict thousands of simultaneous clients. Heuristic 6: Low-traffic servers can use most any I/O strategy. For low-traffic servers, there isn't much call to be super-efficient. Perhaps your server just doesn't see high traffic, or perhaps it's running a Windows 95 derivative and so it limited to 10 100 sockets at a time by the OS. Suitable strategies for 1-100 connections are event objects, non-blocking sockets with select(), asynchronous sockets, and threads with blocking sockets. We've covered the first three methods already, so let's consider threads with blocking sockets. This is often the simplest way by far to write a server. You just have a main loop that accepts connections and spins each new connection off to its own thread, where it's handled with blocking sockets. They are efficient, because when a thread blocks, the operating system immediately lets other threads run. Also, synchronous code is more straightforward than equivalent non-synchronous code. There are two main problems with thread-per-connection servers. First, threads often require a lot of synchronization work, which is hard to get right; Second, threads don't scale well at all: as the number of threads increases, the operating system overhead associated with context switches between the threads becomes significant. This method is only suitable for a fairly small number of connections, or a greater number of connections that are mostly idle. Heuristic 7: Do not block inside a user interface thread. This heuristic sounds more like a straightforward rule of Windows programming, but I bring it up because most programs are single-threaded. Heuristic 8: For GUI client programs, prefer asynchronous sockets. Asynchronous sockets were designed from the start to work well with GUI programs. You already have a window loop going, and you already have window management code in the rest of the program. Adding asynchronous network I/O is about as easy as adding a dialog to your program. All of the alternatives require at least one additional thread to handle the networking in order to satisfy the previous heuristic. With asynchronous sockets, you can handle both the network and the UI with a single thread. Since window messages are handled one at a time in the order they arrive, everything is automatically synchronized. Heuristic 9: Threads are rarely helpful in client programs...