「パフォーマンスおよびスケーラビリティ」の版間の差分

提供:MoodleDocs
移動先:案内検索
編集の要約なし
編集の要約なし
10行目: 10行目:


===すべてのページで決まった数のデータベースクエリしか使用しない===
===すべてのページで決まった数のデータベースクエリしか使用しない===
* ループの中にデータベースコードがある場合、非常に疑ってください。
* ループの中にデータベースコードがある場合、非常に疑ってください。
** これはデータベースアクセスが関数の中に隠されている場合、発見が難しいことがあります。
** これはデータベースアクセスが関数の中に隠されている場合、発見が難しいことがあります。
* 代わりにJOINおよびサブクエリを使用してください (<tt>get_records_sql</tt>, <tt>get_recordset_sql</tt>等)。
* 代わりにJOINおよびサブクエリを使用してください (<tt>get_records_sql</tt>, <tt>get_recordset_sql</tt>等)。
** Or look for a Moodle API function that gets the information you want as efficiently as possible. (For example, <tt>get_users_by_capability</tt>)
** またはあなたが必要としている情報を可能な限り効率的に取得できるMoodle API関数を探してください (例 <tt>get_users_by_capability</tt>)
** またはあなたが必要としている情報を可能な限り効率的に取得できるMoodle API関数を探してください (例 <tt>get_users_by_capability</tt>)。Or look for a Moodle API function that gets the information you want as efficiently as possible. (For example, <tt>get_users_by_capability</tt>)
** See the [[Database|Database guidelines]] for how to write SQL that will work on all our supported databases.
** 詳細は私たちがサポートするすべてのデータベースで動作するSQLの記述方法に関して[[データベース|データベースガイドライン]]をご覧ください。
** 詳細は私たちがサポートするすべてのデータベースで動作するSQLの記述方法に関して[[データベース|データベースガイドライン]]をご覧ください。




===Limit the amount of RAM each page requires to generate===
===各ページの生成に必要なRAMの容量を制限する Limit the amount of RAM each page requires to generate===
 
* Large reports should be broken into pages of a fixed size.
* Large reports should be broken into pages of a fixed size.
* 大きなレポートは一定の大きさのページに分割する必要があります。Large reports should be broken into pages of a fixed size.
* 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) and using [https://github.com/moodle/moodle/blob/master/lib/classes/dml/recordset_walk.php recordset_walk iterator], as there is no RAM benefit on using recordsets if you load all the results in a massive PHP array.
* 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) and using [https://github.com/moodle/moodle/blob/master/lib/classes/dml/recordset_walk.php recordset_walk iterator], as there is no RAM benefit on using recordsets if you load all the results in a massive PHP array.



2022年2月5日 (土) 15:06時点における版

作成中です - Mitsuhiro Yoshida (トーク)

パフォーマンスとはMoodleが一定のハードウェアで可能な限り多くのユーザをサポートできるようにすることです。

もちろん、あなたはいつでも大きなサーバを購入できます。「スケーラビリティ」とは2倍の性能のサーバを買った場合、2倍の負荷に対応できるようにすることです。

このページはMoodleコーディングガイドラインの一部です。

スケールおよびパフォーマンスのためのコードを書く

すべてのページで決まった数のデータベースクエリしか使用しない

  • ループの中にデータベースコードがある場合、非常に疑ってください。
    • これはデータベースアクセスが関数の中に隠されている場合、発見が難しいことがあります。
  • 代わりにJOINおよびサブクエリを使用してください (get_records_sql, get_recordset_sql等)。
    • またはあなたが必要としている情報を可能な限り効率的に取得できるMoodle API関数を探してください (例 get_users_by_capability)。
    • 詳細は私たちがサポートするすべてのデータベースで動作するSQLの記述方法に関してデータベースガイドラインをご覧ください。


各ページの生成に必要なRAMの容量を制限する Limit the amount of RAM each page requires to generate

  • Large reports should be broken into pages of a fixed size.
  • 大きなレポートは一定の大きさのページに分割する必要があります。Large reports should be broken into pages of a fixed size.
  • 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) and using recordset_walk iterator, as there is no RAM benefit on using recordsets if you load all the results in a massive PHP array.


Be cautious about other external calls

Like a database query, there are other operations that are much slower than just executing PHP code. For example:

  • running a shell script
  • making a web-service call
  • (to a lesser extent) working with files.

Whenever you are doing these things, worry about performance.

How to improve the performance of your code

Measure during development

  • Use tools like JMeter to subject your new code to load.


Measure in production

  • If you're using postgres, there'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:

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

You need to configure postgres a bit to make it log things in the correct format. Instructions are in the file.

How big can a Moodle site be?

Looking at the statistics, the largest sites in the world currently have

  • Up to 1 000 000 users
  • Up to 50 000 courses
  • Up to 5 000 users per course
  • Up to 50 roles
  • Up to 100 course categories nested up to about 10 levels deep.
  • Up to XXX activities in a course.
  • Please add more things here.

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.

Even if you can'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.


関連情報