Skip to content

Commit

Permalink
Merge pull request #109 from dterweij/6.1.x
Browse files Browse the repository at this point in the history
Project issue #994.
  • Loading branch information
dterweij committed Feb 23, 2014
2 parents 05812b8 + 222a5bd commit 8ffd26d
Showing 1 changed file with 24 additions and 38 deletions.
62 changes: 24 additions & 38 deletions kloxo/bin/fix/apache-optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

include_once "htmllib/lib/include.php";

// initProgram('admin');

$list = parse_opt($argv);

$select = (isset($list['select'])) ? $list['select'] : 'optimize';
Expand Down Expand Up @@ -54,27 +52,18 @@ function setApacheOptimize($select, $spare = null)

$m['apps'] = (int)shell_exec("free -m | grep buffers/cache: | awk '{print $3}'");

/*
$m['used'] = (int)shell_exec("free -m | grep Mem: | awk '{print $3}'");
$m['free'] = (int)shell_exec("free -m | grep Mem: | awk '{print $4}'");
$m['shared'] = (int)shell_exec("free -m | grep Mem: | awk '{print $5}'");
$m['buffers'] = (int)shell_exec("free -m | grep Mem: | awk '{print $6}'");
$m['cached'] = (int)shell_exec("free -m | grep Mem: | awk '{print $7}'");
$m['avail'] = $m['free'] + $m['shared'] + $m['buffers'] + $m['cached'] - $m['spare'];
*/

$m['avail'] = $m['total'] - $m['spare'] - $m['apps'];

// $maxpar = (int)($m['avail'] / 25);
// $minpar = (int)($maxpar / 2);
$maxCl_p = (int) floor($m['avail'] / 30) + 1;
$maxSS_p = (int) ceil($maxCl_p / 2);
$minSS_p = (int) ceil($maxSS_p / 2);

$maxpar_p = (int)($m['avail'] / 30) + 1;
$minpar_p = (int)($maxpar_p / 2);
$maxThr_w = (int) floor($m['avail'] / 35) + 1;
$maxCl_w = (int) floor( sqrt($maxThr_w));
$ThrPC_w = (int) floor($maxThr_w / $maxCl_w);
$maxST_w = (int) ceil($ThrPC_w / 2);
$minST_w = (int) ceil($maxST_w / 2);

$maxpar_w = (int)($m['avail'] / 35) + 1;
$minpar_w = (int)($maxpar_w / 2);

// because on apache 2.2.x no appear 'overflow' memory so
// no need ServerLimit = MaxClients = $maxpar_p for prefork/itk
// no need MaxClients = ThreadsPerChild = $maxpar_p for worker/event
Expand All @@ -87,41 +76,41 @@ function setApacheOptimize($select, $spare = null)
<IfModule prefork.c>
StartServers 2
MinSpareServers {$minpar_p}
MaxSpareServers {$maxpar_p}
ServerLimit 256
MaxClients 256
ServerLimit {$maxCl_p}
MaxClients {$maxCl_p}
MinSpareServers {$minSS_p}
MaxSpareServers {$maxSS_p}
MaxRequestsPerChild 4000
MaxMemFree 2
</IfModule>
<IfModule itk.c>
StartServers 2
MinSpareServers {$minpar_p}
MaxSpareServers {$maxpar_p}
ServerLimit 256
MaxClients 256
ServerLimit {$maxCl_p}
MaxClients {$maxCl_p}
MinSpareServers {$minSS_p}
MaxSpareServers {$maxSS_p}
MaxRequestsPerChild 4000
MaxMemFree 2
</IfModule>
<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads {$minpar_w}
MaxSpareThreads {$maxpar_w}
ThreadsPerChild 25
MaxClients {$maxCl_w}
ThreadsPerChild {$ThrPC_w}
MaxSpareThreads {$maxST_w}
MinSpareThreads {$minST_w}
MaxRequestsPerChild 0
ThreadStackSize 8196
MaxMemFree 2
</IfModule>
<IfModule event.c>
StartServers 2
MaxClients 150
MinSpareThreads {$minpar_w}
MaxSpareThreads {$maxpar_w}
ThreadsPerChild 25
MaxClients {$maxCl_w}
ThreadsPerChild {$ThrPC_w}
MaxSpareThreads {$maxST_w}
MinSpareThreads {$minST_w}
MaxRequestsPerChild 0
ThreadStackSize 8196
MaxMemFree 2
Expand All @@ -139,10 +128,7 @@ function setApacheOptimize($select, $spare = null)

log_cleanup("- Calculate Apache:");
log_cleanup("-- threads limit (min/max -> $minpar_w/$maxpar_w) and servers limit (min/max -> $minpar_p/$maxpar_p)");

log_cleanup("- Write to /etc/httpd/conf.d/~lxcenter.conf");

// $s=implode("", file("/etc/httpd/conf.d/~lxcenter.conf"));
$f = fopen("/etc/httpd/conf.d/~lxcenter.conf", "w");
fwrite($f,$s,strlen($s));

Expand Down

0 comments on commit 8ffd26d

Please sign in to comment.