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.

The start of some sanity?


In reply to Re: Consumes memory then crashs by BrowserUk
in thread Consumes memory then crashs by allhellno

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.