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!

Wikipathia / American Made

Wikpathia: Traversing wikipedia, from link to link, until your starting link is in no way related to your ending link.

From the “American Made” trailer to an Muslim Archaeologist who was believed to be exchanged for an airplane hijacker that tortured killed a Navy Seabee.

Thanks to: http://www.fark.com/vidplayer/9615942

https://en.wikipedia.org/wiki/Barry_Seal
https://en.wikipedia.org/wiki/Trans_World_Airlines
https://en.wikipedia.org/wiki/Republic_of_New_Afrika
https://en.wikipedia.org/wiki/TWA_Flight_841_(1974)
https://en.wikipedia.org/wiki/Robert_Stethem
https://en.wikipedia.org/wiki/Mohammed_Ali_Hammadi
https://en.wikipedia.org/wiki/Susanne_Osthoff

WordLock… Easy to set, never forget.

So, I have one of these WordLock bicycle locks, and it was cool to learn how to set it up and change the combination.

The only problem is: I forgot what we set the combination to. #sadface

So, without further ado, to programming!

The Scenario:

Lets assume for a moment we know two things:

  1. We know there are 10,000 combinations, and that the combination that it is set to is a word in the english language.
  2. We have a good understanding of what the word might be if we saw it.

So, with those facts, we’ll need two things:

  1. A list of 4-letter words, which we’ll steal *cough* borrow from litscape.com
  2. Some programming that goes through every combination possible and compares it to the wordlist

So, the programming:

<?php

function make4($number)
{
        $num = intval($number);
        if (($num < 0) || ($num > 9999))
        {
                die("out of range");
        }
        $ret = "";

        if (strlen($num) == 4)
        {
                $ret = $num;
        }
        if (strlen($num) == 3)
        {
                $ret = "0${num}";
        }
        if (strlen($num) == 2)
        {
                $ret = "00${num}";
        }
        if (strlen($num) == 1)
        {
                $ret = "000${num}";
        }
        return $ret;
}

function combination($number)
{
        $letters = array(
                array('B', 'F', 'R', 'M', 'D', 'T', 'S', 'W', 'P', 'L'),
                array('Y', 'R', 'W', 'H', 'E', 'L', 'O', 'I', 'A', 'U'),
                array('S', 'N', 'T', 'M', 'R', 'E', 'L', 'A', 'O', 'K'),
                array('E', 'T', 'S', 'M', 'K', 'G', 'D', 'L', 'Y', 'P'),
        );
        $code = "";
        $combo = make4($number);
        for ($x = 0; $x < 4; $x++)
        {
                $digit = substr($combo, $x, 1);
                $letter = $letters[$x][$digit];
                $code .= $letter;
        }
        return $code;
}

$words = "";
include('words4.php');
$word = explode(' ', $words);
echo "Loaded " . count($word) . " words\n";

foreach ($word as $w)
{
        $possible = strtoupper($w);
        echo "Trying: $possible\n";
        for ($x = 0; $x < 10000; $x++)
        {
                $code = combination($x);
                if ($code == $possible)
                {
                        echo "Found: $possible\n";
                }
        }
}
?>

I’ve take the space-separated wordlist and saved it as an assignment to the $words variable in a separate file. vim doesn’t do justice with multi-lined non-carriage returned stuff, so I’m cool with that.

After executing the above, from a wordlist of 2404 items, i’m left with 732 possible items.

It is going to be a looooooooooooooooong day 🙁

