Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
When dealing with flat files this large, a big part of the game is managing the disk head motion. If the disk seeks elsewhere, getting it back to the right place in your file (so that you can keep reading) is relatively expensive. Given that you're on a box that's sharing the disk with lots of processes, the read head isn't something that you can control, but you can influence it. One trick is to read in big chunks (but not so big that you risk having to page, which just causes more disk activity). You're on the right track by thinking 4K chunks, but I'd try something larger, like 8K, 16K, or more. (Use sysread() rather than read(), since the latter will actually use a sequence of OS reads if you try to read a large chunk. You can see this for yourself using ktrace (or equivalent).) By using large reads, you reduce the chance that some other process will sneak in and move the disk head.

Matching in huge files demonstrates a trick for scanning for a pattern through a sliding window in a large file, using sysread() to pull in 8K chunks. You might be able to adapt it to your problem.

In reply to Re: speeding up a file-based text search by dws
in thread speeding up a file-based text search by perrin

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (5)
    As of 2020-10-27 19:11 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (257 votes). Check out past polls.