Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add META.yml, update documentation, add a couple of tests #6

Merged
merged 4 commits into from Nov 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions META.yml
@@ -0,0 +1,27 @@
---
abstract: 'Terminate PSGI server processes if they grow too large'
author:
- 'Audrey Tang <cpan@audreyt.org>'
build_requires:
Module::Package::Au: '0'
ExtUtils::MakeMaker: '0'
Test::More: 0
dynamic_config: 0
license: unrestricted
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Plack-Middleware-SizeLimit
module_name: Plack::Middleware::SizeLimit
no_index:
directory:
- inc
- t
requires:
perl: '5.008'
parent: '0'
Plack::Middleware: '0'
Process::SizeLimit::Core: '0.9501'
resources:
repository: http://github.com/audreyt/plack-middleware-sizelimit
version: '0.07'
24 changes: 16 additions & 8 deletions README
Expand Up @@ -10,21 +10,24 @@ SYNOPSIS
max_unshared_size_in_kb => '4096', # 4MB
# min_shared_size_in_kb => '8192', # 8MB
# max_process_size_in_kb => '16384', # 16MB
check_every_n_requests => 2
check_every_n_requests => 2,
log_when_limits_exceeded => 1
);
$app;
};

DESCRIPTION
This middleware is a port of the excellent Apache::SizeLimit module for
multi-process Plack servers, such as Starman, Starlet and "uWSGI".
multi-process Plack servers, such as Starman, Starlet, Gazelle and
"uWSGI".

This middleware only works when the environment "psgix.harakiri" is set
to a true value by the Plack server. If it's set to false, then this
middleware simply does nothing.

You must use at least version 0.2006 of Starman, and 0.19 of Starlet.
Earlier versions ignore the flag to stop the process.
You must use at least version 0.2006 of Starman (July 2010), and 0.19 of
Starlet (June 2013). Earlier versions ignore the flag to stop the
process.

CONFIGURATIONS
max_unshared_size_in_kb
Expand All @@ -49,18 +52,23 @@ CONFIGURATIONS
check_every_n_requests
Since checking the process size can take a few system calls on some
platforms (e.g. linux), you may specify this option to check the
process size every *N* requests.
process size every *N* requests. The default value for *N* is 1,
i.e. to check after the processing of every request.

log_when_limits_exceeded
When true, a warning will be logged when it kills off a process.
When true, the middleware will log a warning whenever it signals to
the server that the process is to be terminated. This is false by
default.

SEE ALSO
Starman, Starlet
Starman, Starlet, Gazelle

AUTHORS
唐鳳 <cpan@audreyt.org>

CC0 1.0 Universal
LICENSE
This work is under the CC0 1.0 Universal license.

To the extent possible under law, 唐鳳 has waived all copyright and
related or neighboring rights to Plack::Middleware::SizeLimit.

Expand Down
28 changes: 17 additions & 11 deletions README.mkdn
Expand Up @@ -11,22 +11,24 @@ Plack::Middleware::SizeLimit - Terminate processes if they grow too large
max_unshared_size_in_kb => '4096', # 4MB
# min_shared_size_in_kb => '8192', # 8MB
# max_process_size_in_kb => '16384', # 16MB
check_every_n_requests => 2
check_every_n_requests => 2,
log_when_limits_exceeded => 1
);
$app;
};

# DESCRIPTION

