Hi,
I would like to ask one question related to Tie::File. I'm using it on
ActivePerl in Windows -platform and try to write XML-based event-log from
my application.
With tied filehandle it's easy to add lines in the middle of the file and also
remove lines etc. And also the wellformedness of the logfile can be quaranteed.
The problem is that for some reason the memory consumption of the logging feature
starts to increase steadily and if the application is running for a long time and
there is much to log some problems will occur.
I have started to suspect that the memory consumption has something to do with
splice, when lines are spliced in the file. Is this a problem only on Windows platform and
have you seen such behaviour?
Of course there's xml-writing modules available, but since this is custom log and some
special functionality is needed, this approach would have been flexible.
Here's a small script, which should demostrate the problem (when the script is running
the memory consumption of perl.exe can be followed from task-manager):
There is some sleep just for not to eat memory too quickly
use Tie::File;
my $row = 0;
$sleepCnt = 0;
tie @file, 'Tie::File', 'test.xml' or die "\n\n-> failed to tie file\n\n";
splice @file, $row++, 0, "<TEST>";
splice @file, $row, 0, "</TEST>";
while(1) {
splice @file, $row++, 0, "<TAG id=\"testi tag\">Some added text $row</TAG>";
if(++$sleepCnt == 100) {
$sleepCnt = 0;
print "\nSleeping...";
sleep(1);
}
}
untie(@file);
I would like to ask one question related to Tie::File. I'm using it on
ActivePerl in Windows -platform and try to write XML-based event-log from
my application.
With tied filehandle it's easy to add lines in the middle of the file and also
remove lines etc. And also the wellformedness of the logfile can be quaranteed.
The problem is that for some reason the memory consumption of the logging feature
starts to increase steadily and if the application is running for a long time and
there is much to log some problems will occur.
I have started to suspect that the memory consumption has something to do with
splice, when lines are spliced in the file. Is this a problem only on Windows platform and
have you seen such behaviour?
Of course there's xml-writing modules available, but since this is custom log and some
special functionality is needed, this approach would have been flexible.
Here's a small script, which should demostrate the problem (when the script is running
the memory consumption of perl.exe can be followed from task-manager):
There is some sleep just for not to eat memory too quickly
use Tie::File;
my $row = 0;
$sleepCnt = 0;
tie @file, 'Tie::File', 'test.xml' or die "\n\n-> failed to tie file\n\n";
splice @file, $row++, 0, "<TEST>";
splice @file, $row, 0, "</TEST>";
while(1) {
splice @file, $row++, 0, "<TAG id=\"testi tag\">Some added text $row</TAG>";
if(++$sleepCnt == 100) {
$sleepCnt = 0;
print "\nSleeping...";
sleep(1);
}
}
untie(@file);