| |||||||||||
| |||||||||||
Huge data files - what happened earlier?
When I'm programming a log file analysis in Perl, I'll often "slurp" the whole file into a list which I can then traverse efficiently as many times as I need. If I need to look backwards from some interesting event to see what happened in the immediate lead up to it, I can do so simply by looking at a few previous list elements.
This technique fails if my log file can be so massive that it won't fit into my computer memory, or if doing so produces severe swapping. Fortunately, there are other ways of dealing with this in Perl. * Using a queue, each item that's read from the file and is a potential prior event is pushed (on unshift-ed) onto a list * When an event that triggers a report is found, the prior events in the queue can be examimed and reported on * The queue of prior events is kept trimmed to an appropriate length. I've applied this technique to quotations for private courses in our log files ... when I find a quote request, I want to know the background. Code to add all .html and .php requests to a queue just in case the user calls up a quote: next unless (m!T \S+\.(php|html)!);Code to report when a trigger event is found if (m!GET /net/quote\.html!) { # is it a quote?The code to keep the queue trimmed back is part of the "add to queue" code just above. Here's an example of the results that I get from running my program ... Host: cache2.uk.Ichangedthis.com Quote: /net/quote.html?where=bs32+4tr From: /course/otc.html and this tells me that the person who was looking for a quotation for training in BS32 had previously visited the page of general information about on site training ... Full source code of the example that I'm discussing here is available in our handling huge data resource, and is taught on our Perl for larger projects course. (written 2006-06-15 05:44:14) Associated topics are indexed under P667 - Perl - Handling Huge DataP208 - Perl - Lists
Some other Articles
Discounts and approved supplier listsPerl - turning seconds into days, hours, minutes and seconds Journey planning - Xephos v Transport Direct Much more that the world cup Huge data files - what happened earlier? Great new inventions Self help in Perl Watch your Google profile Very good for woodlice Horse and Python training 1635 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||