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

Concurrency blocking issue #171

Merged
merged 3 commits into from
Jul 9, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Unreleased

- Primary key generation no longer blocks if the targeted source is full.
- Upgraded driver to 1.2.0

# v1.4.1
Expand Down
21 changes: 12 additions & 9 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Source struct {
oldValues chan Value
valueCounter *prometheus.CounterVec
bucket string
meter prometheus.Gauge
}

func (s *Source) Get() (Value, bool) {
Expand Down Expand Up @@ -42,6 +43,7 @@ func (s *Source) Get() (Value, bool) {
// then we just drop the value.
}

s.meter.Dec()
s.valueCounter.WithLabelValues("new", s.bucket).Inc()

return values, true
Expand All @@ -54,7 +56,6 @@ func (s *Source) GetOld() (Value, bool) {
}

func (s *Source) stop() {
fmt.Println("Closing source")
close(s.newValues)
}

Expand All @@ -65,7 +66,6 @@ type Generators struct {
partitionsConfig PartitionRangeConfig
seed uint64
done chan struct{}
counter prometheus.Counter
}

type GeneratorsConfig struct {
Expand All @@ -78,10 +78,6 @@ type GeneratorsConfig struct {
}

func NewGenerator(config *GeneratorsConfig) *Generators {
valueGenerationCounter := promauto.NewCounter(prometheus.CounterOpts{
Name: "gemini_partition_key_value_creation",
Help: "How many partition keys are created",
})
valueCounter := promauto.NewCounterVec(prometheus.CounterOpts{
Name: "gemini_partition_key_value_consumption",
Help: "How many partition keys are consumed, both new ald reused 'old'",
Expand All @@ -94,6 +90,10 @@ func NewGenerator(config *GeneratorsConfig) *Generators {
oldValues: make(chan Value, config.PkUsedBufferSize),
bucket: fmt.Sprintf("bucket_%d", i),
valueCounter: valueCounter,
meter: promauto.NewGauge(prometheus.GaugeOpts{
Name: fmt.Sprintf("gemini_partition_key_source_meter_bucket_%d", i),
Help: "How many values the source has in it's buffer",
}),
}
}
gs := &Generators{
Expand All @@ -103,7 +103,6 @@ func NewGenerator(config *GeneratorsConfig) *Generators {
partitionsConfig: config.Partitions,
seed: config.Seed,
done: make(chan struct{}, 1),
counter: valueGenerationCounter,
}
gs.start()
return gs
Expand Down Expand Up @@ -136,8 +135,12 @@ func (gs *Generators) start() {
b, _ := routingKeyCreator.CreateRoutingKey(gs.table, values)
hash := uint64(murmur.Murmur3H1(b))
source := gs.generators[hash%gs.size]
source.newValues <- Value(values)
gs.counter.Inc()
select {
case source.newValues <- Value(values):
source.meter.Inc()
default:
// Ignore, the source is full
}
}
}
}()
Expand Down