This middleware is a port of the excellent [Apache::SizeLimit](https://metacpan.org/pod/Apache::SizeLimit) module
for multi-process Plack servers, such as [Starman](https://metacpan.org/pod/Starman), [Starlet](https://metacpan.org/pod/Starlet) and `uWSGI`.
for multi-process Plack servers, such as [Starman](https://metacpan.org/pod/Starman), [Starlet](https://metacpan.org/pod/Starlet),
[Gazelle](https://metacpan.org/pod/Gazelle) and `uWSGI`.

This middleware only works when the environment `psgix.harakiri` is
set to a true value by the Plack server. If it's set to false, then this
middleware simply does nothing.

You must use at least version 0.2006 of Starman, and 0.19 of Starlet. Earlier versions
ignore the flag to stop the process.
You must use at least version 0.2006 of Starman (July 2010), and 0.19 of
Starlet (June 2013). Earlier versions ignore the flag to stop the process.

# CONFIGURATIONS

Expand All @@ -53,23 +55,27 @@ ignore the flag to stop the process.

- check\_every\_n\_requests

Since checking the process size can take a few system calls on some
platforms (e.g. linux), you may specify this option to check the process
size every _N_ requests.
Since checking the process size can take a few system calls on some platforms
(e.g. linux), you may specify this option to check the process size every _N_
requests. The default value for _N_ is 1, i.e. to check after the processing
of every request.

- log\_when\_limits\_exceeded

When true, a warning will be logged when it kills off a process.
When true, the middleware will log a warning whenever it signals to the server
that the process is to be terminated. This is false by default.

# SEE ALSO

[Starman](https://metacpan.org/pod/Starman), [Starlet](https://metacpan.org/pod/Starlet)
[Starman](https://metacpan.org/pod/Starman), [Starlet](https://metacpan.org/pod/Starlet), [Gazelle](https://metacpan.org/pod/Gazelle)

# AUTHORS

唐鳳 <cpan@audreyt.org>
唐鳳 &lt;cpan@audreyt.org>

# CC0 1.0 Universal
# LICENSE

This work is under the **CC0 1.0 Universal** license.

To the extent possible under law, 唐鳳 has waived all copyright and related
or neighboring rights to [Plack::Middleware::SizeLimit](https://metacpan.org/pod/Plack::Middleware::SizeLimit).
Expand Down
26 changes: 16 additions & 10 deletions lib/Plack/Middleware/SizeLimit.pm
Expand Up @@ -80,22 +80,24 @@ Plack::Middleware::SizeLimit - Terminate processes if they grow too large
max_unshared_size_in_kb => '4096', # 4MB
# min_shared_size_in_kb => '8192', # 8MB
# max_process_size_in_kb => '16384', # 16MB
check_every_n_requests => 2
check_every_n_requests => 2,
log_when_limits_exceeded => 1
);
$app;
};

=head1 DESCRIPTION

This middleware is a port of the excellent L<Apache::SizeLimit> module
for multi-process Plack servers, such as L<Starman>, L<Starlet> and C<uWSGI>.
for multi-process Plack servers, such as L<Starman>, L<Starlet>,
L<Gazelle> and C<uWSGI>.

This middleware only works when the environment C<psgix.harakiri> is
set to a true value by the Plack server. If it's set to false, then this
middleware simply does nothing.

You must use at least version 0.2006 of Starman, and 0.19 of Starlet. Earlier versions
ignore the flag to stop the process.
You must use at least version 0.2006 of Starman (July 2010), and 0.19 of
Starlet (June 2013). Earlier versions ignore the flag to stop the process.

=head1 CONFIGURATIONS

Expand Down Expand Up @@ -124,25 +126,29 @@ The maximum size of the process, including both shared and unshared memory.

=item check_every_n_requests

Since checking the process size can take a few system calls on some
platforms (e.g. linux), you may specify this option to check the process
size every I<N> requests.
Since checking the process size can take a few system calls on some platforms
(e.g. linux), you may specify this option to check the process size every I<N>
requests. The default value for I<N> is 1, i.e. to check after the processing
of every request.

=item log_when_limits_exceeded

When true, a warning will be logged when it kills off a process.
When true, the middleware will log a warning whenever it signals to the server
that the process is to be terminated. This is false by default.

=back

=head1 SEE ALSO

L<Starman>, L<Starlet>
L<Starman>, L<Starlet>, L<Gazelle>

=head1 AUTHORS

唐鳳 E<lt>cpan@audreyt.orgE<gt>

=head1 CC0 1.0 Universal
=head1 LICENSE

This work is under the B<CC0 1.0 Universal> license.

To the extent possible under law, 唐鳳 has waived all copyright and related
or neighboring rights to L<Plack::Middleware::SizeLimit>.
Expand Down
34 changes: 34 additions & 0 deletions t/1-basic.t
@@ -0,0 +1,34 @@
use Test::More;
use Plack::Test;
use Plack::Builder;
use Plack::Request;
use HTTP::Request::Common;

our $terminated = 0;

my $app = sub {
my $env = shift;
$env->{'psgix.harakiri'} = 1 unless $env->{'psgix.harakiri'};
$env->{'psgix.logger'} = sub { $terminated = 1 };
my $r = Plack::Request->new($env);
return [
200,
[ 'Content-Type' => 'text/plain' ],
[ 'abcdef' ]
];
};
$app = builder {
enable SizeLimit => (
max_process_size_in_kb => 1,
log_when_limits_exceeded => 1,
);
$app;
};

my $test = Plack::Test->create($app);
my $res = $test->request(GET "/");

is $res->content, 'abcdef';
is $terminated, 1;

done_testing;