|The stupid question is the question not asked|
Re: Consumes memory then crashsby BrowserUk (Pope)
|on Mar 24, 2012 at 12:51 UTC||Need Help??|
In an attempt to make things faster I added threading, but now when I run the script it quickly shoots up to 4gb memory then crashes.
You are attempting to run 16382 threads concurrently. 4GB / 16382 = 256k. Perl's threads (and threads in most languages) require more than 256k each. Ergo, what you are trying to do won't work.
Now look at it another way. Your stated goal is "an attempt to make things faster".
Does your machine have 16,000 cores?
If not, then using 16382 threads is not going to speed things up.
Rather than each thread starting one lookup(), and running it until completes and then starting the next one; each thread is doing a bit of one, then switching to another and doing a bit; then switching to another and doing a bit, ...
All that switching costs time and cpu. Time and cpu that can no longer be used for solving the original problem. Ergo, it takes longer!
Judicious use of threads can speed up some cpu-intensive tasks; but throwing 1000s of threads at a problem is never going to help unless you happen to have around $10,000,000 with which to purchase a machine that has thousands of cores.
If you want help in improving the performance of your code, show us the unthreaded version(*) and tell us how long it takes and how much faster you would like it to be. Then, if once we've checked that your task cannot be sped up by using a better algorithm, we might suggest a threading solution.
(*)But do ensure that your code is readable and compiles clean with use strict and warnings. Your current code is barely intelligible and has obviously had strict and my slapped into it to try placate this place. It doesn't work and it doesn't help -- you or us.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.