Chamilo : Optimization Guide

Documentation > Optimization Guide

In seldom cases, you will need to start looking into efficiency issues with Chamilo. This guide is a work in progress intended to help administrators optimize their Chamilo installation.

Contents

  1. Using xCache or APC
  2. Slow queries
  3. Indexes caching
  4. Sessions directories
  5. Users upload directories
  6. Zlib compressed output
  7. Memory considerations for high numbers of users

1. Using xCache or APC

See xCache's website for summary documentation.
Set your xcache.ini configuration (/etc/php5/conf.d/xcache.ini) to match your system. For example, you *could* have something like this (intentionally hiding comments here):
xcache.shm_scheme =        "mmap"
xcache.size  =                32M
xcache.count =                 2
xcache.slots =                8K
xcache.ttl   =                 0
xcache.gc_interval =           0
xcache.var_size  =           16M
xcache.var_count =            16
xcache.var_slots =            8K
xcache.var_ttl   =            60
xcache.var_maxttl   =        300
xcache.var_gc_interval =     300
xcache.test =                Off
xCache will feel useless until you actually start to put some variables in cache. If you're showing the "Who is online" counter, that's one of the best item there is to implement xCache.
For example, you could implement it this way (in main/inc/lib/banner.lib.php):
$xc = function_exists('xcache_isset');
$number = 0;
if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting('showonline', 'users') == 'true' AND $user_id) OR (api_get_setting('showonline', 'course') == 'true' AND $user_id AND $course_id)) {
  if ($xc && xcache_isset('campus_chamilo_org_whoisonline_count_simple')) {
    $number = xcache_get('campus_chamilo_org_whoisonline_count_simple');
  } else {
    $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
    xcache_set('campus_chamilo_org_whoisonline_count_simple',$number);
  }
}
$number_online_in_course = 0;
if(!empty($_course['id'])) {
  if ($xc && xcache_isset('campus_chamilo_org_whoisonline_count_simple_'.$_course['id'])) {
    $number_online_in_course = xcache_get('campus_chamilo_org_whoisonline_count_simple_'.$_course['id']);
  } else {
    $number_online_in_course = who_is_online_in_this_course_count(api_get_user_id(), api_get_setting('time_limit_whosonline'), $_course['id']);
    xcache_set('campus_chamilo_org_whoisonline_count_simple_'.$_course['id'],$number_online_in_course);
  }
}
Note that, as xCache is a shared caching system, it is very important to prefix your variables with a domain name or some kind of identifier, otherwise it would end up in disaster if you use a shared server for several portals.

An optional additional caching mechanism you may use is the realpath_cache_size and realpath_cache_ttl php.ini parameters. See the PHP documentation for more details.

If you prefer using APC, you can use the same kind of trick as above, just changing the code a little:
    $xc = function_exists('apc_exists');
    $number = 0;
    if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting('showonline', 'users') == 'true' AND $user_id) OR (api_get_setting('showonline', 'course') == 'true' AND $user_id AND $course_id)) {
        if ($xc) {
            $apc = apc_cache_info(null,true);
            $apc_end = $apc['start_time']+$apc['ttl'];
            if (apc_exists('my_campus_whoisonline_count_simple') AND (time() < $apc_end) AND apc_fetch('my_campus_whoisonline_count_simple') > 0 ) {
                $number = apc_fetch('my_campus_whoisonline_count_simple');
            } else {
                $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
                apc_clear_cache();
                apc_store('my_campus_whoisonline_count_simple',$number,15);
            }
        } else {
                $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
        }
        $number_online_in_course = 0;
        if (!empty($_course['id'])) {
            if ($xc) {
                $apc = apc_cache_info(null,true);
                $apc_end = $apc['start_time']+$apc['ttl'];
                if (apc_exists('my_campus_whoisonline_count_simple_'.$_course['id']) AND (time() < $apc_end) AND apc_fetch('my_campus_whoisonline_count_simple_'.$_course['id']) > 0) {
                    $number_online_in_course = apc_fetch('my_campus_whoisonline_count_simple_'.$_course['id']);
                } else {
                    $number_online_in_course = who_is_online_in_this_course_count($user_id, api_get_setting('time_limit_whosonline'), $_course['id']);
                    apc_store('my_campus_whoisonline_count_simple_'.$_course['id'],$number_online_in_course,15);
                }
            } else {
                $number_online_in_course = who_is_online_in_this_course_count($user_id, api_get_setting('time_limit_whosonline'), $_course['id']);
            }
        }
     ...

2. Slow queries

Enable slow_queries in /etc/mysqld/my.cnf, restart MySQL then follow using sudo tail -f /var/log/mysql/mysql-slow.log

In Chamilo 1.9 in particular, due to the merge of all databases into one, you might experience performance issue if you have many learning paths with many items in them.
To solve this performance issue, you can execute the following queries manually in your database:
ALTER TABLE lp_item ADD INDEX idx_c_lp_item_cid_lp_id (c_id, lp_id);
ALTER TABLE lp_item_view ADD INDEX  idx_c_lp_item_view_cid_lp_view_id_lp_item_id (c_id, lp_view_id, lp_item_id);
These will be available in Chamilo 1.10 directly, but we cannot put them into Chamilo 1.9 from now on for organizational reasons.

3. Indexes caching

One good reference: MySQL documentation on multiple key caches

4. Sessions directories

php_admin_value session.save_path 1;/var/www/test.chamilo.org/sessions/

5. Users upload directories

Create 10 directories inside the main/upload/users directory (from 0 to 9) and update your admin settings. This has to be done at install & configuration time, otherwise you might loose user data (or have to write a script for data distribution).

6. Zlib compressed output

Although this will not make your server faster, compressing the pages you are sending to the users will definitely make them feel like your website's responses are a lot faster, and thus increase their well-being when using Chamilo.

Zlib output compression has to be set at two levels: PHP configuration for PHP pages and Apache for images and CSS.

To update the PHP configuration (either in php.ini or in your VirtualHost), use the zlib.output_compression. If you set this inside your Apache's VirtualHost, you should use the following syntax.
php_value zlib.output_compression 1

Configuring your Apache server to use output compression is a bit trickier. You have to use the mod_deflate module to do it. Your configuration should look like something like this (please read the corresponding documentation before implementing in production).
Easy mode:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
or, for every content type (dangerous) you can put the following inside a location or directory block:
SetOutputFilter DEFLATE

Advanced mode:

# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
 

Don't have time or resources to optimize your Chamilo installation yourself? Hire an official Chamilo provider and get it sorted out professionally by specialists. Valid XHTML 1.0 Transitional Valid CSS

Memory considerations for high numbers of users

Some administration scripts *have to* handle lists of all users, and this might have a considerable impact on portals with very high numbers of users. For example, the main/admin/add_users_to_session.php script that handles the registration of users into a specific session, if used with the (non-default) full list of users, will devour about 3KB per user, which, for 100,000 users, translates into the need for around 300MB of RAM just to show this page, and to around 3GB for 1,000,000 users.
This mode is not loaded by default, but could still be selected, leading to a "Fatal error: Allowed memory size ... exhausted" message.
The only non-scripted solution here is to allow for the corresponding amount of RAM for your PHP configuration (memory_limit = 300M) or your specific VirtualHost if you use mod-php5 (php_value memory_limit 300M).

Authors