Skip to content

feat: add fifo option for pool connection acquisition#4

Open
tgriesser wants to merge 1 commit into
mainfrom
tgriesser/feat/fifo-pool-option
Open

feat: add fifo option for pool connection acquisition#4
tgriesser wants to merge 1 commit into
mainfrom
tgriesser/feat/fifo-pool-option

Conversation

@tgriesser

@tgriesser tgriesser commented Jul 8, 2026

Copy link
Copy Markdown
Member

I'm not sure I ever thought about it critically, but the current approach tarn takes with connection reuse is LIFO. This means that the most recent connections in the stack stay "hot" and get reused again and again, while the earliest created connections will likely not get used and after awhile and will be removed via the idleTimeout reaper.

This is a good thing if you want to keep the number of connections to a minimum, however it's not as helpful if you want to ensure resources stick around for a bit, so that you have enough available for bursts of traffic. Really depends on whether you value keeping the number of active resources low or the frequency of disconnects/reconnects low.

This PR adds a new option fifo, defaulting to false (current behavior), with the option to set to true to pull from the front of the "free" resource queue. This should also help with situations where there's a set number of "min" resources and some of them timeout due to inactivity during periods of relatively low query volume, because all of the requests go to the most recently used items.

Would also be fine with naming the option something more explicit like is mentioned in the issue below:

freeResourceSelectionAlgorithm: 'fifo' | 'lifo' // default 'lifo'

Related: Vincit/tarn.js#76

Comment thread src/Pool.ts
log?: (msg: string) => any;
validate?: (resource: T) => boolean;
propagateCreateError?: boolean;
fifo?: boolean;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually went to use this via patch-package somewhere and noticed a warning:

Pool config option "fifo" is no longer supported. See https://github.com/Vincit/tarn.js for possible pool config options.

Due to checking for options from the old pooling and warning

So maybe better to go with the more explicit freeResourceSelectionAlgorithm

@igalklebanov igalklebanov Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More explicit definitely better here.

Personally,
I'm vibing more with "idle" than "free". "free" is an overloaded term that can confuse - in this context, to the point where someone thinks this is related to the freeing of resources.
And with "strategy" more than "algorithm".

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could later, if necessary, allow passing a custom strategy, or add more built-ins like "round-robin".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants