Bug 164974

Summary: IndexedDB 2.0: Cache and reuse SQLiteStatements in the SQLite backend
Product: WebKit Reporter: Brady Eidson <beidson>
Component: WebCore Misc.Assignee: Brady Eidson <beidson>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, alecflett, buildbot, cdumez, commit-queue, jsbell, rniwa
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=165222
https://bugs.webkit.org/show_bug.cgi?id=165216
Bug Depends on:    
Bug Blocks: 160306    
Attachments:
Description Flags
Patch
none
Patch
none
Archive of layout-test-results from ews105 for mac-yosemite-wk2
none
Patch none

Brady Eidson
Reported 2016-11-18 17:23:19 PST
IndexedDB 2.0: Cache and reuse SQLiteStatements in the SQLite backend sqlite_prepare_v2 is so hot that it's showing up at 15-20% on profiles of *one* specific test I'm working with. Yikes! Caching and re-using statements is an obvious win.
Attachments
Patch (76.94 KB, patch)
2016-11-29 14:21 PST, Brady Eidson
no flags
Patch (65.89 KB, patch)
2016-11-29 14:27 PST, Brady Eidson
no flags
Archive of layout-test-results from ews105 for mac-yosemite-wk2 (1.03 MB, application/zip)
2016-11-29 15:16 PST, Build Bot
no flags
Patch (66.72 KB, patch)
2016-11-30 10:39 PST, Brady Eidson
no flags
Brady Eidson
Comment 1 2016-11-29 14:21:20 PST
Brady Eidson
Comment 2 2016-11-29 14:26:13 PST
This caught two patches in the upload, whoops. Sending only one now...
Brady Eidson
Comment 3 2016-11-29 14:27:03 PST
Alex Christensen
Comment 4 2016-11-29 14:36:40 PST
Comment on attachment 295642 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=295642&action=review r=me > Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:2383 > + return m_cachedStatements[static_cast<int>(sql)].get(); This should be bounds checked just to be extra careful, with an ASSERT_NOT_REACHED of some sort. Also, size_t would be more appropriate than int.
Build Bot
Comment 5 2016-11-29 15:16:42 PST
Comment on attachment 295642 [details] Patch Attachment 295642 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.webkit.org/results/2591094 Number of test failures exceeded the failure limit.
Build Bot
Comment 6 2016-11-29 15:16:45 PST
Created attachment 295652 [details] Archive of layout-test-results from ews105 for mac-yosemite-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews105 Port: mac-yosemite-wk2 Platform: Mac OS X 10.10.5
Brady Eidson
Comment 7 2016-11-29 15:26:25 PST
Those failures are due to the classic "w3c web server stopped working" issue.
Brady Eidson
Comment 8 2016-11-29 15:28:38 PST
Brady Eidson
Comment 9 2016-11-29 17:13:06 PST
This caused issues under Guardmalloc with deadlocked TransactionOperations. Landing a stopgap fix until I can further explore why they aren't ref'ed
Brady Eidson
Comment 10 2016-11-29 17:16:53 PST
(In reply to comment #9) > This caused issues under Guardmalloc with deadlocked TransactionOperations. > > Landing a stopgap fix until I can further explore why they aren't ref'ed Landed this in https://trac.webkit.org/changeset/209104
Brady Eidson
Comment 11 2016-11-29 19:46:01 PST
(In reply to comment #10) > (In reply to comment #9) > > This caused issues under Guardmalloc with deadlocked TransactionOperations. > > > > Landing a stopgap fix until I can further explore why they aren't ref'ed > > Landed this in https://trac.webkit.org/changeset/209104 This fix caused storage/indexeddb/modern/gc-closes-database.html and storage/indexeddb/modern/gc-closes-database-private.html to start timing out (I'm sure of why, also) I'll skip them until I can resolve this mess tomorrow.
Brady Eidson
Comment 12 2016-11-29 19:51:53 PST
(In reply to comment #11) > (In reply to comment #10) > > (In reply to comment #9) > > > This caused issues under Guardmalloc with deadlocked TransactionOperations. > > > > > > Landing a stopgap fix until I can further explore why they aren't ref'ed > > > > Landed this in https://trac.webkit.org/changeset/209104 > > This fix caused storage/indexeddb/modern/gc-closes-database.html and > storage/indexeddb/modern/gc-closes-database-private.html to start timing out > (I'm sure of why, also) > > I'll skip them until I can resolve this mess tomorrow. Skipped in https://trac.webkit.org/changeset/209114 Resolving the GuardMalloc *and* leak issue will happen over in bug https://bugs.webkit.org/show_bug.cgi?id=165186
Chris Dumez
Comment 13 2016-11-29 20:37:27 PST
Reverted r209096, r209104, and r209114 for reason: Caused over 200 layout test failures on the bots Committed r209117: <http://trac.webkit.org/changeset/209117>
Chris Dumez
Comment 14 2016-11-29 20:37:32 PST
Reverted r209096, r209104, and r209114 for reason: Caused over 200 layout test failures on the bots Committed r209117: <http://trac.webkit.org/changeset/209117>
Chris Dumez
Comment 15 2016-11-29 20:38:22 PST
(In reply to comment #14) > Reverted r209096, r209104, and r209114 for reason: > > Caused over 200 layout test failures on the bots > > Committed r209117: <http://trac.webkit.org/changeset/209117> E.g. https://build.webkit.org/builders/Apple%20El%20Capitan%20Release%20WK2%20%28Tests%29/builds/11350
Chris Dumez
Comment 16 2016-11-29 20:40:42 PST
(In reply to comment #15) > (In reply to comment #14) > > Reverted r209096, r209104, and r209114 for reason: > > > > Caused over 200 layout test failures on the bots > > > > Committed r209117: <http://trac.webkit.org/changeset/209117> > > E.g. > https://build.webkit.org/builders/ > Apple%20El%20Capitan%20Release%20WK2%20%28Tests%29/builds/11350 Note that https://trac.webkit.org/changeset/209104 did not help fix those layout test failures.
Brady Eidson
Comment 17 2016-11-29 23:33:57 PST
(In reply to comment #16) > (In reply to comment #15) > > (In reply to comment #14) > > > Reverted r209096, r209104, and r209114 for reason: > > > > > > Caused over 200 layout test failures on the bots > > > > > > Committed r209117: <http://trac.webkit.org/changeset/209117> > > > > E.g. > > https://build.webkit.org/builders/ > > Apple%20El%20Capitan%20Release%20WK2%20%28Tests%29/builds/11350 > > Note that https://trac.webkit.org/changeset/209104 did not help fix those > layout test failures. It wasn't meant to help fix those, which I didn't even know were happening. It *was* meant to fix GuardMalloc failures from a previous changeset that I guess was now reintroduced. It's somewhat surprising this change caused all that, but whatever - I'll sort it out in the A.M.
Chris Dumez
Comment 18 2016-11-30 08:14:39 PST
(In reply to comment #17) > (In reply to comment #16) > > (In reply to comment #15) > > > (In reply to comment #14) > > > > Reverted r209096, r209104, and r209114 for reason: > > > > > > > > Caused over 200 layout test failures on the bots > > > > > > > > Committed r209117: <http://trac.webkit.org/changeset/209117> > > > > > > E.g. > > > https://build.webkit.org/builders/ > > > Apple%20El%20Capitan%20Release%20WK2%20%28Tests%29/builds/11350 > > > > Note that https://trac.webkit.org/changeset/209104 did not help fix those > > layout test failures. > > It wasn't meant to help fix those, which I didn't even know were happening. > > It *was* meant to fix GuardMalloc failures from a previous changeset that I > guess was now reintroduced. I rolled out all 3 changesets so I do not think I reintroduced failures but I could be wrong. > > It's somewhat surprising this change caused all that, but whatever - I'll > sort it out in the A.M. Looks like the roll out was successful on the bots: - Before: https://build.webkit.org/builders/Apple%20Yosemite%20Release%20WK2%20%28Tests%29/builds/19663 - After: https://build.webkit.org/builders/Apple%20Yosemite%20Release%20WK2%20%28Tests%29/builds/19664 The remaining unit test failure was caused by another change which was rolled out later on and we are green as of: https://build.webkit.org/builders/Apple%20Yosemite%20Release%20WK2%20%28Tests%29/builds/19665
Brady Eidson
Comment 19 2016-11-30 10:23:17 PST
I can reproduce locally, only with the w3c tests, after a certain number of tests have run in a given process. e.g.: run-webkit-tests --child-processes=1 imported/w3c/web-platform-tests/IndexedDB/idbcursor_update_index3.htm --iterations=20000 Hammers the same test over and over, and after 68 runs it starts failing. lsof confirms tons of handles to databases from past tests are still open, so opening new database files fails (limit to the number of file handles per process) I'm still unclear how this change caused leaking file handles, but there's not much surface to go over.
Brady Eidson
Comment 20 2016-11-30 10:23:43 PST
(In reply to comment #19) > I can reproduce locally, only with the w3c tests, after a certain number of > tests have run in a given process. > > e.g.: > run-webkit-tests --child-processes=1 > imported/w3c/web-platform-tests/IndexedDB/idbcursor_update_index3.htm > --iterations=20000 > > Hammers the same test over and over, and after 68 runs it starts failing. > > lsof confirms tons of handles to databases from past tests are still open, > so opening new database files fails (limit to the number of file handles per > process) > > I'm still unclear how this change caused leaking file handles, but there's > not much surface to go over. It's also quite unclear why this *doesn't* affect DRT, but only WKTR. o_O
Brady Eidson
Comment 21 2016-11-30 10:25:40 PST
(In reply to comment #20) > (In reply to comment #19) > > I can reproduce locally, only with the w3c tests, after a certain number of > > tests have run in a given process. > > > > e.g.: > > run-webkit-tests --child-processes=1 > > imported/w3c/web-platform-tests/IndexedDB/idbcursor_update_index3.htm > > --iterations=20000 > > > > Hammers the same test over and over, and after 68 runs it starts failing. > > > > lsof confirms tons of handles to databases from past tests are still open, > > so opening new database files fails (limit to the number of file handles per > > process) > > > > I'm still unclear how this change caused leaking file handles, but there's > > not much surface to go over. > > It's also quite unclear why this *doesn't* affect DRT, but only WKTR. o_O DRT is leaking the handles, also. This must be "app process" vs "XPC service process" limitations. DRT *does* start failing after enough runs (850 instead of 68)
Brady Eidson
Comment 22 2016-11-30 10:35:33 PST
Okay figured it out - If you close a sqlite3 handle while you still have prepared statements open, it leaks the file handles. o_O Exact same patch with a couple of sqlite cleanup calls moved around fixes this.
Brady Eidson
Comment 23 2016-11-30 10:39:05 PST
WebKit Commit Bot
Comment 24 2016-11-30 11:59:22 PST
Comment on attachment 295730 [details] Patch Clearing flags on attachment: 295730 Committed r209144: <http://trac.webkit.org/changeset/209144>
WebKit Commit Bot
Comment 25 2016-11-30 11:59:27 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.