Perl_Love has asked for the wisdom of the Perl Monks concerning the following question:
I wrote a few programs, do not know why the memory has been increased from 20M has been added to xxG.
The number of processes to keep about 100.
Please help me, thank you!
My environment:
CentOS7
Perl 5.20.3
#!/usr/bin/perl -w # fork.pl $SIG{INT}=\&INT_EXIT; use IO::Socket::SSL; use Mojo::Asset; use Mojo::Asset::File; use Mojo::Asset::Memory; use Mojo::Base; use Mojo::Content; use Mojo::Content::MultiPart; use Mojo::Content::Single; use Mojo::Cookie; use Mojo::Cookie::Request; use Mojo::EventEmitter; use Mojo::Exception; use Mojo::IOLoop; use Mojo::IOLoop::Client; use Mojo::IOLoop::Delay; use Mojo::IOLoop::Server; use Mojo::IOLoop::Stream; use Mojo::JSON; use Mojo::Loader; use Mojo::Message; use Mojo::Parameters; use Mojo::Path; use Mojo::Reactor; use Mojo::Reactor::Poll; use Mojo::Server; use Mojo::Server::Daemon; use Mojo::Transaction; use Mojo::Transaction::HTTP; use Mojo::Transaction::WebSocket; use Mojo::URL; use Mojo::UserAgent; use Mojo::UserAgent::CookieJar; use Mojo::UserAgent::Proxy; use Mojo::UserAgent::Server; use Mojo::UserAgent::Transactor; use Mojo::Util; use Mojo::WebSocket; use File::Find; use Parallel::ForkManager; $|=1; my %ID; my $dir='/home/root/Perl/zhubo/AccountID'; my $fork; my %Header; my $ua; &Config; &Header; &Mojo_UA; my $pm=new Parallel::ForkManager($fork); sub Config{ open(F,"conf.json") or die; my @conf=<F>; close F; chomp @conf; my $json=join('',@conf); $json_conf=Mojo::JSON::decode_json($json); $fork=$json_conf->{'fork'}; } sub Header{ my @header=<headers/*>; foreach my $H(@header){ next unless($H=~m/\.header$/); my $hn; $hn=$1 if($H=~m/.*\/(.*?)\.header$/); open(H,$H) or die; while(my $h=<H>){ chomp $h; my @H=split('=>',$h); $Header{$hn}{'header'}{$H[0]}=$H[1]; } close H; } } sub Mojo_UA{ $ua=Mojo::UserAgent->new; $ua=$ua->connect_timeout($json_conf->{'connect_timeout'}); $ua=$ua->inactivity_timeout($json_conf->{'inactivity_timeout'}); $ua=$ua->max_redirects($json_conf->{'max_redirects'}); } while(1){ File::Find::find(\&wanted,$dir); } $pm->wait_all_children; sub wanted { if(-f $File::Find::name){ if($File::Find::name=~m/\.next$/){ if(exists $ID{$_}){ my $o=$File::Find::name; $o=~s/\.next$/.bak/; unlink($o); $o=~s/\.bak$//; unlink($o); delete $ID{$_}; } } if($File::Find::name=~m/\.bak$/){ my $gh=$_; my $e=$gh; $gh=~s/\.bak$//; my $f=$_; $f=~s/\.bak$//; unless(exists $ID{$f}){ my $fuck=&AccountID($f); if($fuck ne 'NULL'){ $ID{$f}=1; my $pid=$pm->start and next; system("/home/root/Perl/zhubo/ZhuBo.pl $f"); delete $ID{$f}; rename($e,$gh); $pm->finish; } undef $fuck; } } else{ my $r=$File::Find::name.'.bak'; rename($File::Find::name,$r); unless(exists $ID{$_}){ my $fuck=&AccountID($_); if($fuck ne 'NULL'){ $ID{$_}=1; my $pid=$pm->start and next; system("/home/root/Perl/zhubo/ZhuBo.pl $_"); my $e=$r; $e=~s/\.bak$//; delete $ID{$_}; rename($r,$e); $pm->finish; } undef $fuck; } } } } sub AccountID{ my $accountId=shift; my $url='https://taobaolive.taobao.com/room/index.htm?userId='.$acco +untId; my $res; while(1){ my $eval=eval{ $res=$ua->get($url=>{%{$Header{'item_list'}{'header'}}})->result +; }; last if($eval); } if($res->is_success){ my $body=$res->body; if($body=~m/var liveDetail \= (.*?) \|\| \{\}\;/s){ my $liveDetail=$1; unless($liveDetail=~m/\}$/){ undef $res; undef $body; undef $liveDetail; return 'NULL'; } my $json_hash=Mojo::JSON::decode_json($liveDetail); if(exists $json_hash->{'liveId'}){ if($json_hash->{'liveId'} ne '0'){ my $liveId=$json_hash->{'liveId'}; undef $json_hash; undef $res; undef $body; undef $liveDetail; return $liveId; } else{ undef $json_hash; undef $res; undef $body; undef $liveDetail; return 'NULL'; } } else{ undef $json_hash; undef $res; undef $body; undef $liveDetail; return 'NULL'; } } else{ &AccountID($accountId); } } else{ &AccountID($accountId); } } sub INT_EXIT{ exit; }
|
|---|