简体   繁体   English

perl File :: Tail一定时间后未从文件中读取行

[英]perl File::Tail not reading lines from file after certain period

I am having issues understanding why File::Tail FAILS to read the lines from an always updating file with 1000s of transactions, and automatic rollover . 我在理解为什么File :: Tail FAILS不能从具有1000笔事务和自动翻转的始终更新文件中读取行时遇到问题。

It read to a certain extend correctly, but then later slows down, and for a long period even not able to read the lines in the logs. 它可以正确读取一定程度的内容,但随后会变慢,甚至长时间无法读取日志中的行。 I can confirm that the actual log are being populated as when file::tail shows nothing. 我可以确认当file :: tail不显示任何内容时,正在填充实际的日志。

my $file = File::Tail->new(name=>"$name",
                           tail => 1000,
                           maxinterval=>1,
                           interval=>1,
                           adjustafter=>5,resetafter=>1, 
                           ignore_nonexistant=>1,
                           maxbuf=>32768);

while (defined(my $line=$file->read)) {
    #my $line=$file->read;
    my $xml_string  = "";

    #### Read only one event per line and deal with the XML.
    #### If the log entry is not a SLIM log, I will ignore it.
    if ($line =~ /(\<slim\-log\>.*\<\/slim\-log\>)/) {
        do_something
    } else {
        not_working for some reason
    }

Can someone please help me understand this. 有人可以帮我理解这一点。 Know that this log file is updated at almost 10MB per second or 1000 events per second for an approximation. 知道此日志文件的更新速度约为每秒10MB或每秒1000个事件。

Should I be handing the filehandle or the File::Tail results some other more efficient way? 我应该处理filehandle还是File :: Tail结果以其他更有效的方式处理?

Seems like there's limitations in File::Tail. 似乎File :: Tail中存在限制。 There's some suggestions around other more direct options (a pipe, a fork, a thread, seeking to the end of the file in perl) discussed in http://www.perlmonks.org/?node_id=387706 . 关于http://www.perlmonks.org/?node_id=387706中讨论的其他更直接的选项(管道,派生,线程,在perl中查找文件的末尾),存在一些建议。

My favorite pick is the blocking read from a pipe: 我最喜欢的选择是从管道读取阻塞:

open(TAIL, "tail -F $name|") or die "TAIL : $!";
while (<TAIL>) {
        test_and_do_something
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM