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

Reduce memory allocations in index #7138

Merged
merged 1 commit into from
Aug 17, 2016

Conversation

benbjohnson
Copy link
Contributor

@benbjohnson benbjohnson commented Aug 10, 2016

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

  • Dereference mmap on close
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated

@@ -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()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f6a1b2a.

@benbjohnson benbjohnson force-pushed the optimize-shard-open branch 5 times, most recently from 3acdf01 to f6a1b2a Compare August 15, 2016 14:32
@@ -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)
Copy link
Contributor

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.

Copy link
Contributor Author

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?

@jwilder
Copy link
Contributor

jwilder commented Aug 16, 2016

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.

@jwilder jwilder added this to the 1.1.0 milestone Aug 16, 2016
This commit changes the index to point to index data in the shards
instead of keeping it in-memory on the heap.
@jwilder
Copy link
Contributor

jwilder commented Aug 17, 2016

👍

@benbjohnson benbjohnson merged commit 6553667 into influxdata:master Aug 17, 2016
@jwilder
Copy link
Contributor

jwilder commented Aug 17, 2016

cc @daviesalex @sebito91 This will be in tonights nightly.

@benbjohnson benbjohnson deleted the optimize-shard-open branch April 10, 2017 15:17
SuperQ added a commit to prometheus/influxdb_exporter that referenced this pull request Jul 27, 2017
Updates to interface with influxdb model.

See: influxdata/influxdb#7138
brian-brazil pushed a commit to prometheus/influxdb_exporter that referenced this pull request Jul 27, 2017
Updates to interface with influxdb model.

See: influxdata/influxdb#7138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants