apache process tuning

A long, long time ago I had an opportunity to fine-tune apache processes on a couple hundred hosts. It took one script run on some of the highly-loaded hosts to get specific numbers, and those numbers are what are important.

For shell processing you’ll need bc.

Running the below program on my current host presents the following output:

sudo ./apache_process_tuning.pl
1035:11956224 1036:19152896 1037:16871424 1038:32567296 1039:11386880 1040:13230080 1041:15876096 1042:20291584 2131:14344192 2132:14438400 2133:13373440 10578:15732736 29812:2068480
==========
There are 13 Apache Processes that consume 201,289,728 bytes of RAM
Each process takes an average of 15,483,825 bytes of RAM

You have 2,103,779,328 bytes of RAM, with 1,756,119,040 unused if Apache were not running

You can be ok with a MAX_CLIENTS setting lower than 113

To the gods of perl, I present thee!

#!/usr/bin/perl
use strict;
use warnings
# http://www.perlmonks.org/?node_id=110137
sub commify {
   my $text = reverse $_[0];
   $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
   return scalar reverse $text
}
# step 0, make sure we are sudo
die("Need to sudo this command") if ( not defined $ENV{'SUDO_USER'} );
# Step 1, get system memory information
my $free = `/usr/bin/free -mb`;
my ($mem_total, $mem_used, $mem_free);
for (split /^/, $free) {
   if ($_ =~ /Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
      $mem_total = $1;
      $mem_used = $2;
      $mem_free = $3;
   }
}
die("Cannot get memory statistics") if (not defined $mem_total);
# Step 2, get httpd process
my $processes = `/bin/ps aux`;
my ($process_count, $process_total, $process_mem);
for (split /^/, $processes) {
   if ($_ =~ /(\w+)\s+(\d+)\s+[\d\.]+\s+[\d\.]+\s+\d+\s+\d+\s+[\w\?\/]+\s+[\w\+<]+\s+[\d\w:]+\s+[\d:]+\s+(.+)/) {
      my $proc_owner = $1;
      my $proc_pid = $2;
      my $proc_cmd = $3;
      if ($proc_cmd =~ /httpd$/) {
         # Step 2a, Get some Private_Dirty
         # http://stackoverflow.com/questions/118307/a-way-to-determine-a-processs-real-memory-usage-i-e-private-dirty-rss
         $process_mem = `awk '/Private_Dirty/ {print \$2,\$3}' /proc/${proc_pid}/smaps | sed 's/ tB/*1024 gB/;s/ gB/*1024 mB/;s/ mB/*1024 kB/;s/ kB/*1024/;1!s/^/+/;' | tr -d '\\n' | sed 's/\$/\\n/' | bc`;
         chomp($process_mem);
         $process_count++;
         $process_total+=$process_mem;
         print $proc_pid . ":" . $process_mem . " ";
      }
   }
}
die("Having a problem getting active httpd info") if (not defined $process_count);
# step 3, give some helpful output
my ($process_average, $unused_mem, $max_clients);
print "\n==========\n";
$process_average = sprintf("%d", $process_total / $process_count);
print "There are " . $process_count . " Apache Processes that consume " . commify($process_total) . " bytes of RAM\n";
print "Each process takes an average of " . commify($process_average) . " bytes of RAM\n";
print "\n";
$unused_mem = sprintf("%d", $mem_used - $process_total);
print "You have " . commify($mem_total) . " bytes of RAM, with " . commify($unused_mem) . " unused if Apache were not running\n";
print "\n";
# Math is: "available" RAM with no httpd divided by average process total
$max_clients = sprintf("%d", $unused_mem / $process_average);
print "You can be ok with a MAX_CLIENTS setting lower than " . $max_clients . "\n";
print "\n";

Verses Three

Il Dolce Suono

Italian

Il dolce suono mi colpì di sua voce!
Ah, quella voce m’è qui nel cor discesa!
Edgardo! io ti son resa. Edgardo! Ah! Edgardo, mio! Si’, ti son resa!
fuggita io son da’ tuoi nemici. (nemici)
Un gelo me serpeggia nel sen!
trema ogni fibra!
vacilla il piè!
Presso la fonte meco t’assidi alquanto! Si’, Presso la fonte meco t’assidi.
Ohimè, sorge il tremendo fantasma e ne separa!
Qui ricovriamo, Edgardo, a piè dell’ara.
Sparsa è di rose!

Un’armonia celeste, di’, non ascolti?
Ah, l’inno suona di nozze!
Il rito per noi s’appresta! Oh, me felice!
Oh gioia che si sente, e non si dice!
Ardon gl’incensi!
Splendon le sacre faci, splendon intorno!
Ecco il ministro!
Porgimi la destra!
Oh lieto giorno!
Al fin son tua, al fin sei mio,
a me ti dona un Dio.
Ogni piacer più grato,
mi fia con te diviso
Del ciel clemente un riso
la vita a noi sarà.

English

The sweet sound of his voice struck me!
Ah, that voice has entered my heart!
Edgardo! I surrender to you, oh my Edgardo!
I have escaped from your enemies.
A chill creeps into my breast!
Every fibre trembles!
My foot falters!
Sit down by the fountain with me a while!
Alas, the tremendous phantom arises and separates us!
Let us take refuge here, Edgardo, at the foot of the altar.
It is scattered with roses!

A heavenly harmony, tell me, do you not hear it?
Ah, the marriage hymn is playing!
They are preparing the rite for us! Oh, how happy I am!
Oh joy that is felt but not said!
The incense is burning!
The holy torches are shining, shining around!
Here is the minister!
Give me your right hand!
Oh joyful day!
At last I am yours, at last you are mine,
A god gives you to me.
Let me share
The greatest pleasures with you,
Life for us will be
A smile from merciful heaven.


Invictus

Out of the night which covers me,
Black as the pit from pole to pole,
I thank whatever gods may be
For my unconquerable soul.

In the fell clutch of circumstance
I have not winced nor cried aloud.
Under the bludgeoning of chance
My head is bloody, but unbowed.

Beyond this place of wrath and tears
Looms but the Horror of the shade,
And yet the menace of the years
Finds, and shall find me, unafraid.

It matters not how strait the gate,
How charged with punishments the scroll,
I am the master of my fate:
I am the captain of my soul.


The Destruction of Sennacherib

The Assyrian came down like the wolf on the fold,
And his cohorts were gleaming in purple and gold;
And the sheen of their spears was like stars on the sea,
When the blue wave rolls nightly on deep Galilee.

Like the leaves of the forest when Summer is green,
That host with their banners at sunset were seen:
Like the leaves of the forest when Autumn hath blown,
That host on the morrow lay withered and strown.

For the Angel of Death spread his wings on the blast,
And breathed in the face of the foe as he passed;
And the eyes of the sleepers waxed deadly and chill,
And their hearts but once heaved, and for ever grew still!

And there lay the steed with his nostril all wide,
But through it there rolled not the breath of his pride;
And the foam of his gasping lay white on the turf,
And cold as the spray of the rock-beating surf.

And there lay the rider distorted and pale,
With the dew on his brow, and the rust on his mail:
And the tents were all silent, the banners alone,
The lances unlifted, the trumpet unblown.

And the widows of Ashur are loud in their wail,
And the idols are broke in the temple of Baal;
And the might of the Gentile, unsmote by the sword,
Hath melted like snow in the glance of the Lord.


O Fortuna

Original
O Fortuna
velut luna
statu variabilis,
semper crescis
aut decrescis;
vita detestabilis
nunc obdurat
et tunc curat
ludo mentis aciem,
egestatem,
potestatem
dissolvit ut glaciem.

Sors immanis
et inanis,
rota tu volubilis,
status malus,
vana salus
semper dissolubilis,
obumbrata
et velata
michi quoque niteris;
nunc per ludum
dorsum nudum
fero tui sceleris.

Sors salutis
et virtutis
michi nunc contraria,
est affectus
et defectus
semper in angaria.
Hac in hora
sine mora
corde pulsum tangite;
quod per sortem
sternit fortem,
mecum omnes plangite!

Translation
O Fortune,
like the moon
you are changeable,
ever waxing
and waning;
hateful life
first oppresses
and then soothes
as fancy takes it;
poverty
and power
it melts them like ice.

Fate – monstrous
and empty,
you whirling wheel,
you are malevolent,
well-being is vain
and always fades to nothing,
shadowed
and veiled
you plague me too;
now through the game
I bring my bare back
to your villainy.

Fate is against me
in health
and virtue,
driven on
and weighted down,
always enslaved.
So at this hour
without delay
pluck the vibrating strings;
since Fate
strikes down the strong man,
everyone weep with me!