As your web site grows in popularity, you may notice that pages take longer to load, or worse, pages may fail to load at all if you web server is over capacity. These are symptoms of a lack of performance. This chapter discusses options you can use to get the best performance from your Perforce Chronicle site, and provides some feature-specific recommendations when horizontal scaling is employed.
The options are:
With a single web server, the options for improving performance are limited; to host your Chronicle site, it needs to run the web server software, the Perforce server software for content storage, and Chronicle itself.
Chronicle includes the P4PHP extension, which provides a persistent connection to the Perforce server; it eliminates the overhead of establishing a connection for each operation required to retrieve or change content. Chronicle automatically uses APC when it is installed to cache full pages. Using P4PHP and APC together can nearly double the performance of Chronicle.
When a single web server becomes insufficient to handled the popularity of your site, the next step is to add additional web servers, a technique known as horizontal scaling. The largest web-based companies, such as Google, Amazon, and Facebook, all use thousands or even hundreds of thousands of web servers to host their sites.
One of the challenges of adding web servers, aside from the cost of the hardware, is configuring the hardware so that each web server is serving the same content. To achieve this, each web server needs to communicate with a common Perforce server, and this typically means running the Perforce server software on its own machine.
The cache strategy also needs to change when multiple web servers are employed. If each web server has its own independent cache, it is not possible to guarantee delivery of the same content when content is updated. The solution here is to use a shared cache. Unfortunately, a shared cache is usually slower than the file-based cache each individual web server could use. Chronicle can be configured to use the memory-based cache called memcached. Common practice is to configure memcached to run on each of the web servers, as web servers often have memory to spare, but the best performance can be achieved with dedicated memcached servers.
Scaling the performance of your web site to meet demand can require a significant amount of hardware. This increased demand may be short lived, from a few seconds or minutes where you may decide that the best action is no action, to a few days or weeks. The longer the increased demand lasts, the more tempting it is to deploy additional hardware. When the demand falls off, you then have hardware sitting idle.
Cloud computing services, such as Amazon's Web Services, allow you to spin up additional server instances as needed with only a few minutes' delay. If the demand drops, you simply remove server instances as appropriate.