in reply to Use thread with good care, but definitely keep using it
The principle should be: only to create a new thread, when you see it as the best way to resolve blocking. As for socket application, most of the time, you can simply resolve blocking issues by using IO::Select.
Will there be a performance issue, because using less thread? No, on a single processor computer, threading does not improve performance at all, and even on multi-processor computer, threading only improves performance when you have the right number of threads. Keep in mind, at the most, there will only be one active thread really running, on any given processor, at any given time.
That's fine if the only thing your code is blocking on is client input but if your client's request translates into disk or database I/O, IO::Select won't allow these to overlap. Threads will. Also, if a client request turns into a long cpu-bound calculation, using threads will allow progress to be made (and possibly reported back to the client to show activity) on all outstanding requests simultaneously. Without threads, your clients would be processed serially and think nothing is happening.
Threading is just another tool you can use to solve performance problems. There's no one tool that solves all problems. Before choosing a tool, make sure you understand the tool, its limits, and the problem you're using it on. Make sure the tool fits the situation.
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Use thread with good care, but definitely keep using it
by pg (Canon) on Mar 14, 2003 at 02:09 UTC |