パフォーマンスおよびスケーラビリティ

提供:MoodleDocs
2022年2月8日 (火) 15:08時点におけるMitsuhiro Yoshida (トーク | 投稿記録)による版
移動先:案内検索

作成中です - 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の利点はありません。


その他の外部コールに注意する 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: データベースクエリのように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

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.


関連情報