Skip to content

Remove chunk store parallelisation; add backoff #119

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

Merged
merged 3 commits into from
Nov 7, 2016
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
26 changes: 4 additions & 22 deletions chunk/chunk_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const (

// See http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html.
dynamoMaxBatchSize = 25
maxConcurrentPuts = 100
)

var (
Expand Down Expand Up @@ -129,7 +128,6 @@ func NewAWSStore(cfg StoreConfig) (*AWSStore, error) {
chunkCache: cfg.ChunkCache,
tableName: tableName,
bucketName: bucketName,
putLimiter: NewSemaphore(maxConcurrentPuts),
}, nil
}

Expand All @@ -155,7 +153,6 @@ type AWSStore struct {
chunkCache *Cache
tableName string
bucketName string
putLimiter Semaphore
}

type dynamodbClient interface {
Expand Down Expand Up @@ -268,10 +265,8 @@ func (c *AWSStore) Put(ctx context.Context, chunks []Chunk) error {
func (c *AWSStore) putChunks(userID string, chunks []Chunk) error {
incomingErrors := make(chan error)
for _, chunk := range chunks {
c.putLimiter.Acquire()
go func(chunk Chunk) {
incomingErrors <- c.putChunk(userID, &chunk)
c.putLimiter.Release()
}(chunk)
}

Expand Down Expand Up @@ -314,25 +309,12 @@ func (c *AWSStore) updateIndex(userID string, chunks []Chunk) error {
return err
}

batches := c.batchRequests(writeReqs)

// Request all the batches in parallel.
incomingErrors := make(chan error)
for _, batch := range batches {
c.putLimiter.Acquire()
go func(batch []*dynamodb.WriteRequest) {
incomingErrors <- c.batchWriteDynamo(batch)
c.putLimiter.Release()
}(batch)
}
var lastErr error
for range batches {
err = <-incomingErrors
if err != nil {
lastErr = err
for _, batch := range c.batchRequests(writeReqs) {
if err := c.batchWriteDynamo(batch); err != nil {
return err
}
}
return lastErr
return nil
}

// calculateDynamoWrites creates a set of batched WriteRequests to dynamo for all
Expand Down
1 change: 0 additions & 1 deletion chunk/chunk_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestChunkStore(t *testing.T) {
chunkCache: nil,
tableName: "tablename",
bucketName: "bucketname",
putLimiter: NoopSemaphore,
}
store.CreateTables()

Expand Down
22 changes: 21 additions & 1 deletion ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"
"time"

"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
Expand All @@ -25,6 +26,12 @@ const (
// Reasons to discard samples.
outOfOrderTimestamp = "timestamp_out_of_order"
duplicateSample = "multiple_values_for_timestamp"

// Backoff for flush
minBackoff = 100 * time.Millisecond
maxBackoff = 1 * time.Second

provisionedThroughputExceededException = "ProvisionedThroughputExceededException"
)

var (
Expand Down Expand Up @@ -525,6 +532,8 @@ func (i *Ingester) flushSeries(u *userState, fp model.Fingerprint, series *memor
}

func (i *Ingester) flushLoop(j int) {
backoff := minBackoff

defer func() {
log.Info("Ingester.flushLoop() exited")
i.done.Done()
Expand Down Expand Up @@ -570,12 +579,23 @@ func (i *Ingester) flushLoop(j int) {
}

// flush the chunks without locking the series
if err := i.flushChunks(ctx, op.fp, series.metric, chunks); err != nil {
err := i.flushChunks(ctx, op.fp, series.metric, chunks)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == provisionedThroughputExceededException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instrumenting here would help fix https://github.com/weaveworks/monitoring/issues/12.

(No change required, immediately. One of us will get to it soon enough.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Instrumentation would be good for this. Will do it now.

time.Sleep(backoff)
backoff = backoff * 2
if backoff > maxBackoff {
backoff = maxBackoff
}
}

log.Errorf("Failed to flush chunks: %v", err)
i.chunkStoreFailures.Add(float64(len(chunks)))
continue
}

backoff = minBackoff

// now remove the chunks
userState.fpLocker.Lock(op.fp)
series.chunkDescs = series.chunkDescs[len(chunks):]
Expand Down