BAAS, BAKE, BALD, BALE, BALK, BALL, BALM, BAND, BANE, BANG, BANK, BANS, BARD, BARE, BARK, BARM, BARS, BASE, BASK, BASS, BATS, BEAD, BEAK, BEAM, BEAT, BEEP, BEES, BEET, BELL, BELT, BEND, BENT, BERK, BERM, BEST, BETS, BIAS, BIKE, BILE, BILK, BILL, BIND, BINS, BIOS, BIRD, BITE, BITS, BITT, BLAT, BLED, BLOG, BLOT, BOAS, BOAT, BOLD, BOLL, BOLT, BOND, BONE, BONK, BONY, BOOK, BOOM, BOOS, BOOT, BORE, BOSS, BOTS, BRAD, BRAG, BRAS, BRAT, BRAY, BRED, BULK, BULL, BUMP, BUMS, BUNK, BUNS, BUNT, BUOY, BURL, BURP, BURS, BURY, BUSK, BUST, BUSY, BUTS, BUTT, BYES, BYTE, DAME, DAMP, DAMS, DANK, DARE, DARK, DART, DATE, DEAD, DEAL, DEED, DEEM, DEEP, DEES, DELE, DELL, DEME, DEMY, DENE, DENS, DENT, DENY, DERE, DERM, DESK, DIAL, DIED, DIES, DIET, DILL, DIME, DIMS, DINE, DING, DINS, DIRE, DIRT, DISK, DOES, DOLE, DOLL, DOLT, DOME, DONE, DONS, DOOM, DORK, DORM, DOSE, DOTE, DOTS, DOTY, DRAG, DRAM, DREG, DROP, DUAL, DUEL, DUES, DUET, DUKE, DULL, DULY, DUMP, DUNE, DUNG, DUNK, DUOS, DUSK, DUST, DUTY, DYED, DYES, DYNE, FAKE, FALL, FAME, FANG, FANS, FARE, FARM, FAST, FATE, FATS, FEAT, FEED, FEEL, FEES, FEET, FELL, FELT, FEND, FENS, FILE, FILL, FILM, FIND, FINE, FINK, FINS, FIRE, FIRM, FIRS, FIST, FITS, FLAG, FLAP, FLAT, FLAY, FLED, FLEE, FLOE, FLOG, FLOP, FOAL, FOAM, FOES, FOLD, FOLK, FOND, FONT, FOOD, FOOL, FOOT, FORE, FORK, FORM, FORT, FRAY, FREE, FRET, FROG, FROM, FUEL, FULL, FUME, FUMY, FUND, FUNK, FURS, FURY, FUSE, FUSS, LAKE, LAME, LAMP, LAND, LANE, LANK, LARD, LARK, LASS, LAST, LATE, LEAD, LEAK, LEAP, LEAS, LEEK, LEES, LEKS, LEND, LENS, LENT, LESS, LEST, LETS, LIED, LIES, LIKE, LILY, LIME, LIMP, LIMY, LINE, LINK, LINT, LIRE, LISP, LIST, LITE, LOAD, LOAM, LOLL, LONE, LONG, LOOK, LOOM, LOOP, LOOS, LOOT, LORD, LORE, LOSE, LOSS, LOST, LOTS, LULL, LUMP, LUNG, LURE, LURK, LUST, LUTE, LYRE, MAKE, MALE, MALL, MALT, MANE, MANS, MANY, MARE, MARK, MARL, MARS, MART, MASK, MASS, MAST, MATE, MATS, MATT, MEAD, MEAL, MEAT, MEEK, MEET, MELD, MELT, MEME, MEND, MENS, MERE, MESS, MILD, MILE, MILK, MILL, MILS, MIME, MIND, MINE, MINK, MINT, MIRE, MISS, MIST, MITE, MITT, MOAT, MOLD, MOLE, MOLT, MOMS, MONK, MOOD, MOOS, MOOT, MORE, MOSS, MOST, MULE, MULL, MUMS, MURK, MUSE, MUSK, MUST, MUTE, MUTT, PALE, PALL, PALM, PALS, PANE, PANG, PANS, PANT, PARE, PARK, PARS, PART, PASS, PAST, PATE, PATS, PEAK, PEAL, PEAS, PEAT, PEEK, PEEL, PEEP, PELT, PEND, PENS, PENT, PERK, PERM, PERT, PEST, PETS, PIED, PIES, PIKE, PILE, PILL, PIMP, PINE, PING, PINK, PINS, PINT, PITS, PITY, PLAY, PLED, PLOD, PLOP, PLOT, PLOY, POEM, POET, POKE, POKY, POLE, POLL, POMP, POND, PONY, POOL, POOP, PORE, PORK, PORT, POSE, POST, POSY, POTS, PRAM, PRAY, PREP, PREY, PROD, PROM, PROP, PROS, PUKE, PULL, PULP, PUMP, PUNK, PUNS, PUNT, PUNY, PURE, PUTS, PUTT, PYRE, RAKE, RAMP, RAMS, RAND, RANG, RANK, RANT, RARE, RASP, RATE, RATS, READ, REAK, REAL, REAM, REAP, REED, REEK, REEL, RELY, REND, RENT, REST, RHOS, RIAL, RIEL, RILE, RILL, RILY, RIME, RIMS, RIND, RING, RINK, RIOT, RISE, RISK, RITE, ROAD, ROAM, ROES, ROLE, ROLL, ROMP, ROOD, ROOK, ROOM, ROOT, ROSE, ROSY, ROTE, ROTS, RUED, RUES, RULE, RUMS, RUNE, RUNG, RUNS, RUNT, RUSE, RUST, RUTS, SAKE, SALE, SALT, SAME, SAND, SANE, SANG, SANK, SASS, SATE, SEAL, SEAM, SEAS, SEAT, SEED, SEEK, SEEM, SEEP, SEES, SELL, SEND, SENT, SERE, SETS, SHAM, SHED, SHOE, SHOP, SHOT, SILK, SILL, SILT, SINE, SING, SINK, SINS, SIRE, SIRS, SITE, SITS, SLAM, SLAP, SLAT, SLAY, SLED, SLOE, SLOG, SLOP, SLOT, SOAK, SOAP, SOLD, SOLE, SOME, SOMS, SONG, SONS, SOOT, SORE, SORT, SOTS, SUED, SUES, SUET, SULK, SUMP, SUMS, SUNG, SUNK, SUNS, SURE, SWAG, SWAM, SWAP, SWAT, SWAY, TAKE, TALE, TALK, TALL, TAME, TAMP, TAMS, TANK, TANS, TARE, TARP, TARS, TART, TASK, TEAK, TEAL, TEAM, TEAS, TEED, TEEM, TEES, TELL, TEND, TENS, TENT, TERM, TEST, THAT, THEE, THEM, THEY, TIED, TIES, TIKE, TILE, TILL, TILT, TIME, TINE, TING, TINS, TINT, TINY, TIRE, TOAD, TOED, TOES, TOLD, TOLL, TOME, TONE, TONG, TONS, TOOK, TOOL, TOOT, TORE, TORT, TOSS, TOTE, TOTS, TRAM, TRAP, TRAY, TREE, TREK, TROD, TROT, TROY, TUMS, TUNE, TUSK, TWOS, TYKE, WAKE, WALK, WALL, WAND, WANE, WANT, WARD, WARE, WARM, WARP, WARS, WART, WARY, WASP, WATT, WEAK, WEED, WEEK, WEEP, WELD, WELL, WELT, WEND, WENT, WERE, WEST, WETS, WHAM, WHAT, WHET, WHEY, WHOM, WHOP, WILD, WILE, WILL, WILT, WILY, WIMP, WIND, WINE, WING, WINK, WINS, WIRE, WIRY, WISE, WISP, WIST, WITS, WOAD, WOES, WOKE, WOKS, WONS, WONT, WOOD, WOOL, WOOS, WORD, WORE, WORK, WORM, WORT, WRAP, WYES

Edit:

For the sake of justice, none of the above words looked familiar.

I headed over to the wordlock FAQ and did the following:

I can’t open my lock. What combination does my lock open to?
Try of the following factory-set default combinations to open your lock: BOLT, SPELL, PACK, SHED, TREE, GYMS, WORDS.

Seems the factory default worked, which means I NEVER SET THE DAMN LOCK IN THE FIRST PLACE :/