4 번째 수정본 (4 번째 수정본부터 4 번째 수정본까지의 변경사항)
(소소한 수정 ) (두 수정본의 내용이 동일하거나, 수정본을 비교할 수 없음.)
Archive::Zip
1. 반복적인 read() 호출과 extract() 관련 버그
[스무번째 날: Gearman 사용 사례 -- 펄 크리스마스 달력 #2013] 기사를 작성하는 도중에 발견.
하나의 Archive::Zip 오브젝트에 대하여 read
메쏘드를 호출하여 압축 파일을 읽을 때마다 점점 더 메모리를 차지하게 되고
extractTree
또는 extractMemberWithoutMethods
메쏘드를 호출하여 내용을 추출할 때 점점 더 많은 시간을 소모하게 된다.
my $zip = Archive::Zip->new ();
$zip ->read ($file ) == AZ_OK;
for my $num ( 1 .. 20000 ) {
$zip ->extractMemberWithoutPaths($member );
}
전체 코드는 길어서 접음
!/ usr / bin/env perl
use strict ;
use warnings ;
use Archive::Zip qw/ :ERROR_CODES :CONSTANTS / ;
use Time::HiRes qw/ gettimeofday tv_interval / ;
use Memory::Usage;
my $member = ' LIST.txt ' ;
my $file = ' /home/gypark/temp/gearman/data/00001.zip ' ;
my $mu = Memory::Usage->new ;
my $zip = Archive::Zip->new ();
my $time_read = 0 ;
my $time_extract = 0 ;
my $t0 ;
my $elapsed ;
die ' read erorr ' unless ( $zip ->read ($file ) == AZ_OK );
$mu ->record(' before loop ' );
for my $num ( 1 .. 20000 ) {
$t0 = [ gettimeofday ];
$zip ->extractMemberWithoutPaths($member );
$elapsed = tv_interval($t0 );
$time_extract += $elapsed ;
if ( $num % 1000 == 0 ) {
printf (" %d , %.6f, %.6f \n " , $num , $time_read /1000 , $time_extract /1000 );
$time_read = 0 ;
$time_extract = 0 ;
}
unlink $member or die " unlink: $! " ;
}
$mu ->record(' after loop ' );
$mu ->dump ();
결과:
1000, 0.000000, 0.000742 <-- 매 천 번 반복하는 동안 read()와 extract..()의 평균 실행 시간
2000, 0.000000, 0.000750
3000, 0.000000, 0.000746
4000, 0.000000, 0.000768
5000, 0.000000, 0.000772
6000, 0.000000, 0.000771
7000, 0.000000, 0.000756
8000, 0.000000, 0.000649
9000, 0.000000, 0.000626
10000, 0.000000, 0.000754
11000, 0.000000, 0.000764
12000, 0.000000, 0.000764
13000, 0.000000, 0.000583
14000, 0.000000, 0.000658
15000, 0.000000, 0.000495
16000, 0.000000, 0.000514
17000, 0.000000, 0.000608
18000, 0.000000, 0.000589
19000, 0.000000, 0.000708
20000, 0.000000, 0.000760
time vsz ( diff) rss ( diff) shared ( diff) code ( diff) data ( diff)
0 94868 ( 94868) 8920 ( 8920) 2068 ( 2068) 1412 ( 1412) 7136 ( 7136) before loop
14 94868 ( 0) 8968 ( 48) 2096 ( 28) 1412 ( 0) 7136 ( 0) after loop
read()는 처음 한 번만 하고 루프 내에서는 실행하지 않았으니 시간이 0.0이고
extractM emberWithoutPaths()의 평균 수행 시간은 루프를 천 번 반복하는 동안 합산한 후 1000으로 나눈 값이다. 즉 처음 천 번 루프를 도는 동안 이 함수를 한번 호출할 때 수행 시간은 평균 0.742밀리초였고, 그 다음 천 번 루프를 도는 동안은 평균 0.750밀리초...이런 식. 위 결과를 보면 '''처음 천 번 돌 때나 마지막 스무 번째 천 번 돌 때나 평균시간은 항상 0.8밀리초 이내를 유지한다.
마지막 두 줄은 루프를 돌기 전과 후의 사용 메모리 변화인데, data size 에 전혀 변화가 없다.
2. 기타 & Comments
컴퓨터분류