Closed Bug 1791767 Opened 2 years ago Closed 3 months ago

Replace IndexedDB connection pool thread management with task queues on top of a thread pool

Categories

(Core :: Storage: IndexedDB, task)

task

Tracking

()

RESOLVED FIXED
126 Branch
Tracking Status
firefox108 --- wontfix
firefox126 --- wontfix
firefox127 + wontfix
firefox128 --- fixed

People

(Reporter: jstutte, Assigned: jjalkanen)

References

(Blocks 12 open bugs)

Details

Attachments

(9 files, 15 obsolete files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

be1cda4f-0d00-45f0-8802-629180220919 shows a case with IndexedDB #1,SHDRCV being stuck on a SpinEventLoopUntil:

0	ZwWaitForAlertByThreadId
1	RtlSleepConditionVariableSRW
2	SleepConditionVariableSRW
3	mozilla::detail::ConditionVariableImpl::wait(mozilla::detail::MutexImpl&)
4	mozilla::OffTheBooksCondVar::Wait()
4	mozilla::ThreadEventQueue::GetEvent(bool, mozilla::BaseTimeDuration<mozilla::TimeDurationValueCalculator>*)
4	nsThread::ProcessNextEvent(bool, bool*)
5	NS_ProcessNextEvent(nsIThread*, bool)
6	mozilla::SpinEventLoopUntil(nsTSubstring<char> const&, mozilla::dom::indexedDB::(anonymous namespace)::ConnectionPool::ThreadRunnable::Run::<lambda_87>&&, nsIThread*)
6	mozilla::dom::indexedDB::(anonymous namespace)::ConnectionPool::ThreadRunnable::Run()
7	nsThread::ProcessNextEvent(bool, bool*)
8	NS_ProcessNextEvent(nsIThread*, bool)
8	mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate*)

This indicates a possible misalignment between gLiveDatabaseHashtable->Count() being zero during QuotaManager shutdown (which was not blocked) and the ConnectionPool state, as it needs to explicitly call ConnectionPool::ShutdownThread for all its threads to unblock that SpinEventLoopUntil we see blocking here.

I am also wondering if with bug 1121282 fixed we could simplify this whole thing by not managing our own thread pool at all but just using a normal nsThreadPool ? IIUC the main purpose of the ConnectionPool's thread handling is to guarantee to use a connection only on the same thread it was created on ?

See Also: → 1121282

I think with that relaxed we can actually go a step further and just use an NS_CreateBackgroundTaskQueue-created queue for each connection "thread" and bypass the need for a custom pool at all, noting that ConnectionPool also provides the mechanism for tracking when a connection is idle and triggers closing of the database because it's idle to limit resource usage. Since file descriptors continue to not be infinite, it does seem appropriate to continue to keep the idle mechanism, and there's a bunch of related logic that would probably get renamed/refactored, like ConnectionPool::ScheduleTransaction.

As to comment 0 and be1cda4f-0d00-45f0-8802-629180220919, yeah it seems like there's a race with thread creation and shutdown or something like that, because IPDL Background and the QM I/O thread are definitely already gone, which suggests the thread was created very late.

See Also: → 1794591
Assignee: nobody → jjalkanen
Attachment #9300520 - Attachment description: Bug 1791767 - Replace ConnectionPool of IndexedDB with background event target. r=#dom-storage → Bug 1791767 - Replace ConnectionPool of IndexedDB with background event target. r=asuth,#dom-storage
Attachment #9300519 - Attachment is obsolete: true
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d0fd41bff926 Add ISUPPORTS declaration macro for event targets. r=xpcom-reviewers,nika
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 108 Branch
Status: RESOLVED → REOPENED
Keywords: leave-open
Resolution: FIXED → ---
Blocks: 1749082
Blocks: 1803281
Attachment #9300520 - Attachment description: Bug 1791767 - Replace ConnectionPool of IndexedDB with background event target. r=asuth,#dom-storage → Bug 1791767 - Use task queues on stream transport service for IDB ConnectionPools. r=asuth,#dom-storage
Blocks: 1804397
Blocks: 1804401

Depends on D165984

Depends on D165984

Depends on D179089

Attachment #9316785 - Attachment is obsolete: true
Blocks: 1837369

Comment on attachment 9335903 [details]
Bug 1791767 - Replace single element array with a pointer class. r=#dom-storage

Revision D179090 was moved to bug 1837369. Setting attachment 9335903 [details] to obsolete.

