「パフォーマンスおよびスケーラビリティ」の版間の差分
Mitsuhiro Yoshida (トーク | 投稿記録) 編集の要約なし |
Mitsuhiro Yoshida (トーク | 投稿記録) 編集の要約なし |
||
22行目: | 22行目: | ||
===その他の外部コールに注意する | ===その他の外部コールに注意する=== | ||
データベースクエリのようにPHPコード実行だけよりはるかに遅い操作があります。例えば: | |||
* シェルスクリプトの実行 | |||
* ウェブサービスコールの作成 | |||
* | |||
* ウェブサービスコールの作成 | |||
* (それほどではありませんが)ファイル操作 | * (それほどではありませんが)ファイル操作 | ||
あなたがこれらを実行する場合、必ずパフォーマンスを心配してください。 | あなたがこれらを実行する場合、必ずパフォーマンスを心配してください。 | ||
==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
- Turn on display of performance information (including counting database queries), so you are aware of what your code is doing.
- Use tools like JMeter to subject your new code to load.
- Use https://github.com/moodlehq/moodle-performance-comparison (Moodle 2.5 onwards) to compare performance. You can also use the Test site generator or Test course generator generators (also Moodle 2.5 onwards).
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:
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.
関連情報
- Moodle coding guidelines
- Performance guidance for administrators
- Performance FAQ