Top Banner
Experiences Building InfluxDB in Go Paul Dix paul@influxdb.com @pauldix
49

Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Jun 03, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Experiences Building InfluxDB in Go

Paul Dix [email protected]

@pauldix

Page 2: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Who am I?informs my experience working with a language like Go

Page 3: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

co-founder, CEO, programmer

Page 4: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Author

Page 5: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Languages worked with Professionally in order• VBScript

• Delphi

• C# and VB.NET

• Ruby & Javascript

• Java

• C (only a little)

• Ruby & Javascript

• Scala

• Go

Page 6: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Mix of static and dynamic, but most time in dynamic languages

Page 7: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Open source time series database written in Go

Page 8: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

What’s a time series?

Page 9: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Stock trades and quotes

Page 10: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Metrics

Page 11: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Analytics

Page 12: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Events

Page 13: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Sensor data

Page 14: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Two kinds of time series data…

Page 15: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Regular time series

t0 t1 t2 t3 t4 t6 t7

Samples at regular intervals

Page 16: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Irregular time series

t0 t1 t2 t3 t4 t6 t7

Events whenever they come in

Page 17: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Why’d we pick Go?

Page 18: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Some project requirements• Self contained binary install

Page 19: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Some project requirements• Self contained binary install

• Performance

Page 20: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

previous experience with it

Page 21: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

faster development than working with C/C++

Page 22: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

growing community

Page 23: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

simplicity of the languagesignificant advantage for picking up new programmers and contributors

Page 24: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

InfluxDB Project Stats

• First Commit - September 26th, 2013

• 176 Contributors

• 68,000 LOC

Page 25: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Team background• Java

• Scala

• Python

• Ruby

• C++

Page 26: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

What has been great

Page 27: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Static typingcan’t believe I’m saying this

Page 28: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Community

Page 29: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Performance

Page 30: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

What surprised us

Page 31: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

GC hasn’t been a problem

Page 32: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Contributors with no previous Go experiencesimplicity of the language wins again

Page 33: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Haven’t really missed generics

Page 34: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

except when I do…

Page 35: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

// Sort methodsfunc (a Values) Len() int { return len(a) }func (a Values) Swap(i, j int) { a[i], a[j] = a[j], a[i] }func (a Values) Less(i, j int) bool { return a[i].Time().UnixNano() < a[j].Time().UnixNano()}

Page 36: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Duplicate code for each data type

select percentile(90, value) from cpu where time > now() - 1d group by time(10m)

Page 37: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

// Iterator represents an iterator over a series.type Iterator interface { SeekTo(seek int64) (key int64, value interface{}) Next() (key int64, value interface{}) Ascending() bool

} we have to cast this later

Page 38: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Costs on performance

f := val.(float64)// do some math

Page 39: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

// FloatIterator represents an iterator over a series.type FloatIterator interface {SeekTo(seek int64) (key int64, value float64)Next() (key int64, value float64)Ascending() bool

}

Page 40: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Implement for every functionfunc MapMean(input *MapInput) interface{} {if len(input.Items) == 0 {return nil

}

out := &meanMapOutput{}for _, item := range input.Items {out.Count++switch v := item.Value.(type) {case float64:out.Total += v

case int64:out.Total += float64(v)out.ResultType = Int64Type

}}return out

}

Page 41: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Could use interfaces, but there’s a performance penalty there too…

Page 42: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

What has been bad

Page 43: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Dependency management

Page 44: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Experiences migrating to 1.5

Page 45: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Compile times longeron a project this size it’s noticeable

Page 46: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Performance more about our code

Page 47: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Go 1.5 issue forced us to reverthttps://github.com/golang/go/issues/12233

Page 48: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Unit and integration tests won’t save you.

if you operate at scale, only full blown scale tests will tell you anything and even then you may not find it

Page 49: Experiences building InfluxDB in Go - QCon San Francisco · InfluxDB Project Stats • First Commit - September 26th, 2013 • 176 Contributors • 68,000 LOC

Q&[email protected]

@pauldix