Skip to content

Commit

Permalink
Add option to configure cache size
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiss committed Mar 6, 2024
1 parent ae1f8a3 commit 32a6d65
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion testserver/testserver.go
Expand Up @@ -78,6 +78,8 @@ const (
// By default, we allocate 20% of available memory to the test server.
const defaultStoreMemSize = 0.2

const defaultCacheSize = 0.1

const defaultInitTimeout = 60
const defaultPollListenURLTimeout = 60
const defaultListenAddrHost = "localhost"
Expand Down Expand Up @@ -224,7 +226,8 @@ type testServerArgs struct {
secure bool
rootPW string // if nonempty, set as pw for root
storeOnDisk bool // to save database in disk
storeMemSize float64 // the proportion of available memory allocated to test server
storeMemSize float64 // the proportion of available memory allocated to test server in-memory store
cacheSize float64 // the proportion of available memory allocated to cache
httpPorts []int
listenAddrPorts []int
listenAddrHost string
Expand Down Expand Up @@ -287,6 +290,18 @@ func SetStoreMemSizeOpt(memSize float64) TestServerOpt {
}
}

// CacheSizeOpt sets the proportion of available memory that is allocated
// to the CockroachDB cache.
func CacheSizeOpt(cacheSize float64) TestServerOpt {
return func(args *testServerArgs) {
if cacheSize > 0 {
args.cacheSize = cacheSize
} else {
args.cacheSize = defaultCacheSize
}
}
}

// RootPasswordOpt is a TestServer option that, when passed to NewTestServer,
// sets the given password for the root user (and returns a URL using it from
// PGURL(). This avoids having to use client certs.
Expand Down Expand Up @@ -436,6 +451,7 @@ func NewTestServer(opts ...TestServerOpt) (TestServer, error) {

serverArgs := &testServerArgs{numNodes: 1}
serverArgs.storeMemSize = defaultStoreMemSize
serverArgs.cacheSize = defaultCacheSize
serverArgs.initTimeoutSeconds = defaultInitTimeout
serverArgs.pollListenURLTimeoutSeconds = defaultPollListenURLTimeout
serverArgs.listenAddrHost = defaultListenAddrHost
Expand Down Expand Up @@ -604,6 +620,7 @@ func NewTestServer(opts ...TestServerOpt) (TestServer, error) {
"--port=" + strconv.Itoa(serverArgs.listenAddrPorts[0]),
"--http-port=" + strconv.Itoa(serverArgs.httpPorts[0]),
storeArg,
"--cache=" + strconv.FormatFloat(serverArgs.cacheSize, 'f', 4, 64),
"--listening-url-file=" + nodes[i].listeningURLFile,
"--external-io-dir=" + serverArgs.externalIODir,
}
Expand Down

0 comments on commit 32a6d65

Please sign in to comment.