Server performance category

Boost your nginx web server performance by rewriting favicon.ico requests correctly

Popular sites receive high concurrent web visitor requests and some clients send bad favicon.ico fetch requests. If you are running nginx you probably didn’t notice that, for example: /category/favicon.ico generate significant 404 errors in your server error log file, because this file is located only in root, e.g. /favicon.ico.

Every request for non-existent file takes some load and every 404 missing file error is usually logged into error_log file, unless you have disabled error logging. To forward all non-root favicon.ico requests to /favicon.ico you can set-up the following rewrite rule in nginx.conf file in the correct server{} location:

rewrite ^/(.*)/favicon.ico$ /favicon.ico last;

Voila. Restart the nginx daemon and you will see slightly decreased load on your box.

Comments

Nginx high performance proxy caching system

Nginx has been built with ncache in the core. It’s very fast and offers great performance. It works quite nicely – you install nginx as a front-end proxy server and forward all php queries to Apache back-end. Then you set-up nginx to cache response from Apache back-end to static files on a file system (or even RAM disk).

in http{} section please define the path to proxy cache, levels, keys_zone name, expire time in minutes and max size in megabytes:

proxy_cache_path /path/to/cache levels=1:2 keys_zone=staticfilecache:180m max_size=500m;
proxy_temp_path /path/to/proxy_temp;

Please note that proxy_cache_path and proxy_temp_path should be on the same file system.

proxy_cache_key “$scheme://$host$request_uri $do_not_cache”;
proxy_cache staticfilecache;

in server {} location setting you should define the following values/settings:

proxy_cache_valid 200 15m;

The above caching settings will cache all valid 200 response for 15 minutes.

Comments

Nginx worker_processes configuration and recommendations

From the many posts around the Internet and our own experience worker_processes value is recommended to be set to the number of cores your server has.
For example, if you have two dual core CPU you should set worker_processes 4;

Original worker_processes help from Nginx page:

worker_processes 4;

nginx has the ability to use more than one worker process for several reasons:

1. to use SMP
2. to decrease latency when workers blockend on disk I/O
3. to limit number of connections per process when select()/poll() is used

The worker_processes and worker_connections from the event sections allows you to calculate maxclients value:

max_clients = worker_processes * worker_connections

Comments

Installing high-performance Nginx for first time

I have been somewhat lazy nowadays (hey it’s a summer!), but I thought I need to post a quick guide about installing high performance Nginx daemon. It’s a super fast web serving daemon that is the best choice for static content serving at very high speeds. It requires small hardware resources and places very small load on the hardware.

Download the latest stable version 0.7.61 or fetch a newer version from nginx.net.

Installing nginx:
(depending on the required modules, I prefer to disable all modules that are not needed, for example if you do not wish to host SSL pages, don’t enable SSL and so on).

tar zxvf nginx-0.7.61.tar.gz
cd nginx-0.7.61
./configure

(you can also specify –prefix value if you wish to install nginx in a different folder)

Now you will need to configure nginx.conf file before firing up Nginx daemon.

For better security run Nginx under a non-privileged user:

user nobody;

For medium to high load sites I suggest increasing worker_processes to 5 to 15, or even more if your hardware allows it.

worker_processes 10;

To increase max allowed clients that can access your site increase worker_connections. A good value for start is 256 and higher if you have a more powerful hardware.

events {
worker_connections 512;
}

Please note! If you run a Nginx in reverse proxy configuration you will need to divide this value by 4 because two connections will be opened to client and two to the back-end. If you have worker_processes set to 10 and worker_connections set to 256, then max clients that can access your site will be worker_processes * worker_connections / 2, thus 10 * 512 / 2 becomes 2560 connections.

Now in http {} section you will need to define some settings like mime.types, default_type, log_format, access_log, sendfile, tcp_nopush, keepalive_timeout. That’s pretty self explaining. Just a quick note: Nginx requires very low hardware requirements for keeping keepalive connections active and it’s well know to take less than 30Mb of RAM for 10000 active keepalive connections. Make sure you have correctly calculated max client settings using the formulas above.

Now comes the server {} section were you define Listen to address, ports and custom settings, like redirects etc.

Example:

