Profiling slow Moodle pages

Profiling slow Moodle pages means measuring where time goes before changing anything. This page explains the core tools, how to read their output and how findings become configuration or code fixes.

On this page

Why profiling slow Moodle pages comes before any fix

Profiling finds the cause of a slow page before anyone changes configuration or code. When users or staff report that Moodle is slow, the symptom usually sits in one of several layers: the PHP code path of a specific page, a database query, a session lock held by a long request, or the server and cache stack underneath. Each layer has a different fix, and changing the wrong one costs time and can make the real problem harder to see. A session store change will not help a slow query, and adding database headroom will not help a page that waits on a lock. Before a team tunes anything, it should be able to name the layer that is slow.

Moodle core includes two tools for this work. The profiling admin tool (tool_profiling) records where a request spends its time, and the performance report (report_performance) gives a broader view of how the site behaves. The first is needed when a specific page or action is confirmed slow and the team must see which functions or queries account for the time. The second is the better starting point when the team needs to know which pages or areas are a concern at all. Before relying on either, confirm in your own environment which Moodle release you run, check that both tools are present in your installed code under the public admin and report directories, and confirm who is allowed to enable and read profiling output, because that output can expose internal paths and query detail.

Write down the reported symptoms before you open either tool. Record which pages, which user roles, what time of day, and whether the slowness affects one user or many. A slow page for one user in one course points to different causes than a site-wide slowdown during a scheduled task. This record gives the profiling run a defined target and gives you a baseline to compare against after a fix. The rest of this page covers how to use each tool, the slow query and session lock signals that Moodle can raise, and how to turn a finding into a change that you can verify.

Which Moodle tool answers which performance question

When one page or action is slow and you can reproduce it, the question is where the time goes inside a single request. The profiling admin tool, tool_profiling, records a profile of an individual request so you can see which functions and code paths consumed the time. Enable it for a short window, trigger the slow action once, then review the captured run and compare it against a fast run of the same page.

  • Reproduce with one request: Profile a single run of the action rather than leaving profiling on for all traffic, since capture adds overhead.
  • Compare a fast and slow run: A difference in call counts or time in one function usually points to the cause faster than reading the slow run alone.
  • Check the page type: Quiz attempts, grade reports and course pages each exercise different code, so profile the exact URL users complain about.
  • Confirm the environment: Test on a copy of production data or a representative staging site, because empty courses hide slow paths.
  • Record the Moodle version and plugins: Third-party plugins often appear in the profile and need their own owners.

Confirm the profiling settings and capture behavior for your Moodle version in the Moodle GitHub repository before you rely on them on a shared site.

Configuration options for profiling and slow query logging

This table compares the four diagnostic options Moodle offers for finding slow pages: the profiling tool, the performance report, slow query logging and the session lock warning. Read each row against your own environment, and treat the overhead and storage columns as items to confirm with a test run rather than fixed figures. The main takeaway is that most slow-page investigations need one or two of these options turned on for a short, controlled window, not permanently.

OptionWhat it recordsWhen it fits and what to confirmWho should enable it on production
Profiling admin tool (tool_profiling)Per-request execution data for pages you choose to profile, showing where time is spent in PHP code and functionsFits reproducing a specific slow page or action. Confirm the storage it writes and the overhead on your PHP workers in a staging copy before enabling it on live trafficSite administrators with change approval, for a short window, with a named owner who turns it off
Performance report (report_performance)Site-level performance information gathered by Moodle, presented as a report in the administration areaFits a first look at the site's health and configuration before deeper profiling. Confirm which checks it runs on your Moodle version and what it does not measureSite administrators and platform engineers, since it is read-oriented and carries little risk to users
Slow query logging (dboptions, log_queries table)Database queries that exceed a configured time threshold, written to the log_queries tableFits finding a few expensive queries behind a slow page. Confirm the threshold, the table growth rate and whether your database account can write to the table, and purge it after useDatabase administrators and the platform team, with a time limit and a planned cleanup of the log table
Session lock warning (debugsessionlock)Warnings when a page holds the user session lock longer than expected, which can make a user's other requests waitFits pages that feel slow only when a user has several tabs open or runs long actions. Confirm where warnings appear in your logs before relying on themPlatform engineers and developers, usually in a non-production or controlled environment
Overall production riskEach option adds work to requests or writes data that must be managedConfirm with your vendor documentation and a load test which option costs the most in your setup before any change windowChange board or named technical owner, with a written rollback step for each setting

How to run a profiling session on a live Moodle site

