Well, obviously 16GB are not enough when you're loading 62GB of data into memory. This means lots of swapping. Start your program, and observe the progress with top.

Let's say your program fills 16GB with data from the disk. There are 46GB more. So it writes the first 16GB to swap. Then, you probably run out of swap space as well (which is usually of the same size as RAM), so the system has to allocate more swap. Phew.

When the processing loop starts, it starts with the first lines, which it needs to read from disk again (from swap in this case). But since your RAM is already full, it now swaps out the last records. While the loop continues, the first lines will be written to swap again. So you have a cyclic re-reading and writing, which is the worst which can happen to swap (or cache).

You should read and process record by record, even if that means you have to go through your original file twice.

Physically reading from Disk is slow. SSDs are faster, but still significantly slower than RAM.


In reply to Re^3: efficient perl code to count, rank by haj
in thread efficient perl code to count, rank by Perl_Noob2021

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.