Sunday, April 7, 2013

Google Redirect Rewrite memory usage

Image courtesy of Open Clip Art Library
I previously found out that you can pretty easily rewrite url's for Squid. Today I noticed Squid launches a bunch of child processes to do the url rewriting. I got curious about the memory usage. I had a feeling that the Perl version would not consume as much memory as PHP and it appears it is indeed so.

I tested both PHP and Perl versions to see how much memory they would consume. First I checked the memory usage of the PHP version after browsing a bit. Then I changed squid.conf to use the Perl version and again checked the memory usage. Squid had just launched one googlerewriter child process, so I browsed some more and then checked again. I'm guessing Squid starts the processes when it actually needs them.(ps. Documentation confirmes this) Anyway some processes then appeared to have been launched.

Fields

MAJFL
Major page fault: The number of major page faults that have occurred with this process
TRS (kB)
Text resident set: The amount of physical memory devoted to executable code
DRS (kB)
Data resident set: The amount of physical memory devoted to other than executable code
RSS (kB)
Resident set size: The portion of a process's memory that is held in RAM. The rest of the memory exists in swap or the filesystem (never loaded or previously unloaded parts of the executable).

Even for a tiny script php version caused some page faults and it's using way too much memory for the task it's doing.

PHP

$ ps faxv
  PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
13098 ?        Ss     0:00      0  5047 12668  2608  0.0 /usr/sbin/squid -a 3128 -f /etc/squid/squid.conf
13100 ?        S      0:01      5  5047 35240 25052  0.4  \_ (squid-1) -a 3128 -f /etc/squid/squid.conf
13101 ?        S      0:00      0     5  3942   992  0.0      \_ (logfile-daemon) /var/log/squid/access.log
13102 ?        S      0:00      1     2  3793   740  0.0      \_ (unlinkd)
13109 ?        S      0:00     50  3385 43962  7812  0.1      \_ /usr/bin/php /usr/local/bin/googlerewriter.php
13111 ?        S      0:00      0  3385 43962  7816  0.1      \_ /usr/bin/php /usr/local/bin/googlerewriter.php
13115 ?        S      0:00      0  3385 43962  7816  0.1      \_ /usr/bin/php /usr/local/bin/googlerewriter.php
13116 ?        S      0:00      0  3385 43962  7812  0.1      \_ /usr/bin/php /usr/local/bin/googlerewriter.php
13117 ?        S      0:00      0  3385 43962  7816  0.1      \_ /usr/bin/php /usr/local/bin/googlerewriter.php

$ top
  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND
15552 squid     20   0 47348 7812 5428 S   0.0  0.1   0:00.05 googlerewriter.
15735 squid     20   0 47348 7816 5428 S   0.0  0.1   0:00.03 googlerewriter.
15736 squid     20   0 47348 7816 5428 S   0.0  0.1   0:00.03 googlerewriter.
15741 squid     20   0 47348 7816 5428 S   0.0  0.1   0:00.03 googlerewriter.
The resident set size of the Perl version is 31% that of the PHP version, or in other words the PHP version is using 3 times as much memory per process. By using the Perl version you'd save at least 5.2MiB. Not that this matters much on my current proxy server, but for an embedded server it would matter.

Perl

$ ps faxv
  PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
13382 ?        Ss     0:00      0  5047 12668  2608  0.0 /usr/sbin/squid -a 3128 -f /etc/squid/squid.conf
13384 ?        S      0:01      0  5047 37988 25308  0.4  \_ (squid-1) -a 3128 -f /etc/squid/squid.conf
13387 ?        S      0:00      0     5  3942   992  0.0      \_ (logfile-daemon) /var/log/squid/access.log
13388 ?        S      0:00      0     2  3793   740  0.0      \_ (unlinkd)
13396 ?        S      0:00      0     3  8700  2460  0.0      \_ /usr/bin/perl /usr/local/bin/googlerewriter.pl
13426 ?        S      0:00      0     3  8700  2376  0.0      \_ /usr/bin/perl /usr/local/bin/googlerewriter.pl
13427 ?        S      0:00      0     3  8700  2372  0.0      \_ /usr/bin/perl /usr/local/bin/googlerewriter.pl
13429 ?        S      0:00      0     3  8700  2460  0.0      \_ /usr/bin/perl /usr/local/bin/googlerewriter.pl
13430 ?        S      0:00      0     3  8700  2460  0.0      \_ /usr/bin/perl /usr/local/bin/googlerewriter.pl
13431 ?        S      0:00      0     3  8700  2460  0.0      \_ /usr/bin/perl /usr/local/bin/googlerewriter.pl

$ top
  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND
13396 squid     20   0  8704 2460 1724 S   0.0  0.0   0:00.19 googlerewriter.
13429 squid     20   0  8704 2460 1724 S   0.0  0.0   0:00.03 googlerewriter.
13430 squid     20   0  8704 2460 1724 S   0.0  0.0   0:00.02 googlerewriter.
13431 squid     20   0  8704 2460 1724 S   0.0  0.0   0:00.02 googlerewriter.
13426 squid     20   0  8704 2376 1716 S   0.0  0.0   0:00.04 googlerewriter.
13427 squid     20   0  8704 2372 1716 S   0.0  0.0   0:00.03 googlerewriter.

No comments:

Tip me if you like what you're reading