OpenVZ/cPanel specific Apache memory limit (RlimitMEM)

Here one can find interesting information about OpenVZ management and maintenance. OpenVZ control panels information also goes here

OpenVZ/cPanel specific Apache memory limit (RlimitMEM)

Postby lik » Tue May 12, 2009 2:47 am

Apache memory limit (RlimitMEM)

If you are using cPanel/WHM then you've got an option in your WHM to limit memory usage by apache processes (RLimitMEM), the option is under Security -> Modify Apache Memory Usage.

This option executes the script: /scripts/apachelimits. It works fine on dedicated systems, it reads the /proc/meminfo file for the currently installed memory and sets the limit accordingly.

Unfortunately the script is useless on a VPS, since a VPS uses a part of the system memory. As a result, the generated values are wrong and cause problems for many people.

I've written a perl script, based on the original cPanel apachelimits, which is for VPS servers hosted by Jag. The script will properly give you the setting based on the memory your VPS is allowed to use.

The script does NOT modify your configuration, it just prints the setting and it lets you copy/paste it, just in case you are not happy with the result.

Just copy/paste the following code into a file, make it executable with "chmod +x file.pl" and run it with "./file.pl". You may also place it in your ~/bin directory if you want to frequently run it.

Code: Select all
#!/usr/bin/perl
use lib '/scripts';
use SafeFile;

print "\nSearching for VPS Memory Limit.............: ";
$file = '/proc/user_beancounters';
open(INFO, $file);
@lines = <INFO>;
close(INFO);

$lines[9] =~ s/\s+/:/g;
print $lines[9]."\n";
@words = split(/:/, $lines[9]);
$size = $words[4];
print "Found VPS memory limit (estimated).........: ".int($words[4]/1024*4)." MB\n";

$lines[8] =~ s/\s+/:/g;
@words = split(/:/, $lines[8]);
print "Current VPS memory usage (estimated).......: ".int($words[2]/1024*4)." MB\n";

print "Calculating RLimitMEM......................: ";
$size = int( $size / 2 );
$size = int( $size * 1024 );
print "$size";
$size = int( $size / 3 );
print ", $size\n";

$meg = int( $size / ( 1024 * 1024 ) );
print "Suggested apache child process limit.......: ".$meg." MB\n\n";
print "You may add the following into your /etc/httpd/conf/httpd.conf:\n\nRLimitMEM ".$size."\n\n";
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Return to OpenVZ related

 


  • Related topics
    Replies
    Views
    Last post
cron