After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 581103 - 100% CPU usage and a minute long pause when switching views
100% CPU usage and a minute long pause when switching views
Status: RESOLVED FIXED
Product: banshee
Classification: Other
Component: User Interface
git master
Other All
: Normal blocker
: 1.6
Assigned To: Alexander Kojevnikov
Banshee Maintainers
: 593817 605358 (view as bug list)
Depends on:
Blocks: 603661
 
 
Reported: 2009-05-02 15:17 UTC by David Nielsen
Modified: 2009-12-27 02:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
This is the output of the banshee-1 that I ran in the terminal during high cpu when I gave the kill command (9.63 KB, text/plain)
2009-05-15 19:24 UTC, boris boef
  Details
Force the join order (1.11 KB, patch)
2009-12-04 08:44 UTC, Alexander Kojevnikov
none Details | Review

Description David Nielsen 2009-05-02 15:17:08 UTC
Please describe the problem:
On git master[1] I am seeing 100% CPU usage and pauses where the interface greys out extending beyond several minutes when switching views, e.g. when switching from one smart playlist to another or from the music library to the podcast libray, or when marking artists or albums.

This leads Banshee to be practically unusable compared to 1.4.3

No useful output can be seen when running with --debug

[1] defined as of this commit:
http://git.gnome.org/cgit/banshee/commit/?id=934b511fb25599df2219ddbdc3f98d1d2486d262

Steps to reproduce:
1. compile git master
2. switch views

Actual results:
100% cpu usage and extended pausing

Expected results:
smooth view switching

Does this happen every time?
100%

Other information:
x86_64, da_DK.UTF-8, Ubuntu Karmic Koala
Comment 1 Alexander Kojevnikov 2009-05-03 02:45:58 UTC
In git master there's a scheduled meta-data refresh compared to 1.4.3. It's probably slow because banshee is rescanning your library.
Comment 2 David Nielsen 2009-05-03 03:58:28 UTC
The metadata scan has completed, if it was that, --debug would have shown that. My database is up to date (v 31)
Comment 3 David Nielsen 2009-05-08 08:50:38 UTC
I am also seeing similar high CPU loads when copying music to my iPod (and no, it is not transcoding the files). I have no idea if it's the same bug but it behaves the same.

 5865 david     20   0  827m 303m  16m S  178 15.3  65:56.56 banshee-1         

What can I do to figure out what is going on here?
Comment 4 Gabriel Burt 2009-05-14 16:36:13 UTC
Can you try running this:

sqlite3 ~/.config/banshee-1/banshee.db "vacuum; analyze" and see if things are better afterward?  We should probably do this after in the db migrations after all the change we are making.

How many tracks in your music library, btw?
Comment 5 David Nielsen 2009-05-15 18:29:18 UTC
9783 entries in the music library, 990 entries in the podcast library and one video all amounting to roughly 62gb of data. 

Additionally I have defined 4 smart playlists to filter out items like audiobooks and special podcast episodes (single downloads) as well as to give me a pure music playlist.

I still see problems switching views or to smart playlists after running the requested commands.
Comment 6 boris boef 2009-05-15 19:09:11 UTC
I also tried to run 

sqlite3 ~/.config/banshee-1/banshee.db "vacuum; analyze"

And I still get a very high CPU load when switching songs mostly.
I had it before when switching views but this is not the case anymore.

I'm using ubuntu 09.04

Is everyone on the master branch having this issue? Are there any other suggestions to see where the problem is/ debugging?
Comment 7 Gabriel Burt 2009-05-15 19:13:55 UTC
While the CPU is pegged at 100%, run

kill -s QUIT $(pidof banshee-1)

and paste or attach the output here.  The output will be in the terminal you ran banshee-1 from, or in your ~/.config/banshee-1/log if you ran it from a launcher.
Comment 8 Gabriel Burt 2009-05-15 19:17:16 UTC
In addition to the above test, do another test where you run with --debug-sql to see if it's a SQL query getting repeated forever.
Comment 9 boris boef 2009-05-15 19:24:29 UTC
Created attachment 134731 [details]
This is the output of the banshee-1 that I ran in the terminal during high cpu when I gave the kill command
Comment 10 boris boef 2009-05-15 19:25:27 UTC
I've run the kill command during 100% cpu and attached a file with the output of that.
Comment 11 Gabriel Burt 2009-05-15 20:36:59 UTC
The crux of the problem, from boris via irc:

[Debug 21:29:31.271] Executed in 10865ms SELECT COUNT(*), SUM(CoreTracks.FileSize) FROM CoreTracks,CoreAlbums,CoreArtists, CoreSmartPlaylistEntries WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 3
Comment 12 boris boef 2009-05-16 20:35:46 UTC
(In reply to comment #11)
> The crux of the problem, from boris via irc:
> 
> [Debug 21:29:31.271] Executed in 10865ms SELECT COUNT(*),
> SUM(CoreTracks.FileSize) FROM CoreTracks,CoreAlbums,CoreArtists,
> CoreSmartPlaylistEntries WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND
> CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID
> = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 3
> 

I have the feeling that is more the effect then the cause. Would be interesting to know if that query actually took the 100% CPU or that it just took such a long time because it was waiting for CPU time.
Comment 13 David Nielsen 2009-05-17 22:51:55 UTC
[Warn  00:44:50.367] HyenaSqliteConnection command issued from the main thread
[Debug 00:45:13.024] Executed in 22657ms SELECT COUNT(*), SUM(CoreTracks.FileSize) FROM CoreTracks,CoreArtists,CoreAlbums, CoreSmartPlaylistEntries WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 42 

[Warn  00:45:13.025] HyenaSqliteConnection command issued from the main thread
[Debug 00:45:19.280] Executed in 6256ms 
                    DELETE FROM CoreCache WHERE ModelID = 384;
                        INSERT INTO CoreCache (ModelID, ItemID) SELECT 384, CoreTracks.TrackID FROM CoreTracks,CoreArtists,CoreAlbums, CoreSmartPlaylistEntries WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 42  ORDER BY 
                        CoreAlbums.ArtistNameSortKey ASC, 
                        CoreAlbums.TitleSortKey ASC, 
                        CoreTracks.Disc ASC,
                        CoreTracks.TrackNumber ASC

These seem suspect to me.

Furthermore I tried deleting the smart playlists as I noticed that those two long queries came right after output that looked like it was poking at my defined lists. Without the smartlists view switching does not display the long pauses and 100% CPU load. 

I hope that is helpful.
Comment 14 Gabriel Burt 2009-05-18 23:49:33 UTC
Ok, the problem is SQLite only uses one index per query, and for those it is choosing the CoreSmartPlaylistEntriesPlaylistIndex index.  

Just dropping that index 'fixes' the problem:
sqlite3 ~/.config/banshee-1/banshee.db "drop index CoreSmartPlaylistEntriesPlaylistIndex"

I need to run some more performance tests to make sure that dropping it won't negatively impact other queries.
Comment 15 David Nielsen 2009-05-19 00:30:10 UTC
That does improve matters quite a bit. The long pauses are out and timings for sql queries are in a much saner range now.
Comment 16 boris boef 2009-05-19 08:14:20 UTC
Yes that helps ALOT! Thanks.
Comment 17 Gabriel Burt 2009-05-22 16:01:09 UTC
Fixed in master.
Comment 18 Alexander Kojevnikov 2009-08-03 07:42:51 UTC
(In reply to comment #17)
> Fixed in master.
> 

Gabriel, why both indices has been dropped in [1]? As far as I can see, only CoreSmartPlaylistEntries{PlaylistIndex} or rather the presence of two indices on the table has been causing problems.

CoreSmartPlaylistEntries{Index} is still needed for shuffle by rating/score, see comments 31-32 in bug 565767. Re-adding it doesn't seem to re-introduce this bug.

[1] http://git.gnome.org/cgit/banshee/commit/?id=23274f2ca744391ef3f54e044eb2f7399aa457ff
Comment 19 Alexander Kojevnikov 2009-08-10 00:47:09 UTC
I committed the new index after discussing the issue with Gabriel and checking that there is no regression with David.

If you experienced this bug, please do check that the index doesn't bring it back on your database.
Comment 20 Alexander Kojevnikov 2009-09-02 02:52:28 UTC
*** Bug 593817 has been marked as a duplicate of this bug. ***
Comment 21 David Nielsen 2009-09-05 23:38:51 UTC
[Debug 01:33:54.300] Executed in 16886ms SELECT COUNT(*), SUM(CoreTracks.FileSize) FROM CoreTracks,CoreArtists,CoreAlbums, CoreSmartPlaylistEntries WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 44 

I think this is still capable of great evil, I just saw the above as well as a 195% CPU load (Core 2 Duo laptop) followed by an entirely to predictable complete stall of the interface for minutes.
Comment 22 Alexander Kojevnikov 2009-09-06 02:55:29 UTC
David, does it go away if you temporarily drop the CoreSmartPlaylistEntriesIndex?
Comment 23 ganjalf.the.green 2009-10-30 15:23:06 UTC
@Alexander
The bug is back in the current PPA version of Banshee and yes, dropping the CoreSmartPlaylistEntriesIndex makes it go away. Dunno yet what functionality is taken away with dropping this index.
Comment 24 Alexander Kojevnikov 2009-11-02 05:15:46 UTC
(In reply to comment #23)
> @Alexander
> The bug is back in the current PPA version of Banshee and yes, dropping the
> CoreSmartPlaylistEntriesIndex makes it go away.

If you don't mind doing it, could you email me your database? Also, which version of sqlite do you have?

 $ sqlite3 --version

> Dunno yet what functionality is
> taken away with dropping this index.

See comment 18, the index is needed for shuffle by rating/score.
Comment 25 ganjalf.the.green 2009-11-02 08:53:09 UTC
(In reply to comment #24)
> 
> If you don't mind doing it, could you email me your database? Also, which
> version of sqlite do you have?
> 
>  $ sqlite3 --version

SQLite 3.6.10
Banshee 1.6 Beta 2 (1.5.1)

(The system is Ubuntu Jaunty 9.04.)
Comment 26 Alexander Kojevnikov 2009-11-02 12:01:07 UTC
ganjalf.the.green can no longer reproduce it after system upgrade... which smells like a sqlite3 versioning issue.

Is anyone still seeing it? If you are, could you open your database in sqlite3:

  $ sqlite3 ~/.config/banshee-1/banshee.db

and run this query:

  EXPLAIN QUERY PLAN SELECT COUNT(*), SUM(CoreTracks.FileSize) FROM CoreTracks,CoreArtists,CoreAlbums, CoreSmartPlaylistEntries WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 3;

It should take awhile to execute. Please then include its output in your comment. Thanks!
Comment 27 Mikayla Hutchinson 2009-12-02 23:49:34 UTC
It returns very quickly, with
0|2|TABLE CoreAlbums
1|3|TABLE CoreSmartPlaylistEntries WITH INDEX CoreSmartPlaylistEntriesIndex
2|0|TABLE CoreTracks USING PRIMARY KEY
3|1|TABLE CoreArtists USING PRIMARY KEY
Comment 28 Mikayla Hutchinson 2009-12-03 00:12:35 UTC
I have a super-slow query taking place:

[Debug 19:04:10.090] Executed in 7635ms
                    DELETE FROM CoreCache WHERE ModelID = 41;
                        INSERT INTO CoreCache (ModelID, ItemID) SELECT 41, CoreTracks.TrackID FROM CoreTracks,CoreArtists,CoreAlbums, CoreSmartPlaylistEntries WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 4  ORDER BY
                        CoreArtists.NameSortKey ASC,
                        CoreAlbums.TitleSortKey ASC,
                        CoreTracks.Disc ASC,
                        CoreTracks.TrackNumber ASC
Comment 29 Alexander Kojevnikov 2009-12-03 01:25:47 UTC
After playing with Michael's database I found a way to fix the offending query. The query below runs in about 7 seconds:

SELECT COUNT(*), SUM(CoreTracks.FileSize) FROM CoreTracks,CoreArtists,CoreAlbums, CoreSmartPlaylistEntries WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 4;

Its query plan:

0|2|TABLE CoreAlbums
1|3|TABLE CoreSmartPlaylistEntries WITH INDEX CoreSmartPlaylistEntriesIndex
2|0|TABLE CoreTracks USING PRIMARY KEY
3|1|TABLE CoreArtists USING PRIMARY KEY

After changing the query to use CROSS JOINS to force the join order (as explained in section 5.2 of http://www.sqlite.org/optoverview.html), the query runs instantly:

SELECT COUNT(*), SUM(CoreTracks.FileSize) FROM CoreArtists CROSS JOIN CoreTracks CROSS JOIN CoreSmartPlaylistEntries CROSS JOIN CoreAlbums WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND  CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID AND CoreSmartPlaylistEntries.SmartPlaylistID = 4;

0|0|TABLE CoreArtists
1|1|TABLE CoreTracks WITH INDEX CoreTracksIndex
2|2|TABLE CoreSmartPlaylistEntries WITH INDEX CoreSmartPlaylistEntriesIndex
3|3|TABLE CoreAlbums USING PRIMARY KEY

I will try to fix the offending query in the program and attach the patch...
Comment 30 Alexander Kojevnikov 2009-12-04 08:44:01 UTC
Created attachment 149074 [details] [review]
Force the join order

This patch should fix the slow queries. Please test.
Comment 31 Michael Martin-Smucker 2009-12-24 12:58:54 UTC
*** Bug 605358 has been marked as a duplicate of this bug. ***
Comment 32 Gabriel Burt 2009-12-24 19:07:17 UTC
Why don't you go ahead and commit - it'll probably get wider testing w/ the alpha repos and people building from master that way.
Comment 33 Alexander Kojevnikov 2009-12-27 02:27:02 UTC
Committed. Feel free to re-open if these queries are still slow or if you notice any side effects.

This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.