#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    BCN
    Posts
    84
    Rep Power
    13

    CPU usage in select based server.


    Hi all,

    I'm programming a kind-of-messenger server based on winsock and select to avoid blocking.
    What I do is the classica:
    while(1){
    select(0,read,write,exp); //0 Win32
    bla bla processing.
    }
    I've seen that when running the program consumes almost 50-60 % of CPU, the rest goes to CSRSS.exe. Is it normal? And, what is this CSRSS service?

    Thanks.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    12
    Rep Power
    0
    select in a tight loop will consume high CPU on windows, put a small sleep command in there or use the asynch model of WinSock if CPU time is a real issue.

    As a general rule-of-thumb, using select() on windows is less optimal than message-pump based asynch system that WinSock has (sends a message when a requested event occured on a socket, instead of polling). On many systems select is implemented in terms on poll and can be quite CPU intensive.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    BCN
    Posts
    84
    Rep Power
    13
    Hi,

    Thanks. I don't really know if cpu usage will be an issue or not. I'll try the sleep approach. Anyway, do you know any place where I can find examples of the Winsock event approach? I confess complete ignorance about that!

IMN logo majestic logo threadwatch logo seochat tools logo