HomeSoftwareScriptsNotesToolboxGallery
Computing
Thoughts on Coding Styleddrescue Recovery NotesDomain 301 Perma RedirectWin/Linux PuTTY File TransferOpenVPN Site-to-Site SetupParity Data CheckingRclone Quick ReferenceSnapRAID NotesSSH TunnelingTransfer E-Mails with IMAPUDK Third Person CameraVPN Protocol Ports

GNU/Linux
Apache Process Mem UsageApache and CA OpenSSLApache2 htpasswd NotesCentOS 7 GlusterFS NotesCracking WEP and WPADebian 7 on Hyper-VDebian 7 to 8 UpgradeDebian 8 to 9 UpgradeDebian 9 DRBD SetupDebian and VirtualboxDebian and LSBInitScriptsDebian and systemdDebian Apache LetsEncryptDebian Apt AutoremoveDebian Cron & AnacronDebian KVM HypervisorLinux Bash ColorsLinux Cron BackupLinux Dnsmasq Setup NotesIptables Chain ExampleIptables Firewall and GatewayLinux MD RAID BasicsLinux iproute2 RoutingLinux SFTP Network ShareAvoid Linux Shell LoggingChecking Storage UsageLinux I/O Disk PerformanceLinux ZFS NotesVi/Vim Basic Reference

Microsoft
Bypass Windows PasswordDaz and ToolkitMRTG Network Traffic ViewMS Outlook NotesDOS File Content SearchDOS Merging VCF filesROBOCOPY Batch ScriptingPowerShell Reference NotesThe runas CommandTeamViewer on HeadlessUpdateOrchestrator ModWorkgroup Failover ClusterDisable OneDrive in W10Windows 10 ServerWindows WiFi and netshWindows Boot Custom UIHyper-V NetworkingHyper-V ReplicationIIS10 and PHP7 SetupLet's Encrypt and IISPlex Media Server MigrationRebuilding Boot PartitionSecuring RDP ConnectionsServer 2012 R2 SetupWindows Shortcut CommandsWBAdmin Bare-Metal Backup

BSD/Unix
FreeBSD 10.0 Setup (NOR)

C#/.NET
C# Associative ArraysC# Asynchronized WebcallC# Base64 GZipped JSONC# Broadcast Registry ChangesChanging a project nameC# Code Execution TimerCode Signing With SigntoolC# Creating a WebserverC# Dealing with WhitespacesC# djDBI for SQL CEC# Form ReferencingC# Get Folder SizeC# Handling DisconnectsC# HTTP POST and GETC# Importing DLL FunctionsC# Installing ServicesC# Kill and Start ProcessesC# Lambda ExpressionsC# Local AppData HandlingC# Memory StreamReadingC# Minimize to System TrayC# PDFsharp and MigraDocC# Public Fields vs PropsC# Registry HandlingC# Regular ExpressionsC# Require AdministratorC# RichTextBox File StreamC# Application SettingsC# SqlCeConnection CodeC# Start with hidden formC# String EncryptionC# Cross Thread HandlingC# Updating A RuntimeC# Gmail as SMTPVSI Dependency ErrorC# Handle XML

C/C++
AOB Scan/InjectC Autodelete Old FilesC/C++ Multiline StringsC Socket ListeningC StringsGDI Double BufferWin32 Button ControlWin32 Edit ControlWin32 GetLastError()Win32 KeyloggingWin32 KeypostingWin32 Simple WindowWin32 Socket ProgrammingWin32 VERSIONINFO

PHP
Bitwise IP HandlingPHP ClassesContent Length HandlingDetecting Mobile BrowsersGoogle Captcha IntegrationHidden DownloadsHostname and Port RegexJSON Output HeadersMS Access Conn with COMProportional Image SizingRandom StringsRecursive FunctionsSending MailPHP SessionsSimple HTML-2-PDFPHP SimpleXMLTernary Operator and If/Else

SQL
MS Access Connection StringsMSSQL Case SensitivityMySQL Root Password ResetMySQL Check Slow QueriesColumn CountingQuick Note on CROSS JOINQuick Note on INNER JOINRandom Rows

HTML
HTML Raw Skeleton

JavaScript
AJAX Basicsevent.keyCode ReferenceIE7 Onclick EventsIE GIF Animation Problem

Java
Java Notater (NOR)

CSS
Border StylesFlyout MenusFont-Family Reference

Electrical
Betegnelser og SpenningsfallLovdata Elektrisk ArbeidResistors Series and ParallelSilicone and Circuit Boards

Apache Process Memory Usage and Worker Configuration


A bash script for checking Apache process memory usage. This is useful for figuring out server configuration.

Script:
#!/bin/bash
ps -ylC apache2 --sort:rss | \
awk '{sum+=$8; ++n} END \
{print "Tot="sum"("n")"; \
print "Avg="sum"/"n"="sum/n/1024"MB"}'

Example output:
Tot=322300(16)
Avg=322300/16=19.6716MB

This means that every Apache process currently takes ~20 MB of RAM. What I do is take about 80% of total FREE memory and divide it on how many processes I can support. Then I know how many workers I should put in my web server configuration.

 $ free -m
             total       used       free     shared    buffers     cached
Mem:         15792      15622        169          8        400      14323
-/+ buffers/cache:        897      14894
Swap:         8183          0       8183

(14894 * 0.8) / 20 = 595.76

If you take into account the 16 processes already used:
14894 + (16 * 19.7) = (15209 * 0.8) / 20 = 608.36 instead.

# cat /etc/apache2/mods-enabled/mpm_prefork.conf
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxRequestWorkers: maximum number of server processes allowed to start
# MaxConnectionsPerChild: maximum number of requests a server process serves


        StartServers            5
        MinSpareServers         5
        MaxSpareServers         10
        MaxRequestWorkers       600
        MaxConnectionsPerChild  0


This is given that it's a dedicated web server, or else perhaps based yourself on even less than 80% memory. For monitoring worker usage I use Apache2's built-in status.conf module. This is usually enabled to default, it not you can enable it with a2enmod status.

Lock /etc/apache2/mods-enabled/status.conf for local use first:
SetHandler server-status
Require local

Use PHP to read it locally to any location instead using authorization:
if($_SESSION['pass'] == $password) {
	echo '<input type="button" value="Refresh" onclick="location.reload()"><br>'.
	file_get_contents("https://your-site.com/server-status");
}

Example (most important bit) output of /server-status
1.88 requests/sec - 5.2 kB/second - 2850 B/request
4 requests currently being processed, 8 idle workers

_W.W____K_.W_._...................................

Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process

The example above is from a server with only 1 GB RAM and 50 workers (default) but should be about 25.