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

Add option to configure cache size #177

Merged
merged 1 commit into from Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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