server {
listen      10.10.10.10:80;
server_name  localhost;

access_log  logs/host.access.log  main;

location / {
root   html;
index  index.html index.htm;
}

error_page  404              /404.html;

error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

10.10.10.10 IP is just an example, you will need to specify your allocated server IP.

I hope this quick guide helped you out a little. We will soon publish more in-depth guide about configuring Nginx.

Comments (2)

Monitoring your Linux server load

You can easily monitor your Linux server load using built-in bash commands like

w

free

top

However, many folks prefer sysstat package (can be downloaded here, or from your Linux distribution site) package that provides even further performance monitoring utilities:

iostat

sar

vmstat

——

Login into your Linux server shell and execute the above commands. iostat, sar, vmstat can be run like

vmstat 1 10

where 1 is the time between monitoring load, 10 is the count  how many times the data need to be read.

Comments

Linux server management and tuning services

Many of our blog readers ask if we offer tuning services and support remote server management. At this time we do not offer server management services and we do not offer blog tuning either. However, from time to time we work with a nice company called LinuxAdmin guys and they do high-load and critical blog set-up,  configuration,  load balancing, management and of course full optimization. So if you are looking for a quality and very affordable remote server management or Wordpress blog hosting and management company – contact LinuxAdmin and I am sure you guys can work something out.

Comments (3)

Digg effect vs Yahoo front page listing

Many website owners are dreaming about hundreds of thousands of web visitors and thousands in ad profits, but will your web site handle the load and keep up the file serving? Probably not.

Digg frontpage listing usually sends 120.000  to 170.000 web visitors in two to three hours. It depends for how long you are listed on Digg’s frontpage and what is the topic.  In over 95% of cases this will probably be too much for simple dedicated server – if you are hosting Wordpress blog with some plugins activated (that require some extra load) and without tuning the server box.

You can activate some caching plugins (wp-cache, wp-super-cache, 1blogcacher), configure more efficient content distribution (for example, use lightweight web daemon to serve static files), use less includes and optimize plugin code for performance. This will probably handle the Digg frontpage load.

What if you land Yahoo! frontpage listing? This will be a real challenge for your systems and system administrator. Yahoo! is very popular and if your site gets listed in frontpage they can easily “send you” a few million of web visitors. Once again, depends for how long the listing will stay on the front page. Yahoo! traffic burst will definitely make your web server unreachable and I am saying this with 99.9999% confidence. You need multiple servers to handle  the load and do load balancing, and of course have upstream bandwidth available to serve the content. You need to employ perfect caching architecture, preferable keeping the page 100% static and load it in the server memory for super fast serving to web visitors. If you read it from the hard drive – your servers will experience very high IO and load, thus slowing down web responses.

Last time when one of our client’s got listed on Yahoo! frontpage the site (actually a blog) got around ~900.000 unique visitor landings, over 200.000 visitors browsed site further reading other articles and comments.  The traffic burst from two web front-end servers serving the content was close to 195Mbps (2 x 100Mbps links were fully maxed out) and I am talking about serving HTML/PHP content, not the images from these servers.

This is why you need to plan architecture to be scalable (horizontally) and easily affordable. One server box will not make it even if you get top-notch mega box for 20k USD, period.

Comments (2)

Server virtualization vs dedicated server

I would still love to see virtualized server in a high bandwidth environment hosting a large site with thousands of concurrent connections. I guess there is not much use for very large sites to use virtualization unless it provides advanced features like:

  • live migration
  • fail-over
  • snapshots
  • load balancing

However, virtualization software with the above features usually cost thousands of dollars and it’s out of reach for many folks that need to make some bucks from own sites and still survive occasional Digg or Yahoo frontpage landings. Dedicated servers offer 100% performance and doesn’t have any overhead… unless of course you run many servers and want to consolidate hardware.

If you have a small site or site that doesn’t generate normal income don’t worry about virtualization and high-availability ;) You can still do high-availability without virtualization. For much less, err…. almost for free – you just need to pay for the hardware and someone to set-up and run the server farm for you.

Comments

Tuning tcp keepalive intervals for high performance

We are fine tuning sysctl network stack on Linux OS and  change keepalive intervals for much better “response” times and load. These settings are lowered on our all managed performance servers that do host large sites – Drupal, Wordpress and custom LAMP services.

Enter the following lines in /etc/sysctl.conf

net.ipv4.tcp_keepalive_probes = 2
net.ipv4.tcp_keepalive_intvl = 30

And execute “sysctl -p” to set these settings in real-time.

By default it’s for Linux (Fedora, Redhat, Centos):

net.ipv4.tcp_keepalive_probes=9
net.ipv4.tcp_keepalive_intvl = 75

Enjoy!

Comments (3)

Nginx performance settings

We are running Wordpress on our multi-platform cluster and this is what we use for performance settings in nginx.conf

worker_processes 20;

events {
worker_connections 20000;
use epoll;
}

worker_rlimit_nofile 25000;

Nginx is a front-end and for backend we use Apache, however we will soon try different set-up using different architectures. I will keep you posted!

The client servers are 5400 Series Intel XEONs with 8GB RAM running Linux and SATA hard drives.

Comments