为什么提高plackup(或starman)的内存使用率?
|
我有这个简单的PSGI应用程序(app.psgi)。
use strict;
use warnings;
my $app = sub {
my $mem = `ps -o rss= -p $$`;
$mem =~ s/^\\s*|\\s*$//gs;
return [ 200, [ \'Content-Type\' => \'text/text\' ], [ $mem ]];
};
我被要求上述1000次,并增加了内存使用量。根据服务器的启动方式,得到:
plackup
-前3个请求的内存使用量在增加,接下来的997个请求则保持不变
plackup -r
-内存使用量随机提高(并非在每次请求时都提高4k)。
starman
-与上面一样,内存使用量随机增加4k,但速率较慢
问题是:
为什么要提高内存使用率?泄漏在哪里,以及如何实现恒定的内存使用率(尤其是在starman上),因为我不希望长期运行耗尽内存。 (好的,可以定义--max-requests 100),但这不是内存使用的答案。
或-在我的示例中有什么问题?
如果有人也想对此进行测试-这是我的提取脚本:
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => \'http://localhost:5000\');
my $old_mem = 0;
print \"req#\\tmem\\n\";
foreach my $i (1..1000) {
my $res = $ua->request($req);
(my $mem = $res->content) =~ s/\\D//g;
next if( $mem == $old_mem );
print \"$i\\t$mem\\n\";
$old_mem = $mem;
}
我的结果:
plackup plackup -r starman
req# mem req# mem req# mem
1 7780 1 3924 1 3280
2 7800 2 4296 5 3728
3 7804 3 4304 8 3280
... ...
... deleted ... deleted
... ...
839 4596 994 3912
866 4600 998 3908
962 4604 1000 3912
所以,
为什么在前三个请求中加1?
plackup -r
-增加4k(请参阅最后几行)-开始时更多
starman
-也有加注,但默认情况下有5个工人的速度降低(3280-> 3912)
版本:
# cpanm Plack Starman
Plack is up to date. (0.9979)
Starman is up to date. (0.2010)
# perl -v
This is perl 5, version 12, subversion 3 (v5.12.3) built for darwin-thread-multi-2level
没有找到相关结果
已邀请:
2 个回复
街茬
蜗仓馈
使用\“ plackup -r \”:
使用“ starman”:
版本: Perl:5.12.1和5.12.3 松紧度:0.9979 Starman:0.2010