Bug 8525 - Use Windows Vista low priority I/O for scanner
: Use Windows Vista low priority I/O for scanner
Status: NEW
Product: Logitech Media Server
Classification: Unclassified
Component: Scanner
: 7.0.1
: PC Windows Vista
: -- enhancement with 1 vote (vote)
: 8.0.0
Assigned To: Andy Grundman
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-06-21 02:49 UTC by Nigel Birch
Modified: 2010-12-04 12:26 UTC (History)
1 user (show)

See Also:
Category: ---


Attachments
Sets low priority IO for use on Vista (911 bytes, patch)
2008-06-21 02:51 UTC, Nigel Birch
Details | Diff
Updated patch for v7.3 (901 bytes, patch)
2008-12-15 15:01 UTC, Nigel Birch
Details | Diff
Updated for v7.4 (901 bytes, application/octet-stream)
2010-02-06 16:12 UTC, Nigel Birch
Details
For 7.4 but updated to check for Vista+ and only set very low I/O priority when CPU priority is low (1.51 KB, patch)
2010-04-07 15:25 UTC, Nigel Birch
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nigel Birch 2008-06-21 02:49:02 UTC
Windows Vista includes a low priority I/O feature that would further reduce the impact of the scanner process on music playback, etc. (beyond what the current CPU priority options achieves).  See the PROCESS_MODE_BACKGROUND_BEGIN constant in SetPriorityClass (http://msdn.microsoft.com/en-us/library/ms686219(VS.85).aspx).

I've attached an patch that changes changes Slim::Utils:Misc to set Very Low priority I/O for Below Normal and Low CPU priorities and Normal I/O priority for higher CPU priorities.  This works for me, as I have SqueezeCentre set to High and the scanner set to Low.

The patch has several problems but it does illustrate low priority I/O working:
- it sets low priority I/O for SqueezeCentre too (if SqueezeCentre is set to Below Normal or Low).  This is a bad idea, but then again who would set SS to anything below Normal?
- it doesn't cater for those who want lower CPU priority for the scanner but normal I/O priority.
- perhaps it should be a separate pref. for just the scanner.
- I doesn't check that it's running on Vista or above (I don't know what happens if you use PROCESS_MODE_BACKGROUND_BEGIN/PROCESS_MODE_BACKGROUND_BEGIN_END on 2000/XP/2003).
- It should check whether PROCESS_MODE_BACKGROUND_BEGIN/PROCESS_MODE_BACKGROUND_BEGIN_END has been set already before setting it again ("The function fails if the process is already in background processing mode").
- I couldn't get a logical OR working, so I've repeated the API call again and again (I don't know Perl!).

For the record, in testing I found that Vista 'boxes in' processes (and their children) run by Scheduled Tasks to Low and Very Low I/O priority (using PROCESS_MODE_BACKGROUND_BEGIN always sets Very Low; Low seems to be only ever set or be settable by Scheduled Tasks). See:
http://technet.microsoft.com/en-us/magazine/cc162494.aspx
http://blogs.technet.com/askperf/archive/2008/02/07/ws2008-memory-management-dynamic-kernel-addressing-memory-priorities-and-i-o-handling.aspx
Useful to know when you're running SqueezeCentre via a scheduled task and you can't work out why the API call won't set Normal I/O priority...
Comment 1 Nigel Birch 2008-06-21 02:51:44 UTC
Created attachment 3468 [details]
Sets low priority IO for use on Vista
Comment 2 Nigel Birch 2008-06-21 02:54:56 UTC
Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) can show the I/O priority of processes.
Comment 3 Chris Owens 2008-06-30 09:28:18 UTC
We'll keep and eye on this and come back to it if there's more interest or votes or comments.  Feel free to stir up support on the forums!
Comment 4 Nigel Birch 2008-12-15 15:01:46 UTC
Created attachment 4449 [details]
Updated patch for v7.3

Uses the same method as the previous patch.
Comment 5 Nigel Birch 2009-07-01 14:35:54 UTC
Some performance statistics...

On a computer with:
- AMD 2.4 GHz X2 CPU
- 2 GB RAM
- 500 GB 7200 RPM HDD
- Dedicated to SqueezeCentre
- Peforming no tasks other SqueeCentre/scanner

With a database of:
- 12,083 FLAC tracks
- 869 albums
- 377 artists
- 26 genres

Took ~ 26 minutes with the scanner process at Idle CPU priority / normal I/O priority (i.e. without the attached patch) and ~ 30 minutes at Idle CPU priority / Very Low I/O priority.

Obviously if there were other processes performing significant I/O which had I/O priorities higher than Very Low, the scanning process would take longer (which is what is desired).  However, it does show the magnitude of the slow-down due to just the lower I/O priority.
Comment 6 Nigel Birch 2009-07-01 14:36:33 UTC
Opps - comment 5 refers to a wipe/rescan.
Comment 7 Nigel Birch 2009-07-01 15:00:48 UTC
And it's a 2.0 GHz CPU (but that shouldn't matter much to the relative times).
Comment 8 Andy Grundman 2009-07-29 14:58:38 UTC
Moving 7.4 bugs to 8.0.
Comment 9 Nigel Birch 2010-02-06 16:12:21 UTC
Created attachment 6494 [details]
Updated for v7.4
Comment 10 Nigel Birch 2010-04-07 15:25:40 UTC
Created attachment 6744 [details]
For 7.4 but updated to check for Vista+ and only set very low I/O priority when CPU priority is low

I've updated the patch to:
- check that it's running on Windows Vista or above (only these OSs support I/O priority)
- only set VERY LOW I/O priority when CPU priority is LOW.

The latter change corresponds to what Windows Task Scheduler does - it uses LOW I/O priority with BELOW NORMAL CPU priority for tasks. Therefore, using VERY LOW I/O priority with to LOW CPU priority is a reasonable match.  Setting I/O priority to LOW isn't possible using the published API, otherwise we could do this for when CPU priority is BELOW_NORMAL.

I think this is a safe default setting - if one sets scanner CPU priority to LOW, it's safe to assume the user is trying to avoid the scanner having an affect on streaming or other tasks on the server.  My tests indicate only a slight slowdown in scanning speed on an unloaded server (see previous comments).

This is currently not a separate preference (e.g. a checkbox for "Use very low priority I/O for the scanner".   Is this desired in order to get this patch added to Squeezebox Server?  Thanks.
Comment 11 Nigel Birch 2010-12-04 12:26:25 UTC
Is there any interest in getting this added to Squeezebox Server? Would it need a separate preference to enable this?  Or is it okay for it to be combined with the scanner CPU priority?

If it needs a separate preference, I could take a look to see if I can add one (not done that before but can try).

Thanks.