[英]perl File::Tail not reading lines from file after certain period
我在理解为什么File :: Tail FAILS不能从具有1000笔事务和自动翻转的始终更新文件中读取行时遇到问题。
它可以正确读取一定程度的内容,但随后会变慢,甚至长时间无法读取日志中的行。 我可以确认当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
}
有人可以帮我理解这一点。 知道此日志文件的更新速度约为每秒10MB或每秒1000个事件。
我应该处理filehandle还是File :: Tail结果以其他更有效的方式处理?
似乎File :: Tail中存在限制。 关于http://www.perlmonks.org/?node_id=387706中讨论的其他更直接的选项(管道,派生,线程,在perl中查找文件的末尾),存在一些建议。
我最喜欢的选择是从管道读取阻塞:
open(TAIL, "tail -F $name|") or die "TAIL : $!";
while (<TAIL>) {
test_and_do_something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.