-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Reduce memory allocations in index #7138
Reduce memory allocations in index #7138
Conversation
@@ -515,6 +523,16 @@ func (d *DatabaseIndex) DropSeries(keys []string) { | |||
atomic.AddInt64(&d.stats.NumSeries, -nDeleted) | |||
} | |||
|
|||
// Dereference removes all references to data within b and moves them to the heap. | |||
func (d *DatabaseIndex) Dereference(b []byte) { | |||
d.mu.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably needs to be an RLock
so that a slow delete doesn't lock up the whole database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dereference
changes the underlying series so I think we need to write lock. I'm not sure how to get around it unless we get a list of series ids and then iterate over it in chunks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is taking a lock on the index though, not the series. A write lock on the series makes sense though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in f6a1b2a.
3acdf01
to
f6a1b2a
Compare
@@ -1118,6 +1130,11 @@ func (p *purger) purge() { | |||
p.mu.Lock() | |||
for k, v := range p.files { | |||
if !v.InUse() { | |||
// Remove any mmap references held by the index. | |||
if p.fileStore.dereferencer != nil { | |||
v.deref(p.fileStore.dereferencer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to be called within FileStore.Replace
and FileStore.Remove
. The Purger
just handles removing files that are still in use by a query after a compaction has run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it to FileStore.Replace
in 6614e0b but FileStore.Remove
doesn't seem to actually close the file so it doesn't seem like the right place for dereference. Is it the purger that actually closes those files?
f6a1b2a
to
6614e0b
Compare
Tested this quite a bit yesterday and memory usage after restarts drops about ~30-40%. Objects in the heap was also reduced ~5-6x. Startup times are also reduced quite a bit. There is not much of a change if there is no restart. If we can figure out a solution for @joelegasse concerns then this should be good to merge. |
This commit changes the index to point to index data in the shards instead of keeping it in-memory on the heap.
6614e0b
to
8aa224b
Compare
👍 |
cc @daviesalex @sebito91 This will be in tonights nightly. |
Updates to interface with influxdb model. See: influxdata/influxdb#7138
Updates to interface with influxdb model. See: influxdata/influxdb#7138
Overview
This commit changes the index to point to index data in the shards instead of keeping it in-memory on the heap.
NOTE: This pull request is still missing dereferencing from the mmap when a shard is closed.
/cc @pauldix @jwilder
TODO