Administrators/Optimize performance/Webserver/en

Use HHVM
Facebooks HipHop Virtual Machine implements a highly optimizing virtual machine for PHP code that is much faster than the official PHP interpreter. Tests have shown that HHVM is ca. 2.5 times faster than the combination of PHP interpreter and APC when used for Arcavias. As the Arcavias Core fully supports HHVM, this can give your shop a tremendous performance boost. In a VM running on a hardware from 2010, we achieved response times of around 130ms for uncached list and detail views and ca. 80ms for both views when cached!

Note: HHVM isn't 100% compatible with the official PHP interpreter yet but gets closer with every release. This means that not every code will run without problems in HHVM and some PHP modules are not yet available for HHVM. If you use the Arcavias Core as part of another application, please check if that application will work with HHVM first!

Use PHP 5.4 or later
The core PHP developers improved the performance a lot in PHP 5.4 and later versions. You may see a speed increase of around 30% compared to PHP 5.3. Furthermore, PHP 5.5 integrates its own byte code cache so APC isn't required for this any more. If you cant use HHVM for your shop, you can still get much better results by using PHP 5.4 or 5.5.

Note: Even if PHP 5.5 implements a byte code cache, it doesn't contain a cache for storing configuration values and translated strings! Arcavias benefits a lot from caching this data and Arcavias is ca. 30% faster when using PHP 5.4 and APC when compared to PHP 5.5 without APC.

Use APC
Arcavias is a very powerful and flexible, object-oriented framework and consists of many PHP files. Remember that PHP is an interpreted language and without APC, each file is parsed by every new request. That leads to a large amount of time that is used for translating the files to byte code and has a very bad influence on the overall performance. In fact, it's likely to have a 3-4 times worse performance compared to the same server with APC.

Note: If the configuration values are cached within APC or any other memory based cache, you have to clear this configuration cache (it's named "user" cache in APC) each time you change a configuration value or you update the code. Otherwise, your application will behave not the way you expect or even exit with errors.

To get the maximum performance, you can disable the checks to look for updated PHP files. This will save a lot of stat calls and is especially useful when your storage (e.g. hard disk) is slow. Updated files will then only be used after the APC cache is cleared or the file is removed from the cache manually.

php_admin_value apc.stat 0

If your server must answer many requests in parallel for an Arcavias based application, you should disable apc.slam_defense. It's enabled by default and can lead errors in the application during startup of the web server. Make sure that apc.write_lock is enabled instead (usually the default setting).

php_admin_value apc.slam_defense 0 php_admin_value apc.write_lock 1

Don't store the source code on NFS shares
NFS (network file system) is a way to access files on a remote server over a network. It's great for sharing files between different hosts and is also sometimes used to provide a common installation for web applications. Nevertheless, it has one important drawback even if files are cached in the client cache: Often files have to be fetched from the remote server and compared to a local hard disc, this is painfully slow. Tests have shown that serving a request takes 3-4 times longer when the Arcavias files are located on a NFS server instead of a local hard disc.

If you have to use NFS for some reasons, the APC byte code cache can help to mitigate the problem. Make sure your APC installation uses this configuration:

php_admin_value apc.stat 0

This disables checking the modification time of each file at each request and significantly improves performance on NFS shares by ca. 50%. See the PHP documentation for more information. Also be aware of the fact that you have to clear the APC system cache before code changes will have any effect and you should activate this setting only on production servers where the code changes rarely.

Adapting PHP's realpath cache size can also help to reduce the performance loss on NFS.

Adapt PHP's realpath cache size
The Arcavias core consists of a lot of files and include_once will check some information for each included file via the lstat system call. On fast (local) file systems you won't notice that there are a lot of lstat calls because your hard disk is probably fast enough so they doesn't slow down the application.

Things are getting different with remote file systems like NFS. If you can't avoid using NFS, you can at least use PHP's realpath cache to reduce the number of lstat calls that have to be sent over the wire. There's an article with more details related to this problem available. The necessary settings for your host are:

php_admin_value realpath_cache_size 128K php_admin_value realpath_cache_ttl 3600

A cache size of 128 KiB seems to be a good start as the Arcavias demo uses up to 80 KiB of the cache. You can check the actual yourself which is printed at end of the HTML source code for each request to the demo frontend. The value that fits best for you depends on the application which uses the Arcavias framework. If the application also consists of a lot of files, you may need a higher value. To see the actually used cache, you can call a simple script from your browser that contains:

<?php echo realpath_cache_size;

James Hayden has written an article about how to optimize PHP's realpath cache size settings. As he states, the cache should be as big as necessary but as small as possible because the cache is per process. The TTL value (the time in seconds after which the file informations will be retrieved again from the file system) can be set to a high value if the permissions of the files doesn't change (which shouldn't be the case). The PHP documentation contains also a section about the realpath cache settings.

Serve static content from caches
A web server needs much longer to serve static files than a caching proxy server like Squid. Files fitting into the main memory of the proxy server are sent to the clients almost instantly and the web server can concentrate on executing the PHP scripts that generate the HTML source code.

If your visitors are from differenct continents, you should think about using a content delivery network (CDN). The static files like images, CSS and JavaScript files can be served much faster by a cache that is geographically nearby the visitor because the latency for the requested files is small. The difference can be up to several seconds for the page load time.