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

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




===その他の外部コールに注意する Be cautious about other external calls===
===その他の外部コールに注意する===
 
データベースクエリのようにPHPコード実行だけよりはるかに遅い操作があります。例えば:
Like a database query, there are other operations that are much slower than just executing PHP code. For example:
* シェルスクリプトの実行
データベースクエリのようにPHPコードの実行だけよりはるかに遅い操作があります。例えば:
* ウェブサービスコールの作成
* running a shell script
* シェルスクリプト実行 running a shell script
* making a web-service call
* ウェブサービスコールの作成 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==
==あなたのコードのパフォーマンス改善方法 How to improve the performance of your code==


===Measure during development===
===Measure during development===

2022年2月9日 (水) 15:03時点における版

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

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

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

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

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

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

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


各ページの生成に必要なRAMの容量を制限する

  • 大きなレポートは一定の大きさのページに分割する必要があります。
  • データベースから大量のデータを処理する場合、レコードセットを使用して処理する必要があります (あなたがデータベース内のすべての処理をSQLで実行できない場合)。また、recordset_walk iterator を使用します。あなたがすべての結果を大量のPHP配列で読み込む場合、レコードセット使用によるRAMの利点はありません。


その他の外部コールに注意する

データベースクエリのようにPHPコード実行だけよりはるかに遅い操作があります。例えば:

  • シェルスクリプトの実行
  • ウェブサービスコールの作成
  • (それほどではありませんが)ファイル操作

あなたがこれらを実行する場合、必ずパフォーマンスを心配してください。

あなたのコードのパフォーマンス改善方法 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.


関連情報