While monitoring a http/php server, I needed to do some statistics about php-cgi memory usage.
Playing with memory_limit in PHP, we wanted to know the average memory usage per php-cgi process. This is easily calculated with our best friend awk.
First, get the number of php running processes:
# ps aux | grep php-cgi | grep -v grep | wc -l
126
Then, use awk to calculate the average memory usage for these processes:
# ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'
33987.8
The number used in the calculation is the field RSS given by ps. The ps manual page says:
rss: resident set size, the non-swapped physical memory that a task has used (in kiloBytes)
You can also calculate the total memory used by all php-cgi processes:
# ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s;}'
4302028
If you need to watch the trend of this average memory usage, a little shell loop does the trick:
# while [ 1 ]; do ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'; sleep 2; done
34401.3
34405.1
34408.4
34409.4
34414.2
34417
This entry was written by CharlyBr, posted on March 13, 2009 at 4:14 pm, filed under Benchmarks, Command line, Monitoring and tagged awk, memory, php, shell. Leave a comment or view the discussion at the permalink.
While reading articles about optimization, I read about the accf_http module.
The man page of the module is here, where you can read:
The utility of accf_http is such that a server will not have to context switch several times before performing the initial parsing of the request.
To load this module, use the following command:
# kldload accf_http
To load it at boot time, add the following line in /boot/loader.conf:
accf_http_load="YES"
To check if the module is loaded, use the command kldstat:
# kldstat
Id Refs Address Size Name
1 4 0xc0400000 906518 kernel
2 1 0xc0d07000 6a32c acpi.ko
3 1 0xc5e65000 2000 accf_http.ko
This entry was written by CharlyBr, posted on March 12, 2009 at 6:04 am, filed under Optimization and tagged FreeBSD. Leave a comment or view the discussion at the permalink.
On some of freshly installed servers (Debian Etch), I encountered these error messages in /var/log/munin/munin-node.log:
Use of uninitialized value in eval {block} exit at /usr/sbin/munin-node line 456, <CHILD> line 8.
What a great error message
After digging into Google results, I found it was just a problem with host_name variable in the configuration. Default value is hostname.localdomain. I’ve replaced it with a valid hostname and it works!
This entry was written by CharlyBr, posted on March 11, 2009 at 8:51 am, filed under Monitoring and tagged debian, etch, munin. Leave a comment or view the discussion at the permalink.
If you encounter this warning message under Linux:
2009/03/09 21:23:19 [warn] 26827#0: 4096 worker_connections are more than open file resource limit: 1024
A solution is to use the command ulimit in nginx start script, just before lunching nginx:
[...]
ulimit -n 65536
[...]
This entry was written by CharlyBr, posted on March 9, 2009 at 10:30 pm, filed under Distro, http and tagged debian, linux, nginx, ulimit. Leave a comment or view the discussion at the permalink.
If like me you just have upgraded your Debian system to Lenny, you probably encounter the following warnings while launching perl:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "fr_FR.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
To get rid of these annoying messages, I’ve just reconfigured locales with the command:
# dpkg-reconfigure locales
Choose your locale when you’re asked for your “Default locale for the system environment”.
You should have a message like:
Generating locales (this might take a while)...
en_US.UTF-8... done
Generation complete.
Then, logout, login and your perl installation works fine!
This entry was written by CharlyBr, posted on February 24, 2009 at 11:59 am, filed under Distro and tagged debian, lenny, locales, perl. Leave a comment or view the discussion at the permalink.
I encountered a problem last week with cron. crond was running but the jobs seems to not work. After debugging the crontab, I saw that on one job, the username was missing.
Nothing was written in the logs to say that there was a problem.
To avoid future problems, I wrote an alert for monit.
In my crontab, I’ve added the following job:
*/5 * * * * root touch /tmp/check_cron
This job will update the timestamp of the file /tmp/check_cron every 5 minutes.
And in monit configuration (/etc/monit/monitrc), I’ve added the following alert:
check file check_cron with path /tmp/check_cron
if timestamp > 10 minutes then alert
If the crontab is not working, monit will send you an alert email like this:
Subject: monit alert -- Exists check_cron
Exists Service check_cron
Date: Thu, 27 Nov 2008 21:21:53 +0100
Action: alert
Host: myhost
Description: 'check_cron' file exist
Your faithful employee,
monit
This entry was written by CharlyBr, posted on November 27, 2008 at 10:27 pm, filed under Monitoring and tagged cron, monit. Leave a comment or view the discussion at the permalink.
As read in Diamond Notes, Amazon is moving into CDN market with CloudFront.
Some Content Delivery Network providers
This entry was written by CharlyBr, posted on November 25, 2008 at 11:46 pm, filed under http and tagged CDN. Leave a comment or view the discussion at the permalink.
If you need to install your gems without extra documentation, use flags –no-rdoc and –no-ri
Example:
$ gem install --no-rdoc --no-ri rails
This entry was written by CharlyBr, posted on November 21, 2008 at 4:18 pm, filed under Ruby and tagged gem. Leave a comment or view the discussion at the permalink.
When adding new virtual hosts in your nginx configuration file, you can experience this error message:
# nginx -t
2008/11/13 09:37:03 [emerg] 12299#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
2008/11/13 09:37:03 [emerg] 12299#0: the configuration file /etc/nginx/nginx.conf test failed
server_names_hash_bucket_size controls the maximum length of a virtual host entry (ie the length of the domain name).
In other words, if your domain names are long, increase this parameter.
You need to add this flag in the http context:
http {
server_names_hash_bucket_size 64;
...
}
After increasing the value, test your configuration file and reload nginx:
# nginx -t
2008/11/13 09:48:06 [info] 12315#0: the configuration file /etc/nginx/nginx.conf syntax is ok
2008/11/13 09:48:06 [info] 12315#0: the configuration file /etc/nginx/nginx.conf was tested successfully
# kill -HUP `cat /var/run/nginx.pid`
This entry was written by CharlyBr, posted on November 14, 2008 at 11:28 am, filed under http and tagged nginx. Leave a comment or view the discussion at the permalink.
Sun JRE is available in the non-free repository. You need to update your repositories configuration file (/etc/apt/sources.list).
Add the following line:
deb http://ftp.us.debian.org/debian/ etch main contrib non-free
Update apt with apt-get update command and you’re ready to install the JRE.
$ apt-get install sun-java5-jre
Check your java binary:
$ java -version
java version "1.5.0_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode, sharing)
This entry was written by CharlyBr, posted on November 13, 2008 at 1:07 pm, filed under Java and tagged debian, etch, Java, jre. Leave a comment or view the discussion at the permalink.
« Previous Entries
» Next Entries