![]() |
![]()
| ![]() |
![]()
NAMEPlack::Middleware::MemoryUsage - for measuring process memory SYNOPSISuse Plack::Builder; builder { enable "MemoryUsage", callback => sub { my ($env, $res, $before, $after, $diff) = @_; my $worst_count = 5; for my $pkg (sort { $diff->{$b} <=> $diff->{$a} } keys %$diff) { warn sprintf("%-32s %8d = %8d - %8d [KB]\n", $pkg, $diff->{$pkg}/1024, $after->{$pkg}/1024, $before->{$pkg}/1024, ); last if --$worst_count <= 0; } }; $app; }; # 1st diff after before MemoryEater 36864 = 36873 - 9 [KB] B::Size2::Terse 191 = 645 - 453 [KB] B::AV 21 = 37 - 16 [KB] B::HV 4 = 18 - 14 [KB] B::NV 0 = 8 - 8 [KB] # 2nd (grow up 18432 KB) MemoryEater 18432 = 55305 - 36873 [KB] Plack::Middleware::MemoryUsage 0 = 13 - 13 [KB] IO::Socket::INET 0 = 270 - 270 [KB] Apache2::Status 0 = 26 - 26 [KB] Symbol 0 = 40 - 40 [KB] DESCRIPTIONPlack::Middleware::MemoryUsage is middleware for measuring process memory. Enabling Plack::Middleware::MemoryUsage causes huge performance penalty. So I HIGHLY RECOMMEND to enable this middleware only on development env or not processing every request on production using Plack::Middleware::Conditional. builder { ## with 1/3 probability enable_if { int(rand(3)) == 0 } "MemoryUsage", ## only exists X-Memory-Usage request header # enable_if { exists $_[0]->{HTTP_X_MEMORY_USAGE} } "MemoryUsage", callback => sub { ... }; $app; }; CONFIGURATION
AUTHORHIROSE Masaaki <hirose31 _at_ gmail.com> REPOSITORY<https://github.com/hirose31/plack-middleware-memoryusage> git clone git://github.com/hirose31/plack-middleware-memoryusage.git patches and collaborators are welcome. SEE ALSOPlack::Middleware LICENSEThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|