Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: speeding up a file-based text search

by dws (Chancellor)
on May 06, 2003 at 18:14 UTC ( #255973=note: print w/replies, xml ) Need Help??


in reply to speeding up a file-based text search

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.

  • Comment on Re: speeding up a file-based text search

Replies are listed 'Best First'.
Re: Re: speeding up a file-based text search
by perrin (Chancellor) on May 07, 2003 at 19:52 UTC
    I tried this, but unfortunately I only got about a 10% performance gain. I do need to know the line that matched, so I used the chunked stuff to qualify chunks and then check them line by line if they match. This lazy way of doing things was quick to try out, but I would probably get better performance if I actually take the time to write code that can extract the line from a chunk based on the position of a match. I'll try that next.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://255973]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-10-27 06:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (256 votes). Check out past polls.

    Notices?