为什么会提高 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
那么,
- 为什么
plackup
在前 3 个请求中提出? 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
I have this simple PSGI application (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 ]];
};
I was requested the above 1000 times and got increased memory usage. Depending on how was started the server, got:
plackup
- memory usage is raising at first 3 requests and remain constant for the next 997 requestsplackup -r
- memory usage is randomly raising (not at every request) by 4k.starman
- like above, the memory usage is randomly raising by 4k, but with slower rate
The question is:
- WHY is raising the memory usage ? Where is the leak, and how achieve constant memory usage (especially on starman), because i don't want run out of memory at long run. (OK, it is possible define for example --max-requests 100), but it is not an answer for the memory usage.
- or - what is wrong in my example?
If anyone want test this too - here is my script for the fetching:
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;
}
My results:
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
So,
- why
plackup
raising in first 3 requests? plackup -r
- 4k increase (see last lines) - at the beginning much morestarman
- raising too, but with default 5 workers in slower rate (3280->3912)
Versions:
# 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 miyagava 的评论,答案是:
谢谢。
Based on miyagava's comments the answer is:
thanx.
你用的是最新版本吗?我无法重现你的输出。
使用“plackup”:
使用“plackup -r”:
使用“starman”:
版本:
Perl:5.12.1 和5.12.3
普拉克:0.9979
星人:0.2010
Did you use the latest version? I cannot reproduce your output.
With "plackup":
With "plackup -r":
With "starman":
Versions:
Perl: 5.12.1 & 5.12.3
Plack: 0.9979
Starman: 0.2010