Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-19 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found