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

Batch writes for monitor service (1.3 backport) #8720

Merged
merged 3 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- [#8706](https://github.com/influxdata/influxdb/pull/8706): Cursor leak, resulting in an accumulation of `.tsm.tmp` files after compactions.
- [#8713](https://github.com/influxdata/influxdb/issues/8713): Deadlock when dropping measurement and writing

### Features

- [#8711](https://github.com/influxdata/influxdb/pull/8711): Batch up writes for monitor service

## v1.3.3 [2017-08-10]

### Bugfixes
Expand Down
32 changes: 22 additions & 10 deletions monitor/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ func (m *Monitor) Open() error {
return nil
}

func (m *Monitor) writePoints(p models.Points) error {
m.mu.RLock()
defer m.mu.RUnlock()

if err := m.PointsWriter.WritePoints(m.storeDatabase, m.storeRetentionPolicy, p); err != nil {
m.Logger.Info(fmt.Sprintf("failed to store statistics: %s", err))
}
return nil
}

// Close closes the monitor system.
func (m *Monitor) Close() error {
if !m.open() {
Expand Down Expand Up @@ -414,24 +424,26 @@ func (m *Monitor) storeStatistics() {
return
}

points := make(models.Points, 0, len(stats))
// Write all stats in batches
batch := make(models.Points, 0, 5000)
for _, s := range stats {
pt, err := models.NewPoint(s.Name, models.NewTags(s.Tags), s.Values, now)
if err != nil {
m.Logger.Info(fmt.Sprintf("Dropping point %v: %v", s.Name, err))
return
}
points = append(points, pt)
}

func() {
m.mu.RLock()
defer m.mu.RUnlock()
batch = append(batch, pt)
if len(batch) == cap(batch) {
m.writePoints(batch)
batch = batch[:0]

if err := m.PointsWriter.WritePoints(m.storeDatabase, m.storeRetentionPolicy, points); err != nil {
m.Logger.Info(fmt.Sprintf("failed to store statistics: %s", err))
}
}()
}

// Write the last batch
if len(batch) > 0 {
m.writePoints(batch)
}
case <-m.done:
m.Logger.Info(fmt.Sprintf("terminating storage of statistics"))
return
Expand Down