in reply to Consumes memory then crashs
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".
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Consumes memory then crashs
by allhellno (Novice) on Mar 24, 2012 at 13:20 UTC | |
by BrowserUk (Patriarch) on Mar 24, 2012 at 14:54 UTC | |
by allhellno (Novice) on Mar 24, 2012 at 15:25 UTC | |
by BrowserUk (Patriarch) on Mar 24, 2012 at 15:40 UTC | |
by mbethke (Hermit) on Mar 24, 2012 at 19:35 UTC | |
| |
by allhellno (Novice) on Mar 24, 2012 at 16:00 UTC | |
| |
by Corion (Patriarch) on Mar 24, 2012 at 15:27 UTC |