-

Optimize performance

You may think your site is too small for performance optimization... it is never true... with the nature of the web, it is always good to be ready for any inflow of visits after you get linked from a popular website. Further, the more responsive your site is, the more people will appreciate their visit (including you). A nonresponsive site will take more time to be indexed, more likely to be forgotten by users who will be less likely to come back. As a matter of fact, google did a study and if the web page takes more than 5 seconds to load, 25% people will leave the page... so if your page is taking too long to load, you are losing people already.

Optimization tip: Optimize database requests

Relational databases rock when it comes to extracting data but they are very resource hungry. Here are a few things you can do
  • Indices - I have seen cases where adding a few indices has turned a site crawling on its knees to a fast responsive web site
  • cache queries in computed form/ ready to serve form
  • examine the possibility of using flat files or non relational databases like noSQL... especially if data is read only with simple format and query rarely changes
  • consider grouping multiple insert statements into one if your database supports it
  • consider optimizing queries - if for example you do not need to have a join, do not include it
  • consider using transactions when multiple database requests... all transactions sent at once. I once cut down the importing of a huge database by at least one order of magnitude by encapsulating multiple queries into a transaction
  • consider database replication - sometimes by having more than one server that replicate, you can optimize performance. This works especially well in intranets when users are grouped in a limited amount of sites.
  • consider stored procedures... they will increase load on the database server but decrease data sent back and forth between application and db server. also, it happens on the server so, happens on the raw data.

Optimization tip: Consider a daemon process

Sometimes you need to access data or resources with a long init process. By offloading this to a daemon that stays in memory and optimizes calls, some long processes can make the query instantaneous.

Optimization tip:Consider a cron job

Some tasks such as caching, prefetching data can be offloaded to a cron job that would run at regular intervals, preferably to offpeak times

Optimization tip: Consider using specialized servers

Search engines are a good example. Some machines will crawl, others will index the data and others will serve the data... If you have limited web power resources such as a VPS. Consider running some processes at home where having a powerful machine is free for you.

Optimization tip: Optimize code

  • Consider JIT compiler or compiler for interpreted languages. Compilers such as hiphop for php allow huge performance savings and decreasing memory footprint. Sometimes it may make sense to rewrite one part of code into a lower level language such as C
  • Delay framework usage for simple stuff... frameworks allow very cool things such as MVC and simplify code reuse but they have a performance cost
  • See if you can optimize the algorithms to use less resources.  There are times where object oriented is more appropriate and allows to swap in/ swap out new algorithms on the fly
  • Prune out unused code regularly
  • make sure there are no race conditions and identify places where you can speed up function calls. Once, an application was very slow simply because it repeatedly queried the same hostnames multiple times. By identifying duplicate calls and reusing results, the site was much faster
  • Check if network factors such as latencies, error rates need improvement (Once a whole site was brought down by a faulty ethernet cable)

Optimization tip: Load balancing

  • consider load balancing if necessary - When more traffic comes, sometimes it makes sence to offload the work to more than one server. Many situations exist, among others cluster and round robin solutions. Having more than one server available has the added benefit of allowing for failsafe scenarios if one server goes down and also scaling more easily by adding servers as needed.

Optimization tip: cache content

RSS feeds, databases and fetched data like social network interaction can bring lots of power to your site... but it can really slow your website. Make sure the cache refreshes enough yet refresh as little as possible (in some cases data can be cached for days). Either in a simple way or through specialized processes like memcache. This particularly holds true for anonymous access of the landing page which often contains non user specific content.

Optimization tip: Alternative servers

servers nginx like nginx can instantly boost your performance (though to be fair apache has done efforts to catch up). Consider alternatives to all server processes.

Optimization tip:  consider different/ simpler programs

Some great software is out which can do tons of stuff... yet at the cost of added resources. If all you need is a picture gallery, consider a simple gallery program and not a big complicated CMS that will have a picture feature

Optimization tip: consider static pages

Many times, dynamic pages are necessary... but sometimes, a simple html file will do, maybe offloading the dynamic part to a script

Optimization tip: Separate Static content

It is good to host static content on a separate server. Even if your server is under heavy load, the images/ css will load faster faster

Optimization tip: Only run the services needed

On development machines, it is tempting to enable tons of services that you will not use for fun and wow factor... on production machines, run only what is needed. Not only will your server be more responsive but it makes your installation more secure with less security holes.

Optimization tip: optimize images, css, preload

  • Order of HTML matters, make sure you load the important parts first in the page.
  • If many images, preload images if possible, it will make your site feel more responsive
  • if you can compress the css and/or optimize it it is good
  • consider offloading to javascript client side for more responsive UI (thinks like validation, dependent combos, auto complete)
  • consider reloading partially page with AJAX... more responsive, less traffic
  • with complex javascript, make sure your javascript ui remains responsive, only do the needed stuff upfront or page may become  un responsive
  • If possible, avoid multiple copies of the same file (image, music, etc) across pages... consumes more bandwidth, makes site less responsive and makes maintainance harder
  • If your page will take a long time, make sure at least something displays
Good luck in making sites more responsive