From: John Carter Date: 2008-03-27T04:53:31+09:00 Subject: Re: "loop do IO.select([io], nil, nil)" eats 95% of CPU, any other way? --Boundary_(ID_+1vf8IetHIdCYwNiKlClqA) Content-type: TEXT/PLAIN; format=flowed; charset=X-UNKNOWN Content-transfer-encoding: QUOTED-PRINTABLE On Thu, 27 Mar 2008, I=C3=B1aki Baz Castillo wrote: > Hi, which is the most efficient way of receiving and processing dat= a =66rom a network socket? I use GServer in this common way: -------------- class MyServer < GServer def serve(io) loop do if IO.select([io], nil, nil) .... -------------- A "top" says to me that Ruby is eating more than 90% of CPU and there is no connections yet... :( Any other suggestion? Hmm.From the "man select" page... timeout is an upper bound on the amount of time elapsed before select() returns. It may be zero, causing select() to return immediately. (This is useful for polling.) If timeout is NU= LL (no timeout), select() can block indefinitely. ri IO.select IO.select(read_array [, write_array [, error_array [, timeout]]] ) =3D> array or nil My guess is you have one too few nil's in there and the default timeo= ut is 0 not nil. If you are on linux say... "man strace" to discover why linux is such a great place to develop on.... you can _always_ find out what is really going on with any program. As a little side comment... You can _always_ take a program written around a select & state machine and make it multi-threaded doing blocking I/O or conversely refactor a multi-threaded app into a selec= t based state machine. Choose whichever is easiest / cleanest for you. John Carter Phone : (64)(3) 358 6639 Tait Electronics Fax : (64)(3) 359 4632 PO Box 1645 Christchurch Email : john.carter@tait.co.n= z New Zealand --Boundary_(ID_+1vf8IetHIdCYwNiKlClqA)--