optimization.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <html lang="en">
  2. <head>
  3. <meta charset="utf-8" />
  4. <title>Chamilo Optimization Guide</title>
  5. <link rel="stylesheet" href="../main/css/base.css" type="text/css" media="screen,projection" />
  6. <link rel="stylesheet" href="default.css" type="text/css" media="screen,projection" />
  7. <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h1>Chamilo 1.8.8.4 : Optimization Guide</h1>
  12. <a href="index.html">Documentation</a> &gt; Optimization Guide
  13. <p>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.</p>
  14. <h2><b>Contents</b></h2>
  15. <ol>
  16. <li><a href="#1.Using-XCache">Using xCache</a></li>
  17. <li><a href="#2.Slow-queries">Slow queries</a></li>
  18. <li><a href="#3.Indexes-caching">Indexes caching</a></li>
  19. <li><a href="#4.Sessions-directories">Sessions directories</a></li>
  20. <li><a href="#5.Users-upload-directories">Users upload directories</a></li>
  21. <li><a href="#6.Zlib-compression">Zlib compressed output</a></li>
  22. <li><a href="#7.High-numbers-memory">Memory considerations for high numbers of users</a></li>
  23. </ol>
  24. <h2><a name="1.Using-XCache"></a>1. Using xCache</h2>
  25. See <a href="http://xcache.lighttpd.net/">xCache's website</a> for summary documentation.<br />
  26. <ul>
  27. <li>On Debian/Ubuntu: sudo apt-get install php5-xcache</li>
  28. </ul>
  29. 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):
  30. <pre>
  31. xcache.shm_scheme = "mmap"
  32. xcache.size = 32M
  33. xcache.count = 2
  34. xcache.slots = 8K
  35. xcache.ttl = 0
  36. xcache.gc_interval = 0
  37. xcache.var_size = 16M
  38. xcache.var_count = 16
  39. xcache.var_slots = 8K
  40. xcache.var_ttl = 60
  41. xcache.var_maxttl = 300
  42. xcache.var_gc_interval = 300
  43. xcache.test = Off
  44. </pre>
  45. 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.<br />
  46. For example, you could implement it this way (in main/inc/banner.inc.php):<br />
  47. <pre>
  48. $xc = function_exists('xcache_isset');
  49. $number = 0;
  50. if ($xc &amp;&amp; xcache_isset('campus_chamilo_org_whoisonline_count_simple')) {
  51. $number = xcache_get('campus_chamilo_org_whoisonline_count_simple');
  52. } else {
  53. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  54. xcache_set('campus_chamilo_org_whoisonline_count_simple',$number);
  55. }
  56. $number_online_in_course = 0;
  57. if(!empty($_course['id'])) {
  58. if ($xc &amp;&amp; xcache_isset('campus_chamilo_org_whoisonline_count_simple_'.$_course['id'])) {
  59. $number_online_in_course = xcache_get('campus_chamilo_org_whoisonline_count_simple_'.$_course['id']);
  60. } else {
  61. $number_online_in_course = who_is_online_in_this_course_count(api_get_user_id(), api_get_setting('time_limit_whosonline'), $_course['id']);
  62. xcache_set('campus_chamilo_org_whoisonline_count_simple_'.$_course['id'],$number_online_in_course);
  63. }
  64. }
  65. </pre>
  66. 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.<br />
  67. <br />
  68. An optional additional caching mechanism you may use is the realpath_cache_size and realpath_cache_ttl php.ini parameters. See <a href="http://php.net/manual/en/ini.core.php">the PHP documentation</a> for more details.
  69. <hr />
  70. <h2><a name="2.Slow-queries"></a>2. Slow queries</h2>
  71. Enable slow_queries in /etc/mysqld/my.cnf, restart MySQL then follow using sudo tail -f /var/log/mysql/mysql-slow.log
  72. <hr />
  73. <h2><a name="3.Indexes-caching"></a>3. Indexes caching</h2>
  74. One good reference: <a href="http://dev.mysql.com/doc/refman/5.1/en/multiple-key-caches.html">MySQL documentation on multiple key caches</a><br />
  75. <hr />
  76. <h2><a name="4.Sessions-directories"></a>4. Sessions directories</h2>
  77. php_admin_value session.save_path 1;/var/www/test.chamilo.org/sessions/
  78. <hr />
  79. <h2><a name="5.Users-upload-directories"></a>5. Users upload directories</h2>
  80. 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 &amp; configuration time, otherwise you might loose user data (or have to write a script for data distribution).
  81. <hr />
  82. <h2><a name="6.Zlib-compression"></a>6. Zlib compressed output</h2>
  83. 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.<br /><br />
  84. Zlib output compression has to be set at two levels: PHP configuration for PHP pages and Apache for images and CSS.<br /><br />
  85. To update the PHP configuration (either in php.ini or in your VirtualHost), use the <a href="http://php.net/manual/en/zlib.configuration.php">zlib.output_compression</a>. If you set this inside your Apache's VirtualHost, you should use the following syntax.
  86. <pre>
  87. php_value zlib.output_compression 1
  88. </pre>
  89. <br />
  90. Configuring your Apache server to use output compression is a bit trickier. You have to use <a href="http://php.net/manual/en/zlib.configuration.php">the mod_deflate module</a> to do it. Your configuration should look like something like this (please read the corresponding documentation before implementing in production).<br />
  91. Easy mode:
  92. <pre>
  93. AddOutputFilterByType DEFLATE text/html text/plain text/xml
  94. </pre> or, for every content type (dangerous) you can put the following inside a location or directory block:<pre>SetOutputFilter DEFLATE</pre>
  95. <br />
  96. Advanced mode:
  97. <pre>
  98. <Location />
  99. # Insert filter
  100. SetOutputFilter DEFLATE
  101. # Netscape 4.x has some problems...
  102. BrowserMatch ^Mozilla/4 gzip-only-text/html
  103. # Netscape 4.06-4.08 have some more problems
  104. BrowserMatch ^Mozilla/4\.0[678] no-gzip
  105. # MSIE masquerades as Netscape, but it is fine
  106. # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  107. # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
  108. # the above regex won't work. You can use the following
  109. # workaround to get the desired effect:
  110. BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
  111. # Don't compress images
  112. SetEnvIfNoCase Request_URI \
  113. \.(?:gif|jpe?g|png)$ no-gzip dont-vary
  114. # Make sure proxies don't deliver the wrong content
  115. Header append Vary User-Agent env=!dont-vary
  116. </Location>
  117. </pre>
  118. <hr />
  119. Don't have time or resources to optimize your Chamilo installation yourself? Hire an <a href="http://www.chamilo.org/en/providers">official Chamilo provider</a> and get it sorted out professionally by specialists.
  120. <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" style="margin: 1em; float: right;" height="31" width="88" /></a>
  121. <a href="http://jigsaw.w3.org/css-validator/">
  122. <img src="http://jigsaw.w3.org/css-validator/images/vcss-blue" style="margin: 1em; float: right;" alt="Valid CSS" />
  123. </a>
  124. <hr />
  125. <h2><a name="7.High-numbers-memory"></a>Memory considerations for high numbers of users</h2>
  126. 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.<br />
  127. This mode is not loaded by default, but could still be selected, leading to a "Fatal error: Allowed memory size ... exhausted" message.<br />
  128. The only non-scripted solution here is to allow for the corresponding amount of RAM for your PHP configuration (<em>memory_limit = 300M</em>) or your specific VirtualHost if you use mod-php5 (<em>php_value memory_limit 300M</em>).<br/>
  129. <hr />
  130. <h2>Authors</h2>
  131. <ul>
  132. <li>Yannick Warnier, Zend Certified PHP Engineer, BeezNest Belgium SPRL, <a href="mailto:ywarnier@beeznest.net">ywarnier@beeznest.net</a></li>
  133. </ul>
  134. </div>
  135. </body>
  136. </html>