현재 추출 로그가 필요한 스크립트가 있습니다. 다음은 Perl 코드 단편입니다. 스크립트는 모든 서버 폴더를 탐색하고 필요한 정보를 grep합니다. 문제는 로그 수가 너무 많아지면 스크립트를 완료하는 데 시간이 오래 걸릴 수 있습니다. 병목 목은 다음과 같습니다.이 Perl 스크립트의 grep 속도를 높이는 방법
이 작업 속도를 높이려면 어떤 방법이 있을까요? 스크립트는 CPU 및 8G 메모리 당 8 개의 코어가있는 서버에서 실행 중이므로 이러한 리소스를 사용할 수있는 방법이 있습니까?
my $grep = ($leaflog_zipped) ? "zgrep" : "grep" ;
my %leaf_info;
my @stage = ("STAGE1", "STAGE1", "STAGE3");
foreach my $leaf_dir (@leaf_dir_list){
my $grep_path = $log_root_dir . "/$leaf_dir/*" ;
foreach my $current_stage (@stage){
my @leaf_lines;
@leaf_lines = qx($grep -l "stagename = $current_stage" $grep_path| xargs $grep "Keywords"); ## how to improve the grep speed?
foreach (@leaf_lines){
if(...){
$leaf_info{$current_stage}{xxx} = xxxx;
}
}
}
}