What's happening to you is a phenomenon known as thrashing. Virtual memory page faults and the corresponding page-I/O is eating you alive. This always happens abruptly: "hitting the wall." Performance goes straight from a linear slow-down to an exponential one. And the only thing that you can do about it is either to buy more RAM or to redesign your algorithm.

Hash tables are purposely designed to widely-distribute their memory addresses and this works just fine as long as "memory is free." But when thrashing begins to occur it makes it worse: almost every single hash "hit" might cause a page fault.

One good alternative strategy would be to select the URLs out of the file and write them to an external file, which you then sort using an on-disk sorting command. Then, read the sorted file: each occurrence of the same name will now be consecutive – simply note when the value changes. This strategy places an explicit disk-file in place of the virtual-memory disk backing-store, and it will produce predictable performance regardless of data volume. It's a strategy that's as old as punched cards, and it still works.


In reply to Re: Hash Search is VERY slow by Anonymous Monk
in thread Hash Search is VERY slow by rtjensen

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.