server {
server_name domain.com;
rewrite ^(.*)$ http://www.domain.com$1 permanent;
}
This entry was written by , posted on March 20, 2009 at 7:12 am, filed under http and tagged nginx. Leave a comment or view the discussion at the permalink.
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 , 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 , 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 , 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 , 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.