Repository navigation
refactor(pool): admit tasks at the connection pool - #7
Merged
Merged
Conversation
SmbTask kept a list of operators, a pending counter, and per-op progress for spawn(), which no operator calls. Each task also started a detached thread while the thread that launched it blocked in start(). Run the single operator inline on the thread that starts the task. - remove spawn, launchOp, appendOps, pending_, and OperatorContext::opIndex - track one progress entry; onOpStatus/onOpProgress drop the op index - run() replaces start() and calls the operator instead of waiting on a completion future
publishResult wrote resultValue_ without stateMutex_ while publishedResult read it under the lock, so a JS read could race the operator thread. - take stateMutex_ in publishResult
MetadataContextLease only wrapped a PoolContextHandle, and copyTreeImpl acquired its own lease when a caller passed none. A caller that already held a slot could then wait on itself once the pool was full. Take the caller's handle instead. - delete MetadataContextLease.hpp and OperatorBase::makeMetadataLease - copyTreeImpl and inspectCopyTreeSource take a required PoolContextHandle& - copy and duplicate request a Metadata context directly
Delete gave up its slot after stat and again before unlink or the tree delete, so each phase queued behind other work for a new slot. Keep the first slot for the whole delete. - stat, unlink, and the listed tree delete share one context
listShares was the only request that could not add a slot. When it reached the head of the queue with every slot busy, tryAssignNext stopped there, and growable requests behind it waited even though the pool could open another slot. The operator now requests a context like any other Interactive operation. - ListSharesOperator enumerates through the granted handle's manager - remove SmbConnectionPool::listShares and canGrowPoolSlot
Each operator called requestContext inside run(), so its mode was only known once the operator was already running. Operators now declare their mode, and the task acquires the slot before run() and hands it over through context(). Argument checks and task paths move to prepare(), so they still happen before the task waits for a slot. - add acquireMode(); nullopt marks lifecycle operators - listDirectory picks Interactive or Metadata from maxDepth - add prepare() for validation and setSourceDestination, without SMB I/O - remove OperatorBase::requestContext; operators use context()
Every work task first waited in Nitro's shared Promise::async queue, which has at most 10 threads and grows lazily, and then kept one of those threads blocked for its whole run. Under bulk work, interactive requests waited behind it before they reached the pool's interactive-first queue. Queue work only at the pool and start a thread once a slot is granted. - requestContext is asynchronous: it queues ContextCallbacks and returns at once - SlotReservation is a move-only handle to a reserved slot; activate() connects on the runner thread, never on the JS thread or a releasing thread - callbacks fire outside the pool mutex; cancel, drain, and NotConnected reject queued requests without starting a thread - SmbTask::prepare/run/reject replace the blocking run; lifecycle tasks run inline on the lifecycle thread - remove ExecutionLane and PoolSlot::accepts; startTask routes by acquireMode() - queued tasks now report Pending instead of Idle
Describe the single admission point, the one-task-one-slot rule, the thread bounds, and when a task reports Pending. - add a Task admission section to ARCHITECTURE - note that every request may open a slot; drop the PoolSlot::accepts snippet - TASK_MODEL: status is Pending while queued for a slot
Pending/Running need clear labels. - Active/Waiting badges - Running before Pending - In progress / Finished
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor: admit tasks at the connection pool
Why
Every work task waited in two queues. First,
Promise::asyncput it on Nitro's shared thread pool, which has at most 10 threads, starts with 3, and adds a thread only when a task is already waiting. Then the operator asked the connection pool for a slot, where interactive requests go first.Under bulk work, such as thousands of
duplicateItemcalls, the first queue filled up. AgetPathInfoorlistDirectorywaited behind them before it ever reached the pool's interactive-first queue. Each task also used two threads: a Nitro thread blocked infut.wait(), and a detached thread that did the work.What
Pendinginstead ofIdle.Design
requestContextis asynchronous. It queuesContextCallbacks(onGranted,onRejected) and returns at once. Exactly one callback runs per request, outside the pool mutex.SlotReservation: a move-only handle to a slot markedActivating.activate()connects the slot if needed (TCP, negotiate, session setup, tree connect) on the task's own thread. Before, this ran insidetryAssignNexton whichever thread called it, which could be a thread that was releasing a slot. With the new asynchronous flow it would have been the JS thread. Dropping a reservation without activating it frees the slot.acquireMode()returnsInteractive,Metadata, ornulloptfor lifecycle operators.listDirectorypicks based onmaxDepth. Operators usecontext()and can no longer request a slot themselves, which also removes the possibility of a task waiting on itself for a second slot.prepare(): argument checks andsetSourceDestinationrun before the task queues. Queued transfers still show their paths, and invalid arguments fail without taking a place in the queue.Cancelledonce activation returns.initialize,connect,connectShare, anddisconnecttake no slot. They run inline on the lifecycle thread.Related cleanups
listSharesis a normal Interactive request. It was the only request that could not open a new slot; with every slot busy it sat at the head of the queue and blocked requests behind it that could have opened one.deleteItemkeeps one Metadata slot for stat, unlink, and tree delete. Before, it released the slot and queued again between phases.SmbTaskruns a single operator. The unusedspawn(), multi-operator bookkeeping, and per-operator progress are removed.MetadataContextLease.copyTreeImpltakes the caller's handle and no longer acquires its own slot when none is passed.publishResultnow writes understateMutex_, which matches howpublishedResultreads it.Notes for reviewers
perf(pool): admit work at the pool…) is the core change. Commits 1–6 prepare for it and each builds on its own.requestContextmay runonRejectedsynchronously when the pool is not running. In that case a task can settle beforestartTaskreturns, the same final state as before but no longer delayed by a hop to a Nitro thread.destroy()still usesPromise::async. No task holds a Nitro thread anymore, so it no longer waits behind running tasks.