Repository navigation
Bug 2091167 - SizeLimit plugin parses all of /proc/self/smaps in pure Perl after every request (~3 ms per request) #2822
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e4bdea
Bug 2091167 - SizeLimit plugin parses all of /proc/self/smaps in pure…
dklawren bbce74d
Merge branch 'master' into 2091167
dklawren 7ccc262
docs: Bug 2091167 - Rename linux_smaps feature to rlimit, trim comment
dklawren 2bc0a77
Merge branch 'master' into 2091167
dklawren a80ae4b
docs: Bug 2091167 - Describe size_limit as VmSize in kB
dklawren 4b37ab1
Merge branch 'master' into 2091167
dklawren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env perl | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
| use strict; | ||
| use warnings; | ||
| use 5.10.1; | ||
| use lib qw( . lib local/lib/perl5 ); | ||
|
|
||
| BEGIN { $ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf' } | ||
|
|
||
| # Empty setrlimit so the plugin does not cap this test process's memory. | ||
| use Bugzilla::Test::MockLocalconfig (size_limit => 750_000, setrlimit => '{}'); | ||
| use Bugzilla; | ||
| use Bugzilla::App::Plugin::SizeLimit; | ||
| use Test2::V0; | ||
| use Test::Mojo; | ||
| use Mojolicious::Lite; | ||
|
|
||
| subtest 'vm_size_kb reads VmSize' => sub { | ||
| skip_all 'no /proc/self/status' unless -r '/proc/self/status'; | ||
| my $size = Bugzilla::App::Plugin::SizeLimit::vm_size_kb(); | ||
| like($size, qr/^\d+$/, 'whole number of kB'); | ||
| ok($size > 1024, "plausible size ($size kB)"); | ||
| }; | ||
|
|
||
| subtest 'after_dispatch closes the worker only when over the limit' => sub { | ||
| skip_all 'no /proc/self/status' unless -r '/proc/self/status'; | ||
|
|
||
| # Must be defined when register() runs, or it skips installing the hook. | ||
| my $fake_size = 1; | ||
| my $stops = 0; | ||
| my $mock_size = mock 'Bugzilla::App::Plugin::SizeLimit' => | ||
| (override => [vm_size_kb => sub {$fake_size}]); | ||
| my $mock_loop | ||
| = mock 'Mojo::IOLoop' => (override => [stop_gracefully => sub { $stops++ }]); | ||
|
|
||
| plugin 'Bugzilla::App::Plugin::SizeLimit'; | ||
| get '/' => sub { shift->render(text => 'ok') }; | ||
| my $t = Test::Mojo->new; | ||
|
|
||
| $fake_size = 749_999; | ||
| $t->get_ok('/')->status_is(200)->header_isnt(Connection => 'close'); | ||
| is($stops, 0, 'under the limit: worker keeps running'); | ||
|
|
||
| $fake_size = 750_000; | ||
| $t->get_ok('/')->status_is(200)->header_is(Connection => 'close'); | ||
| is($stops, 1, 'at the limit: worker stops gracefully'); | ||
|
|
||
| $fake_size = undef; | ||
| $t->get_ok('/')->status_is(200)->header_isnt(Connection => 'close'); | ||
| is($stops, 1, 'size unavailable: no action'); | ||
| }; | ||
|
|
||
| done_testing; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BMO_size_limitin README.md andlocalconfig_size_limitin template/en/default/setup/strings.txt.pl still mention the limit as "unshared memory", while it is compared to VmSize (much larger).Since this PR makes it explicit, maybe could they say "virtual memory size (VmSize, in kB)" instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated both
BMO_size_limitin README.md andlocalconfig_size_limitin strings.txt.pl to say "virtual memory size (VmSize, in kB)" in a80ae4b14.