Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Untangling Log Files

by jettero (Monsignor)
on Feb 08, 2007 at 12:11 UTC ( [id://598983]=note: print w/replies, xml ) Need Help??


in reply to Untangling Log Files

I like this problem.

Personally, I would keep a hash of filehandles, but close one at random if there are too many open (hoping the pids are kinda grouped together in the logfile).

use strict; my %handles = (); sub open_one { my $pid = shift; return $handles{$pid} if exists $handles{$pid}; while( (my @k = keys %handles) > $threshold ) { my $toclose = $k[ int rand @k ]; close $handles{$toclose}; delete $handles{$toclose}; } open $handles{$pid}, ">>", "logfile-$pid.log" or die "hrm: $!"; return $handles{$pid}; } sub scanner { # ... boring things if( m/something/ ) { my $pid = $1; my $fh = &open_one($pid); print $fh $stuff; } # boring things... }

-Paul

Replies are listed 'Best First'.
Re^2: Untangling Log Files
by Util (Priest) on Feb 08, 2007 at 15:53 UTC

    ++jettero

    FYI, the core module FileCache will automate the close/re-open of filehandles.

Re^2: Untangling Log Files
by loris (Hermit) on Feb 09, 2007 at 07:23 UTC

    I like the problem, too, and I certainly like your solution. Randomly closing file handles seems like an nice way of making it scalable.

    Thanks,

    loris


    "It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ." (from "Slow Loris" by Alexis Deacon)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-24 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found