This sequence captures the evidence needed to find why specific pages are slow, using a bounded window that limits load and log growth on production. Each step ends with a check so the findings can be trusted before any configuration or code change is made.

  1. Reproduce the slow page on a staging copy

    Restore a recent production database and dataroot to a staging environment that matches the production PHP, database and web server versions as closely as you can. Load representative data, such as a course with the same number of enrolled users, quiz attempts or forum posts as the page that is slow in production. Trigger the slow page and time it at least twice, so you know the problem reproduces before you touch production. The check: the page is slow on staging in a way that matches the production report. If it is not slow on staging, the cause is probably data volume, a plugin difference or production load, and the next steps on production will be more important.

  2. Enable the profiling tool for a bounded window

    Turn on the profiling admin tool (tool_profiling, in the admin tool area of Moodle core) for the smallest set of requests you need. Limit capture to the affected pages or to a named user or course where the option is available, and set a clear end time for the window before you start. Record who enabled it and the time, so the change is traceable and can be reversed by the same person. The check: open the profiling run list and confirm that a run appears for your test request, with the correct URL and user. If no run appears, the capture rule is wrong and you should fix it before waiting for more traffic.

  3. Enable slow query logging and session lock warnings

    Switch on the slow query logging option in the database settings (dboptions in config.php, based on the config-dist.php reference) and set the session lock warning option (debugsessionlock) so pages that hold the session lock for too long are reported. Make these changes in a single change request so you can roll them back together. Confirm the database account can write to the log_queries table, because slow queries are recorded there. The check: trigger one slow request and confirm a row appears in log_queries and a session lock warning appears in the Moodle log. If either is missing, review the configuration syntax and the database permissions before continuing.

  4. Exercise the affected pages under normal use

    Ask a small group of real users, or a scripted set of test accounts, to follow the path that is slow, such as opening the course page, starting a quiz or loading the gradebook. Keep the activity inside the window you set in the profiling step so the captured data matches the time when users noticed the problem. Note the time each action started and finished so you can match them to profiling runs and log entries later. The check: the set of profiling runs and slow query rows includes the requests you exercised, and you can match at least one run to a user-reported delay.

  5. Collect the performance report

    Open the performance report (report_performance, in the report area of Moodle core) and review the figures for the same window. Compare page load, database and cache activity against the staging baseline so you can see which numbers moved. Export or copy the relevant figures and attach them to the investigation record with the time range and the Moodle version. The check: the report covers the full window you set, and the numbers you are comparing come from the same period as the profiling runs and log entries. Data from outside the window should be excluded from the analysis.

  6. Disable the diagnostics and confirm the log state

    Turn off the profiling tool, remove or reset the slow query logging and session lock warning settings, and restore the original config.php values. Confirm the change in the admin interface and in the file itself, and reload one page to confirm the diagnostics no longer write new entries. Check that the log and profiling tables are not growing faster than normal and that log rotation or the scheduled clean-up task is running as expected. The check: no new profiling runs or slow query rows are created after a test request, and the log_queries table is no longer growing, so the production site is back to its normal logging level.

  7. Turn the findings into fixes

    Group the captured evidence by cause, such as a slow query from a specific plugin, a session lock held too long by one page, or cache misses on a shared store. For each group, decide whether the fix is configuration, such as a cache mapping or session setting, or code, such as a query change or a plugin update. Test each fix on the staging copy from step one and repeat the same timed requests to confirm the improvement. The check: each fix has a before and after measurement from the same staging scenario, and the change is recorded in your change log before it is promoted to production.

How to read profiling output and separate database, session and code causes

Start by deciding which of four buckets a slow page falls into: database time, session lock waits, cache misses or plugin code. Profiling output from the tool_profiling admin tool records where time went during a single request, so the first read is the breakdown of time between database calls and everything else. If most of the request is spent in database calls, the next question is which queries and which code paths issued them. If the database share is small but the page is still slow, the cause is more likely PHP execution, external calls or waiting on a lock. Treat each conclusion as a hypothesis at this stage, and record the page, the user role, the course size and the time of day so the reading can be compared with later runs.

Repeated slow queries in the log_queries table are the strongest database signal. A single slow query is usually noise, but the same statement recorded across many requests, especially one filtering or sorting on columns without a suitable index, points to a missing index or a heavy query inside a plugin. Group entries by normalized SQL text and by the calling component. Queries that originate in a third-party block, report or local plugin are a sign to review that plugin's code or ask its maintainer, not to tune the core schema. Session lock warnings have a different signature: when debugsessionlock is enabled, a warning names a page that held the session lock longer than expected, which means other requests from the same user queued behind it. Check whether that page performs long work, such as report generation or external web service calls, that could run without the lock.

Findings become fixes only after a re-test under similar conditions. Compare the same page, user and data set before and after each change, and change one variable at a time so the effect can be attributed. A cache miss pattern that looks like a slow page may disappear once the cache mapping is corrected, and an index that helps one query may leave the page slow because another query dominates. Confirm with your Moodle version and plugin versions, since database and plugin behavior changes between releases. If the re-test does not reproduce the improvement, return to the profile rather than adding more configuration. Ask the partner or your team to document the hypothesis, the change, the measured result and the date in your change log.

Turning findings into configuration changes or code fixes

Profiling output points at a cause, but the fix differs by category: a session setting, a missing index, a misbehaving plugin, an oversized template or a scheduled task running at the wrong time. Each category needs its own evidence bar and its own regression check before the change reaches production.

Configuration changes

Session, cache and debug settings in config.php, such as the session lock warning from debugsessionlock, often explain a page that waits rather than computes. Justify a change only when the profile shows time spent waiting on the session or cache, not in PHP or SQL. Regression test by repeating the same profiled request before and after, and by checking that pages which write to the session still save their data correctly.

config-dist.php

Database indexes and query changes

Slow query entries in the log_queries table identify the SQL statement, its run count and its duration. Add an index or rewrite a query only when the same statement dominates the profile across several requests and the table has enough rows for the plan to matter. Regression test with the query plan before and after on a copy of production data, and confirm that writes to the indexed table do not slow down noticeably.

Plugin fixes or removal

A third-party block, report or local plugin that appears in the profile is a candidate for an upgrade, a patch or removal. Confirm the plugin's compatibility with your exact Moodle version, check its open issues for the slow path, and remove plugins that no course uses. Regression test the features the plugin provides, since removing a block can break a page layout that several courses depend on.

Theme and template changes

Heavy Boost-based theme output, unbounded course lists in a template override or large JavaScript bundles can dominate render time without touching the database. Change templates only when the profile shows time in rendering and the same template appears on the slowest pages. Regression test with the theme cache rebuilt, across the main layouts (course, dashboard, activity) and at the browser's narrowest screen width.

Scheduled task timing

Long cron tasks such as reports, backups or log cleanup that run during business hours compete with user requests for database and PHP capacity. Move a task to a quieter window, change its frequency or split its work only when the profile or server metrics show overlap with the slow periods. Regression test by checking that the task still completes in its window and that the next run starts on schedule.

How a slow request moves from user to diagnosis

The diagram starts with a learner or staff member loading a slow Moodle page through the web server into PHP. PHP takes the session lock and queries the database, and each stage has an observer: the session lock warning watches the session store, the slow query log watches the database, and the profiling tool records the whole request. The reader then decides whether the evidence points to a configuration fix, a code fix or a retest before changing anything.

Observers attached to each stage of a slow Moodle request, leading to one of three next steps.

Limits to confirm before relying on these tools

The profiling tool, the performance report and the logging settings each show a different slice of a slow page. Before you act on what they show, confirm your Moodle version, your database engine, your cluster layout and how closely a test run matches production traffic.

Moodle version and admin pages

The profiling tool and the performance report live under the admin tree, and their availability and location depend on the release you run. Confirm which admin pages your version exposes against the release notes for your exact version, since the 5.1 and 5.3 notes cover different server and upgrade requirements. A finding from one release's report may not map to the screens on another, so record the version alongside every profile you capture.

Moodle 5.1 notes

Database engine slow query logging

The dboptions setting can write slow queries to the log_queries table, but what the database itself records is a separate question. Confirm how your PostgreSQL, MySQL, MariaDB or SQL Server instance logs slow statements, what threshold it uses and who can read those logs. Two logs can disagree about timing, so compare them before you decide a query is the bottleneck.

config-dist.php

Session lock behaviour in a cluster

The debugsessionlock warning fires on one node when a page holds the session lock too long, but a cluster with shared or stored sessions can behave differently from a single server. Confirm where sessions are stored, whether requests from one user can land on several nodes, and whether the warning appears in the logs you actually collect. A lock wait seen on one node can be caused by another node's request.

Profile data against production load

A profile captured by one tester on a quiet staging site shows the code path, not the wait under concurrency. Confirm that the test data volume, course sizes, cron activity and number of concurrent users resemble production before you change configuration. Slow queries that appear only under real contention, such as cache misses or lock waits, will not show in a single-user run.

Access and retention of profile output

Profiling output and query logs can include SQL text, user identifiers and page paths, so they carry personal data and should be treated as sensitive. Confirm who may enable the profiling tool, where its files are written, how long they are kept, and whether the production environment allows it at all. Document those rules before the first capture so that a diagnostic step does not become a data exposure.

Questions buyers ask about profiling slow Moodle pages

What does profiling a slow Moodle site cost in effort, and who pays for it?

Profiling is billed as investigation time: someone reproduces the slow pages, enables the profiling tool, reads the results, and tests candidate fixes. If your own team does it, the cost is staff time taken from other work. If a partner does it under a fixed-scope agreement, the cost is the agreed quote, which should list the pages in scope, the environments used, the number of reproduction rounds and the deliverables. The one-time cost is the diagnosis and fix work. Recurring cost appears only if you later want monitoring or retainer support. Ask any provider to state what is included in the quote and what would trigger a change order.

How long does a Moodle performance diagnosis take, and what makes it longer?

The duration depends mostly on how well the slow pages can be reproduced and how many layers are involved. A single slow report with a clear query pattern is quicker than an intermittent slowdown that appears only under peak concurrency. Other drivers include access to logs and monitoring history, whether a staging copy with realistic data exists, the number of plugins involved, whether sessions, caches or the database are shared across nodes, and how many fix-and-retest cycles the findings require. No duration is stated here; ask the provider to propose one based on the page list and environment you supply.

What does the work need from our team: access, staging copies and data samples?

Expect to provide the following:

  • Read access to web server, PHP-FPM, database and Moodle logs for the period when pages were slow.
  • A staging copy of the site, with the same Moodle version, plugins, and configuration as production, and a recent database snapshot.
  • Anonymized or masked data samples, such as course sizes, quiz attempt counts and enrolment volumes, so that slow paths reproduce at realistic scale.
  • Named contacts who can approve configuration changes and schedule test windows.

Without a production-like dataset, findings may describe the staging copy rather than your live site. Confirm data handling rules before any copy leaves your environment.

Can our internal team profile and fix Moodle slow pages on its own?

Yes, a team with Moodle administration and PHP experience can run the core tools itself. Moodle core includes the profiling admin tool (tool_profiling) and the performance report (report_performance), and the configuration file offers session lock warnings and slow query logging. The harder part is interpreting results across the web tier, session store, caches and database, and deciding whether a fix belongs in configuration or in code. Teams that lack a staging environment, or that have no one who reads query plans and PHP profiles regularly, usually find the diagnosis slower than expected.

When is it worth hiring a partner to diagnose Moodle performance?

A partner is worth considering when the slowdown affects exams, enrolment peaks or regulated services, when it recurs after each release, or when the cause could sit across several systems. It also helps when your team cannot spare people for weeks of testing, or when a fix needs code changes that must be reviewed and handed over properly. A fixed-scope engagement gives you agreed deliverables, such as a written findings report with prioritized fixes and a retest, before work starts. Ask whether the provider will hand over profiling scripts, configuration changes and documentation your team can reuse.

What happens after the fix: retest, monitoring and regression checks?

A fix is only confirmed when the original slow pages are retested under the same conditions that exposed them, using the same staging copy or a comparable production window. Good practice includes re-running the profiler, comparing performance report results with the baseline, and checking that the session lock warnings and slow query log no longer show the problem. After go-live, monitoring should watch the pages that were slow and the database and PHP metrics behind them. Changes to Moodle versions, plugins or cache settings can reintroduce the problem, so ask the provider how regression checks will be handled.

Could profiling expose user data or sensitive course content?

Yes. Profiling output, slow query logs and debug information can contain SQL with user identifiers, course names or quiz content. Store captured data only in systems approved by your security team, restrict who can read it, and remove it after the diagnosis. Disable profiling and debugging on production once the investigation ends. Confirm with the provider how captured data is handled, where it is stored and when it is deleted before any access is granted.

How DeployOpen scopes and delivers Moodle performance diagnosis

DeployOpen treats performance diagnosis of a slow Moodle as a fixed-scope engagement, with the scope, deliverables and timeline agreed in writing before any profiling starts. The written scope should name the pages and user journeys in question (for example, quiz attempts, gradebook views or course listings), the environments that will be examined, the access granted, and the form the findings will take. Each deliverable should be listed so the client can check whether the work is complete. Nothing in this section is a promise about how much a page will improve or how long the work will take; those depend on what the investigation finds, and the client should ask for both to be stated as assumptions in the quote.

The work is carried out inside the client's own infrastructure, on their web nodes, database servers, cache and session stores and logs. Profiling data, slow query logs and performance reports often contain user names, course content and IP addresses, so the client should decide in advance where captured data is stored, who can read it and when it is deleted. Enabling profiling output or slow query logging on production can add load of its own, so the scope should say which environment is profiled first, whether a staging copy with production-like data is available, and who approves a change to a live configuration. Confirm the exact diagnostic settings for your Moodle version against the current documentation before anyone changes them.

Ongoing needs are covered by a retainer rather than a new fixed-scope project. A retainer can keep the profiling setup available for repeat investigations, re-check pages after each Moodle minor release, and review performance after plugin or theme changes. The client should ask for the retainer terms in writing, including what is included each month, how urgent incidents are handled, and what is excluded. Costs for the diagnosis itself are one-time, while retainers recur, so the quote should separate the two.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.