Skip to content

Commit

Permalink
Merge pull request #1622 from authzed/spanner-conn-pool-count
Browse files Browse the repository at this point in the history
derive Spanner default gRPC connection count from GOMAXPROCS
  • Loading branch information
josephschorr authored Oct 27, 2023
2 parents 6156904 + 95d4e35 commit 589153e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/datastore/spanner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package spanner

import (
"fmt"
"math"
"runtime"
"time"
)

Expand All @@ -27,8 +29,6 @@ const (
defaultWatchBufferLength = 128
defaultDisableStats = false
maxRevisionQuantization = 24 * time.Hour
defaultReadMaxOpen = 4
defaultWriteMaxOpen = 4
defaultSchemaWatchHeartbeat = 100 * time.Millisecond
)

Expand All @@ -37,14 +37,17 @@ const (
type Option func(*spannerOptions)

func generateConfig(options []Option) (spannerOptions, error) {
// originally SpiceDB didn't use connection pools for Spanner SDK, so it opened 1 single connection
// This determines if there are more CPU cores to increase the default number of connections
defaultNumberConnections := max(1, math.Round(float64(runtime.GOMAXPROCS(0))))
computed := spannerOptions{
watchBufferLength: defaultWatchBufferLength,
revisionQuantization: defaultRevisionQuantization,
followerReadDelay: defaultFollowerReadDelay,
maxRevisionStalenessPercent: defaultMaxRevisionStalenessPercent,
disableStats: defaultDisableStats,
readMaxOpen: defaultReadMaxOpen,
writeMaxOpen: defaultWriteMaxOpen,
readMaxOpen: int(defaultNumberConnections),
writeMaxOpen: int(defaultNumberConnections),
schemaWatchHeartbeat: defaultSchemaWatchHeartbeat,
}

Expand Down

0 comments on commit 589153e

Please sign in to comment.