Attachment #9335903 - Attachment is obsolete: true

Is this still a "leave-open" bug? If so, why?

Originally, the leave-open tag was added because we needed an extension to a utility in a different component as a prerequisite for other work related to this bug, and did not want the automation to close the ticket after the first item landed.

Now, the most relevant patches are still in review but we probably don't want to land (merge) them one by one so from that point of view, we don't need the leave-open tag anymore. After the patches are in, the code path which is relevant for the hang has been removed, so keeping the leave-open tag for monitoring purposes also won't be purposeful.

Blocks: 1846510
Attachment #9310714 - Attachment description: Bug 1791767 - Stop maintenance when threads are used up. r=#dom-storage,janv → Bug 1791767 - Stop maintenance when threads are needed or connection is closed. r=#dom-storage,janv

(In reply to Jari Jalkanen from comment #15)

Originally, the leave-open tag was added because we needed an extension to a utility in a different component as a prerequisite for other work related to this bug, and did not want the automation to close the ticket after the first item landed.

Now, the most relevant patches are still in review but we probably don't want to land (merge) them one by one so from that point of view, we don't need the leave-open tag anymore. After the patches are in, the code path which is relevant for the hang has been removed, so keeping the leave-open tag for monitoring purposes also won't be purposeful.

So, this is all still pending a review?

Flags: needinfo?(jjalkanen)

Yes, it shouldn't take long.

Flags: needinfo?(jjalkanen)
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e1593dd3fcc0 Use task queues on stream transport service for IDB ConnectionPools. r=dom-storage-reviewers,asuth,jstutte https://hg.mozilla.org/integration/autoland/rev/6980270f21e4 Stop maintenance when threads are needed or connection is closed. r=dom-storage-reviewers,jstutte
No longer blocks: 1803281
Attachment #9335902 - Attachment is obsolete: true
Attachment #9357038 - Attachment description: Bug 1791767 - Simplify databases complete callbacks. r=#dom-storage → WIP: Bug 1791767 - Simplify databases complete callbacks. r=#dom-storage
Attachment #9300520 - Attachment description: Bug 1791767 - Use task queues on stream transport service for IDB ConnectionPools. r=asuth,#dom-storage → WIP: Bug 1791767 - Use task queues on stream transport service for IDB ConnectionPools. r=asuth,#dom-storage
Attachment #9310714 - Attachment description: Bug 1791767 - Stop maintenance when threads are needed or connection is closed. r=#dom-storage,janv → WIP: Bug 1791767 - Stop maintenance when threads are needed or connection is closed. r=#dom-storage,janv

Depends on D190599

CachingDatabaseConnection relies on a global macro to toggle thread
ownership checks. The checks do not work with thread pool event targets
and by this change we ensure that the global macro users are not
impacted by such event target changes.

Depends on D190600

Attachment #9357038 - Attachment description: WIP: Bug 1791767 - Simplify databases complete callbacks. r=#dom-storage → Bug 1791767 - Simplify databases complete callbacks. r=#dom-storage
Attachment #9357658 - Attachment description: WIP: Bug 1791767 - Use a serial event target to debug IDB connection threads. r=#dom-storage → Bug 1791767 - Use a serial event target to debug IDB connection threads. r=#dom-storage
Attachment #9357661 - Attachment description: WIP: Bug 1791767 - Exclude CachingDatabaseConnection with event target from general thread checks. r=#dom-storage → Bug 1791767 - Exclude CachingDatabaseConnection with event target from general thread checks. r=#dom-storage
Attachment #9310714 - Attachment description: WIP: Bug 1791767 - Stop maintenance when threads are needed or connection is closed. r=#dom-storage,janv → Bug 1791767 - Stop maintenance when threads are needed or connection is closed. r=#dom-storage,janv
Attachment #9357659 - Attachment description: WIP: Bug 1791767 - Make thread pool event target available in IDB ConnectionPool. r=#dom-storage → Bug 1791767 - Make thread pool event target available in IDB ConnectionPool. r=#dom-storage
Attachment #9357660 - Attachment description: WIP: Bug 1791767 - Use task queue on thread pool as event target for IDB database connections. r=#dom-storage → Bug 1791767 - Use task queue on thread pool as event target for IDB database connections. r=#dom-storage
Attachment #9300520 - Attachment description: WIP: Bug 1791767 - Use task queues on stream transport service for IDB ConnectionPools. r=asuth,#dom-storage → Bug 1791767 - Use task queues on stream transport service for IDB ConnectionPools. r=asuth,#dom-storage
Blocks: 1858625
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b84d0334c5c2 Simplify databases complete callbacks. r=dom-storage-reviewers,janv
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4e3e2379861f Use a serial event target to debug IDB connection threads. r=dom-storage-reviewers,janv
Blocks: 1858989
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/72be6393ca5f Exclude CachingDatabaseConnection with event target from general thread checks. r=dom-storage-reviewers,janv

Comment on attachment 9357660 [details]
Bug 1791767 - Remove IDB transaction scheduling queue. r=#dom-storage

Revision D190600 was moved to bug 1791766. Setting attachment 9357660 [details] to obsolete.

Attachment #9357660 - Attachment is obsolete: true

Depends on D165984

Depends on D190600

Attachment #9300520 - Attachment description: Bug 1791767 - Use task queues on stream transport service for IDB ConnectionPools. r=asuth,#dom-storage → Bug 1791767 - Remove unused thread management code from IDB ConnectionPool. r=asuth,#dom-storage

Depends on D190600

Attachment #9359073 - Attachment is obsolete: true
Attachment #9359072 - Attachment is obsolete: true
Attachment #9359071 - Attachment is obsolete: true
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c2b7b572d19b Make thread pool event target available in IDB ConnectionPool. r=dom-storage-reviewers,janv
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4b6bd9b6e697 Manage thread serial numbers from IDB ConnectionPool. r=dom-storage-reviewers,janv

Depends on D191452

Attachment #9359393 - Attachment description: WIP: Bug 1791767 - Add BackgroundThread context checks. r=#dom-storage → Bug 1791767 - Add BackgroundThread context checks. r=#dom-storage
Attachment #9359394 - Attachment description: WIP: Bug 1791767 - Dispatch IDB idle maintenance with InvokeAsync and promises. r=#dom-storage → Bug 1791767 - Dispatch IDB idle maintenance with InvokeAsync and promises. r=#dom-storage
Attachment #9359395 - Attachment description: WIP: Bug 1791767 - Remove IdleConnectionRunnable class. r=#dom-storage → Bug 1791767 - Remove IdleConnectionRunnable class. r=#dom-storage
Summary: Verify if the IndexedDB connection pool threads are explicitly closed on shutdown → Replace IndexedDB connection pool thread management with task queues on top of a thread pool
Attachment #9310714 - Attachment description: Bug 1791767 - Stop maintenance when threads are needed or connection is closed. r=#dom-storage,janv → Bug 1791767 - Change maintenance interupt signal from posted runnable to flag. r=#dom-storage,janv
Attachment #9359085 - Attachment description: Bug 1791767 - Remove IDB ConnectionPool idle thread management. r=#dom-storage → Bug 1791767 - Use task queues on nsThreadPool for IDB connections. r=#dom-storage
Attachment #9310714 - Attachment description: Bug 1791767 - Change maintenance interupt signal from posted runnable to flag. r=#dom-storage,janv → Bug 1791767 - Change maintenance interupt signal from posted runnable to flags. r=#dom-storage,janv
Attachment #9359393 - Attachment is obsolete: true
Depends on: 1878841
Depends on: 1879493
No longer blocks: 1858989
Depends on: 1858989
Attachment #9357660 - Attachment description: Bug 1791767 - Use task queue on thread pool as event target for IDB database connections. r=#dom-storage → Bug 1791767 - Remove IDB transaction scheduling queue. r=#dom-storage
Attachment #9357660 - Attachment is obsolete: false
Attachment #9310714 - Attachment description: Bug 1791767 - Change maintenance interupt signal from posted runnable to flags. r=#dom-storage,janv → Bug 1791767 - Interrupt IDB idle maintenance with atomic flag. r=#dom-storage,janv
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/520bd9381f15 Interrupt IDB idle maintenance with atomic flag. r=janv,dom-storage-reviewers,jstutte

Backed out or causing bustages on ActorsParent.cpp

Backout link

Push with failures

Failure log

Flags: needinfo?(jjalkanen)
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/592e22279f89 Interrupt IDB idle maintenance with atomic flag. r=janv,dom-storage-reviewers,jstutte
Flags: needinfo?(jjalkanen)
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/df9f354630cf Relax timing dependent IDB maintenance test thresholds. r=dom-storage-reviewers,janv https://hg.mozilla.org/integration/autoland/rev/01eef2ce9d20 Use task queues on nsThreadPool for IDB connections. r=dom-storage-reviewers,janv

Backed out for causing build bustages in ActorsParent.cpp

  • Backout link
  • Push with failures
  • Failure Log
  • Failure line: /builds/worker/checkouts/gecko/dom/indexedDB/ActorsParent.cpp:8824:1: error: 'mozilla::dom::indexedDB::{anonymous}::ConnectionPool::IdleThreadInfo::~IdleThreadInfo()' defined but not used [-Werror=unused-function]
Flags: needinfo?(jjalkanen)
Attachment #9300520 - Attachment is obsolete: true
Pushed by jjalkanen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/abb086864075 Relax timing dependent IDB maintenance test thresholds. r=dom-storage-reviewers,janv https://hg.mozilla.org/integration/autoland/rev/58f4bf812f63 Use task queues on nsThreadPool for IDB connections. r=dom-storage-reviewers,janv
Target Milestone: 108 Branch → ---
Blocks: 1889563
Regressions: 1891227

The main patch replacing the custom thread pool with nsThreadPool landed.

Flags: needinfo?(jjalkanen)

After a thorough discussion about performance regression 1891227, the following plan was conceived:

We would like to back out patch https://phabricator.services.mozilla.com/D191296 from beta, to keep the regression from impacting the users, but keep it in nightly and actively work to overcome the regression. There are already some preliminary investigations on nsThreadPool addressing the challenge.

Jari, we are nearing the start of the 127 beta cycle and bug 1891227 was not fixed, should we back out D191296 again when we reach beta?

Flags: needinfo?(jjalkanen)

It would be nice if you could back it out once more, thank you! The related fix probably won't quite make it to this cycle.

Flags: needinfo?(jjalkanen)
Flags: needinfo?(pascalc)
Flags: needinfo?(pascalc)

The fix to the performance surprise 1891227 landed so there is no longer a reason why this could not ride the trains, once more.

Flags: needinfo?(pascalc)
Blocks: 1900379
Blocks: 1900380

Comment on attachment 9394936 [details]
Bug 1791767 - Remove unneeded AdjustIdleTimer call; r=#dom-storage

Revision D206588 was moved to bug 1900380. Setting attachment 9394936 [details] to obsolete.

Attachment #9394936 - Attachment is obsolete: true
Blocks: 1900382

Comment on attachment 9352049 [details]
Bug 1791767 - Test IDB and OPFS interaction under heavy load; r=#dom-storage

Revision D187686 was moved to bug 1900382. Setting attachment 9352049 [details] to obsolete.

Attachment #9352049 - Attachment is obsolete: true

Set status for 126 and 127 to wontfix since it was backed out on those branches.

Target Milestone: --- → 126 Branch
Flags: needinfo?(pascalc)

Do we need to move some of the open patches to another bug to be able to close this such that the status flags continue to make sense?

Flags: needinfo?(jjalkanen)
Blocks: 1903603

Comment on attachment 9357660 [details]
Bug 1791767 - Remove IDB transaction scheduling queue. r=#dom-storage

Revision D190600 was moved to bug 1903603. Setting attachment 9357660 [details] to obsolete.

Attachment #9357660 - Attachment is obsolete: true
Blocks: 1903607

Comment on attachment 9359086 [details]
Bug 1791767 - Drain IDB task queues on shutdown. r=#dom-storage

Revision D191297 was moved to bug 1903607. Setting attachment 9359086 [details] to obsolete.

Attachment #9359086 - Attachment is obsolete: true
Blocks: 1903614

Comment on attachment 9359395 [details]
Bug 1791767 - Remove IdleConnectionRunnable class. r=#dom-storage

Revision D191453 was moved to bug 1903614. Setting attachment 9359395 [details] to obsolete.

Attachment #9359395 - Attachment is obsolete: true

Comment on attachment 9359394 [details]
Bug 1791767 - Dispatch IDB idle maintenance with InvokeAsync and promises. r=#dom-storage

Revision D191452 was moved to bug 1903614. Setting attachment 9359394 [details] to obsolete.

Attachment #9359394 - Attachment is obsolete: true

The patches which were not strictly required for this ticket were moved to dedicated items.

Flags: needinfo?(jjalkanen)

All the patches still associated with this bug landed. https://phabricator.services.mozilla.com/D191296 was only backed out of Beta, so it is still fixed for Firefox 128.

Status: REOPENED → RESOLVED
Closed: 2 years ago3 months ago
Resolution: --- → FIXED
No longer blocks: 1900379
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: