怎样优化和加速你的vps server

2012年7月18日 | 分类: HowTo | 标签: ,

Increasing the speed with which a page loads involves aspects (i) the server configuration and (ii) the web pages (or wordpress) configuration.

First, lets look at how we can speed up the time that it takes for the server to respond.

(i) Using nginx instead of apache:

My personal experience has been that nginx responds to page requests faster than apache and consumes lesser memory. While this may not be noticeable in normal times, it becomes a crucial factor when there is a huge traffic rush towards your site. When I post something, I also send out an email to all the subscribers and also tweet about it. If the topic is interesting, there is usually a huge surge of traffic within just a few moments of posting. When I was using apache, my site would frequently crawl and collapse. However, with nginx, my site remains cool as a cucumber even with thousands on concurrent visitors onboard.

(ii) Using memcache:

Memcache reduces database load by caching database objects. I use it with nginx and it works very well. Memcache is used by all the big-ticket sites like Facebook, Youtube, Twitter etc and so there is no reason why you should not have it on your site even if you get only a fraction of the traffic that the big sites get.

(iii) Proper configuration of nginx, php etc:

One can spare oneself of the botheration of tweaking the configuration by using a pre-configured auto-installer. While there are a number of auto-installers available, my personal favourite is centminmod which loads nginx, php, APC (or xcache), memcache, Mysql and Mariadb. It is nicely configured to work straight out of the box and consumes very less memory (RAM). My 128 MB RAM VPS is powered by centminmod. The other auto-installers like lnmp.org and its variations in rockia.com and ruchirablog.com are also noteworthy for their ease of use and extent of efficiency.

(iv) Optmize Database (through phpmyadmin):

The mysql database gets jumbled up frequently, slowing down the response time. There is a very easy way to optimize the mysql database with phpmyadmin. Just one click of the button and it is done.

It can also be done through the command line.

Now, lets look at how we can speed up the wordpress site.

(v) Cache plugin: Cache plugins are absolutely essential because they convert the php pages into plain html pages and avoid the server having to be asked to serve the page.

The best cache plugin for wordpress is Quick Cache because it does not require any complicated configuration and is ready to use. The other popular cache plugins for wordpress are WP Super Cache and W3 Total Cache.

By using any of the cache plugins, you will notice an immediate quickness in the speed with which the pages are loaded. This enhances visitor experience and also leads to better search rankings.

(iv) Optmize Database (through DB Optimizer plugin):

An easier way to optimize the database (if you don’t want to do it through phpmyadmin) is the DB Optimzer plugin. The advantage of this plugin over phpmyadmin is that it can also remove post revisions, trash posts, spam comments apart from optimizing the database tables.

(v) Cloudflare CDN:

If you have visitors coming in from several countries, Cloudflare’s CDN (Content Delivery Network) is a must-have. Cloudflare works by caching the web pages on their own servers and diverting traffic there instead of to your servers. The advantage is that visitors located closer to cloudflare’s servers will get served faster and the load on your server is reduced. Cloudflare has a free option that one must try.

The downside to cloudflare is that if the bulk of your visitors are local (relative to where your server is located), then diverting them to cloudflare’s servers may actually increase the response time and make your site seem slower.

The other CDNs are Amazon Cloudfront and MaxCDN.

(vi) Avoid Sharethis and Addthis plugins:

One must avoid plugins that need to communicate with their own servers to work. Sharethis and Addthis need to communicate with their respective servers to store data on how many requests your site has received. The problem with this is that if the remote site is down or slow, it directly impacts the load time of your site.

(vii) Use low resolution images: High resolution images can take quite a while to load. WordPress offers the ideal solution for this. You can upload high-resolution images to your site but choose to show the thumbnails or mid-size images in the post. A visitor who wants to see the full image has to click on the thumbnail to see it.

(viii) Avoid external comment systems: WordPress has an inbuilt comment system which is very efficient. External comments systems like Disqus & IntenseDebate increase load time without appreciable increase in efficiency.

  1. ryan
    2012年7月18日11:04

    有兴趣者可以将其翻译成中文

  2. xiaobao
    2012年7月18日11:14

    不错,不错,学习下 :心动: