prometheus/prometheus

Proposal: add `Close()` method to `index.Postings` interface

Open

#15 160 ouverte le 14 oct. 2024

Voir sur GitHub
 (3 commentaires) (2 réactions) (0 assignés)Go (10 408 forks)batch import
component/tsdbhelp wantedkind/featurenot-as-easy-as-it-lookspriority/P3

Métriques du dépôt

Stars
 (64 042 stars)
Métriques de merge PR
 (Merge moyen 11j 5h) (118 PRs mergées en 30 j)

Description

Proposal

Under heavy loads we allocate lots of ListPostings and similar objects, and we could benefit from some pooling to reduce pressure on the GC.

However, there's no clear closing call on the postings, even though the contract is clear: once Postings.Next() is false, there's nothing else we can do with them.

What if we added a Close() method to postings interface and did some recycling in that call, assuming that the instance isn't going to be used anymore.

The largest issue I see is that existing codebases (especially downstream projects) will fail to review all their calls, so we won't be able to rely on that call for a while, and we'll have to be just optimistic.

An alternative I considered was to implement just a recycle() method on ListPostings and bigEndianPostings, and call it from intersectPostings and removedPostings, as those are likely the major consumers of the former ones.

Guide contributeur