Speed up with threads

Jonathan Hogg jonathan at onegoodidea.com
Mon Aug 5 06:47:54 EDT 2002


On 5/8/2002 11:27, in article jqjsku0kld44qvsqvqmqlcbdo0pkc01vmt at 4ax.com,
"Rhymes" <raims at dot.com> wrote:

> Thank you so much. Your solution works. However it is as fast as my
> initial multithreading version... Is it a Win2K limitation?

To be honest, the only thing wrong with your original implementation was
that it created and destroyed a lot of "one-shot" threads. If that turns out
to be cheap on your OS, then you won't notice anyway. The Worker Threads
pattern simply re-uses existing threads.

Both solutions end up with 'n' threads running simultaneously trying to
connect to ports. So I'd expect the difference to come down to how expensive
thread creation is on your platform vs the time spent doing the scanning.

The Worker Threads pattern is a good one though so it's worth learning. It's
especially useful when you're concerned about latency, which is why it tends
to be popular in network servers. When a connection comes in you want to get
to work on it straight away, so if you have a pre-created thread you can
just pass it the connection and get going instead of waiting to create a new
thread.

Jonathan




More information about the Python-list mailing list