On Jan 15, 9:23 am, [EMAIL PROTECTED] (Zentara) wrote: > On Mon, 14 Jan 2008 20:26:05 -0800 (PST), [EMAIL PROTECTED] > > > > (Turner) wrote: > >On Jan 14, 4:07 pm, [EMAIL PROTECTED] (Robert Leibl) wrote: > >> Turner wrote: > >> > Hello Perl gurus, > > >> > I'm currently in the process of writing a chat server in Perl. > >> > Everything is all hunky-dory--it parses commands as it should, and is, > >> > of course, quite satisfying. Except for one thing, and that is that it > >> > cannot handle multiple clients at once, which, needless to say, is > >> > kind of useful for a chat program, isn't it? So I've been following > >> > the discussion online of Threads vs. forking vs. non-blocking IO, and > >> > I've decided to try threads, which is neat because this is the first > >> > thing I've ever done with threading. However, my excitement has been > >> > somewhat dampened by the fact that it does not work. It can still > >> > happily handle a single client--no complaints there. However, it can > >> > still ONLY handle a single client. There's probably a hole in my > >> > understanding of threads (e.g., I don't entirely understand what > >> > join() and detach() DO...). Below is the relevant server code, and I > >> > was hoping some kind soul could look at it, suppress his laughter at > >> > my naive code and point me in the right direction. > > >> [...] > > >> If you just want to handle multiple clients, you may want to look at the > >> select() function. > >> (See the bottom part in the perldoc-umentation. The one with RBITS, > >> WBITS, ... or herehttp://www.perlfect.com/articles/select.shtml) > > >Thank you, that was exactly what I needed. It works beautifully now. > >Thanks. > > Hi, would you mind posting the complete working code? > I would like to test it > for good functionality and no memory leaks with repeated > connects/disconnects. > > Thanks, zentara > > -- > I'm not really a human, but I play one on earth.http://zentara.net/japh.html
I would normally happily do so, but this program is part of an application to a programming job, so I'm being cautious as to how much and what kind of help I get, and I think posting it here for you to debug would be kind of cheating. But I really appreciate the offer, and in other circumstances, I'd certainly oblige. However, I think general questions are legit. And with that in mind, I have some questions about IO::Select. While my server runs as it should, it eats up a ton of CPU cycles; when it's running, my computer slows noticably. Windows Task Manager shows it taking about 50% of the CPU. This is obscene. I'm pretty sure it shouldn't have that big a footprint. I've done some cursory profiling with -d:DProf and the problem seems to center around IO::Select::select--in one run of about a minute or so, there were 280395 calls to IO::Select::select. I think this is probably where most of the performance pit is. Any ideas on how to fix it? Thanks, Turner -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/