Created
November 22, 2012 08:22
-
-
Save tmitz/4129969 to your computer and use it in GitHub Desktop.
apache maxclients limit
This file contains 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
use strict; | |
use warnings; | |
use Linux::Smaps; | |
use List::Util; # not core module | |
@ARGV or die "usage: %0 [pid...]"; | |
my $memory_total = `cat /proc/meminfo | grep MemTotal | awk '{print \$2}'` * 0.7; # -30% memory total | |
my @shared; | |
my @rss; | |
print "PID\tRSS\tSHARED\t\n"; | |
for (@ARGV) { | |
my $map = Linux::Smaps->new($_); | |
unless ($map) { | |
warn "not exists process...: $!"; | |
next; | |
} | |
push @shared, ($map->shared_dirty + $map->shared_clean); | |
push @rss, $map->rss; | |
printf "%d\t%d\t%d (%d%%)\n", $_, $map->rss, $map->shared_dirty + $map->shared_clean, int((($map->shared_dirty + $map->shared_clean) / $map->rss) * 100); | |
} | |
my $avg_shared = List::Util::sum(@shared) / scalar(@shared); | |
my $avg_rss = List::Util::sum(@rss) / scalar(@rss); | |
my $maxclient = scalar($memory_total / ($avg_rss + $avg_shared)); | |
print "------ MaxClients -----------\n"; | |
printf "memory_total / (avg_rss + avg_shared) = %dKB / (%dKB + %dKB) = %d\n", $memory_total, $avg_rss, $avg_shared, $maxclient; | |
print "-----------------------------\n"; | |
# vim ts=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment