Anyone who runs jobs in the Windows task scheduler will sooner or later stumble upon inexplicable differences in runtime. A PHP script that runs in 5 minutes on the command line suddenly takes 20 minutes when run via Windows Task Scheduler. Same user, same rights, same code – four times the execution time. What was going on there?
After hours Debugging, Process monitor sessions and countless configuration comparisons, the solution was shockingly simple: Windows task scheduling sets a lower process priority by default. The default value for tasks in Task Scheduler is 7 (Below Normal), not 4-6 (Normal), as you would expect. This seemingly small difference can lead to massive performance losses in I/O-intensive operations.
The Windows priority levels in detail are:
| Value | Priority | Description |
|---|---|---|
| 0 | Realtime | Highest priority (caution!) |
| 1 | High | High priority |
| 2-3 | Above Normal | About Normal |
| 4-6 | Normal | Standard for interactive processes |
| 7 | Below Normal | DEFAULT in Task Scheduler |
| 8-9 | Below Normal | Even lower |
| 10 | Idle | Lowest priority |
The problem with priority in task scheduling is multifaceted: When you export a task and look at the XML, you will often find no Priority setting. Windows will then silently use the default value 7. The GUI displays this value during export, but it is not explicitly stored in the task. The lower priority not only results in less CPU time, but also:
- Throttled disk I/O operations
- Lower network priority
- Poor file system caching
- Delays in database access
Even if you use the same user and enable "Run with highest privileges," the task runs in a different Windows station/desktop environment with different priorities. To identify the problem, you can use PowerShell to list all tasks with their actual priorities.:
38b7fa6c77dc344401485cd338ea4128
Almost all my tasks ran with priority 7. We now specifically correct the priority of several tasks at once:
38b7fa6c77dc344401485cd338ea4128
After setting the priority to 4 My PHP script ran (normally) again in the expected 300 seconds. If you have configured tasks with a specific user account, you can simply enter this in line 10 as follows:
38b7fa6c77dc344401485cd338ea4128