<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3APerformance_and_scalability</id>
	<title>Development:Performance and scalability - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3APerformance_and_scalability"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Performance_and_scalability&amp;action=history"/>
	<updated>2026-05-06T18:46:00Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Performance_and_scalability&amp;diff=11556&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Performance_and_scalability&amp;diff=11556&amp;oldid=prev"/>
		<updated>2024-10-21T08:52:55Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:52, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Performance_and_scalability&amp;diff=11555&amp;oldid=prev</id>
		<title>1&gt;Mjollnir: /* Measure in production */</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Performance_and_scalability&amp;diff=11555&amp;oldid=prev"/>
		<updated>2009-11-27T10:27:26Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Measure in production&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Performance&amp;#039;&amp;#039;&amp;#039; is about allowing Moodle to support as many users as possible with a certain amount of hardware.&lt;br /&gt;
&lt;br /&gt;
Of course you can always always buy a bigger server. &amp;#039;&amp;#039;&amp;#039;Scalability&amp;#039;&amp;#039;&amp;#039; means ensuring that if you buy a server that is about twice as powerful, it can then handle about twice as much load.&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[Development:Coding|Moodle coding guidelines]]&lt;br /&gt;
&lt;br /&gt;
==Writing code that scales and performs==&lt;br /&gt;
&lt;br /&gt;
===Every page should only use a fixed number of database queries===&lt;br /&gt;
&lt;br /&gt;
* Be very suspicious if you ever see database code inside a loop.&lt;br /&gt;
** This is sometimes hard to spot if the database access is hidden in a function.&lt;br /&gt;
* Instead use JOINs and subqueries. (&amp;lt;tt&amp;gt;get_records_sql&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;get_recordset_sql&amp;lt;/tt&amp;gt;, etc.).&lt;br /&gt;
** Or look for a Moodle API function that gets the information you want as efficiently as possible. (For example, &amp;lt;tt&amp;gt;get_users_by_capability&amp;lt;/tt&amp;gt;)&lt;br /&gt;
** See the [[Development:Database|Database guidelines]] for how to write SQL that will work on all our supported databases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Limit the amount of RAM each page requires to generate===&lt;br /&gt;
&lt;br /&gt;
* Large reports should be broken into pages of a fixed size.&lt;br /&gt;
* Processing large amounts of data from the database should be handled with a recordset (when you cannot do all the processing in the database with SQL).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Be cautious about other external calls===&lt;br /&gt;
&lt;br /&gt;
Like a database query, there are other operations that are much slower than just executing PHP code. For example:&lt;br /&gt;
* running a shell script&lt;br /&gt;
* making a web-service call&lt;br /&gt;
* (to a lesser extent) working with files.&lt;br /&gt;
Whenever you are doing these things, worry about performance.&lt;br /&gt;
&lt;br /&gt;
==How to improve the performance of your code==&lt;br /&gt;
&lt;br /&gt;
===Measure during development===&lt;br /&gt;
&lt;br /&gt;
* Turn on [[Debugging#Performance_info|display of performance information]] (including counting database queries), so you are aware of what your code is doing.&lt;br /&gt;
&lt;br /&gt;
* Use tools like [http://jakarta.apache.org/jmeter/ JMeter] to subject your new code to load.&lt;br /&gt;
&lt;br /&gt;
* Use the random course/user generator (build in to Moodle 2.0, available as [http://cvs.moodle.org/contrib/tools/generators/?pathrev=MOODLE_19_STABLE an add on for Moodle 1.9]), so you can test with many users and courses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Measure in production===&lt;br /&gt;
&lt;br /&gt;
* If you&amp;#039;re using postgres, there&amp;#039;s a script that can parse the logs and output the top 10 slow queries, ready to be plugged into a cronjob to email you every day.  It can be found here: &lt;br /&gt;
&lt;br /&gt;
http://git.catalyst.net.nz/gw?p=pgtools.git;a=blob_plain;f=scripts/pg-log-process.pl;hb=refs/heads/pg-log-process-multidb&lt;br /&gt;
&lt;br /&gt;
You need to configure postgres a bit to make it log things in the correct format.  Instructions are in the file.&lt;br /&gt;
&lt;br /&gt;
==How big can a Moodle site be?==&lt;br /&gt;
&lt;br /&gt;
Looking at the [http://moodle.org/stats/ statistics], the largest sites in the world currently have&lt;br /&gt;
* Up to 1 000 000 users&lt;br /&gt;
* Up to 50 000 courses&lt;br /&gt;
* Up to 5 000 users per course&lt;br /&gt;
* Up to 50 roles&lt;br /&gt;
* Up to 100 course categories nested up to about 10 levels deep.&lt;br /&gt;
* Up to XXX activities in a course.&lt;br /&gt;
* Please add more things here.&lt;br /&gt;
&lt;br /&gt;
When planning and testing your code, these are the sorts of numbers you should be contemplating. However, do not assume that Moodle sites will never get bigger than this.&lt;br /&gt;
&lt;br /&gt;
Even if you can&amp;#039;t test sites this big on your development server, you should use the generator script so you can test your code in a Moodle site that is not tiny.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:Coding|Moodle coding guidelines]]&lt;br /&gt;
* [[Performance]] guidance for administrators&lt;br /&gt;
* [[Performance FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Performance]]&lt;br /&gt;
[[Category:Coding guidelines|Performance]]&lt;/div&gt;</summary>
		<author><name>1&gt;Mjollnir</name></author>
	</entry>
</feed>