Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dbnode] Remove tag decoders from write tagged requests. #3472

Merged
merged 7 commits into from
May 10, 2021

Conversation

soundvibe
Copy link
Collaborator

@soundvibe soundvibe commented May 6, 2021

What this PR does / why we need it:

Removes tag decoders and their pools from write paths. This change should reduce memory usage and avoid huge memory usage spikes when writes are increased.
Introduced TagMetadataResolver which wraps conversion methods from encoded tags, tag iterators and decoded tags.

Heap profile before this PR:
heap-profile-before

Heap profile with the changes from this PR:
Screenshot 2021-05-07 at 14 42 09

Special notes for your reviewer:

Does this PR introduce a user-facing and/or backwards incompatible change?:


Does this PR require updating code package or user-facing documentation?:


soundvibe added 4 commits May 6, 2021 12:31
Introduced TagMetadataResolver which wraps convertion methods from encoded tags, tag iterators and decoded tags.
* master:
  Skip source Middleware if M3-Source header is missing (#3470)
  Add Middleware to populate source in request context (#3467)
  Add a request scoped logger to a context (#3466)
  Add configurable Middleware to query server (#3463)
@codecov
Copy link

codecov bot commented May 7, 2021

Codecov Report

Merging #3472 (23a6d9a) into master (58e9631) will decrease coverage by 0.1%.
The diff coverage is 83.0%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #3472     +/-   ##
========================================
- Coverage    56.0%   55.9%   -0.2%     
========================================
  Files         548     549      +1     
  Lines       61188   61146     -42     
========================================
- Hits        34308   34197    -111     
- Misses      23797   23857     +60     
- Partials     3083    3092      +9     
Flag Coverage Δ
aggregator 57.3% <ø> (ø)
cluster ∅ <ø> (∅)
collector 54.3% <ø> (ø)
dbnode 60.3% <83.0%> (-0.2%) ⬇️
m3em 46.4% <ø> (ø)
metrics 19.8% <ø> (ø)
msg 74.4% <ø> (-0.3%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58e9631...23a6d9a. Read the comment docs.

// namespace
pooledIDs := make([]writeBatchPooledReqID, 1+(2*client.DefaultWriteBatchSize))
// NB(r): Make pooled IDs 1x the default write batch size plus an extra one for the namespace
pooledIDs := make([]writeBatchPooledReqID, 1+client.DefaultWriteBatchSize)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we don't pool tag decoders, we can reduce pooledIDs by 2x.

@@ -108,15 +108,14 @@ func (b *writeBatch) Add(
func (b *writeBatch) AddTagged(
originalIndex int,
id ident.ID,
tagIter ident.TagIterator,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No need for TagIterator when batching writes.

@soundvibe soundvibe requested a review from robskillington May 7, 2021 18:44
Comment on lines 229 to 232
type TagMetadataResolver interface {
// Resolve resolves doc metadata.
Resolve(id ID) (doc.Metadata, error)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The one thing that could reduce allocations even further would be to make this a struct instead of an interface type (i.e. type TagMetadataResolver struct) and then just have special constructors for each type and based on which constructor was used set some type of boolean or enum on the struct so that when Resolve(id) (doc.Metadata, error) is called it knows what to do.

For an example see the following: NewMetadataFromIDAndTagIterator and NewMetadataFromIDAndTags and then see the ResetOrReturnProvidedTagIterator method.

That way it can be passed on the stack and doesn't need to be heap allocated (which is required with an interface).

Copy link
Collaborator

@robskillington robskillington left a comment

Choose a reason for hiding this comment

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

This LGTM other than the mention about switching to a struct vs interface so can pass the argument on the stack rather than needing to create a struct on the heap that fits the interface.

src/dbnode/network/server/tchannelthrift/node/service.go Outdated Show resolved Hide resolved
Comment on lines -78 to -82
// SetTagDecoderPool sets the tag encoder pool.
SetTagDecoderPool(value serialize.TagDecoderPool) Options

// TagDecoderPool returns the tag encoder pool.
TagDecoderPool() serialize.TagDecoderPool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great to see all this cleanup happening!

src/dbnode/storage/index/convert/convert.go Outdated Show resolved Hide resolved
src/dbnode/storage/shard.go Show resolved Hide resolved
src/dbnode/storage/tag_resolver.go Outdated Show resolved Hide resolved
soundvibe added 3 commits May 10, 2021 12:02
Moved TagMetadataResolver to convert namespace.
Other small changes after review.
* master:
  [query] Add Graphite movingWindow() function (#3484)
  [lint] Add missing build tags to linter configuration (#3480)
  [query] Fix Graphite nil arg not interpreted as explicit nil (#3481)
  [query] Fix Graphite context time window expansions not being cumulative
  [readme] Remove coverage badge due to CodeCov not able to execute (#3476)
  [query] Fix using median with aggregateWithWildcards and support more aggregate functions (#3469)
  [matcher] [coordinator] Add RequireNamespaceWatchOnInit option (#3468)
  [buildkite] Remove codecov uploading from unit tests (#3475)
  [aggregator] Add integration test for aggregator placement changes (#3465)
  [tools] Use streaming reads in read_data_files (#3474)
  [tools] Close the reader in read_data_files (#3473)
Copy link
Collaborator

@linasm linasm left a comment

Choose a reason for hiding this comment

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

LGTM

@soundvibe soundvibe merged commit 97ee4d5 into master May 10, 2021
@soundvibe soundvibe deleted the linasn/tag-metadata-resolver branch May 10, 2021 14:01
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.

3 participants