Skip to content

Commit cbda309

Browse files
committed
Speed up test DBs and reduce memory footprint
1 parent c2df331 commit cbda309

2 files changed

Lines changed: 47 additions & 12 deletions

File tree

common/persistence/cassandra/test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ func (s *TestCluster) LoadSchema(schemaFile string) {
175175
}
176176
for _, stmt := range statements {
177177
if err = s.session.Query(stmt).Exec(); err != nil {
178+
// CreateDatabase recreates the keyspace via DROP+CREATE. Cassandra's
179+
// schema metadata can briefly lag the DROP, so the next CREATE TYPE /
180+
// TABLE / INDEX may fail with "already exists" against stale state.
181+
// Treat that as success: a fresh keyspace can't have any object that
182+
// matters here besides what we're trying to create.
183+
if strings.Contains(err.Error(), "already exists") {
184+
s.logger.Warn("LoadSchema: object already exists, skipping",
185+
tag.NewStringTag("statement", stmt), tag.Error(err))
186+
continue
187+
}
178188
s.logger.Fatal("LoadSchema", tag.Error(err))
179189
}
180190
}

develop/github/docker-compose.yml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
x-healthcheck-defaults: &healthcheck-defaults
2-
interval: 3s
2+
interval: 30s # steady-state polling once healthy; avoids ongoing probe overhead
33
timeout: 3s
4-
retries: 60
4+
retries: 3 # ~90s of failures at steady-state before marking unhealthy (startup is covered by start_period)
5+
start_period: 60s # probe failures within this window don't count against retries
6+
start_interval: 1s # probe every 1s during start_period; trims startup wait (Docker 25+)
57

68
services:
79
cassandra:
@@ -10,10 +12,20 @@ services:
1012
- "9042:9042"
1113
environment:
1214
CASSANDRA_LISTEN_ADDRESS: 127.0.0.1
13-
MAX_HEAP_SIZE: "2G"
14-
HEAP_NEWSIZE: "200M"
15-
# Increase native transport threads for handling more concurrent connections
16-
JVM_EXTRA_OPTS: "-Dcassandra.native_transport_max_threads=512"
15+
MAX_HEAP_SIZE: "1G" # default 2G; right-sized for single-node tests
16+
HEAP_NEWSIZE: "100M" # 10% of MAX_HEAP_SIZE per Cassandra docs
17+
# native_transport_max_threads=512: default 128; xdc tests open many CQL conns.
18+
# ring_delay_ms=1000: default 30000; no ring on single node, saves ~30s startup.
19+
# skip_wait_for_gossip_to_settle=0: skips additional gossip wait, redundant on single node.
20+
# initial_token=0 / num_tokens=1: skip vnode token allocation work.
21+
# consistent.rangemovement=false: skip safety check for pending range moves (none on single node).
22+
JVM_EXTRA_OPTS: >-
23+
-Dcassandra.native_transport_max_threads=512
24+
-Dcassandra.ring_delay_ms=1000
25+
-Dcassandra.skip_wait_for_gossip_to_settle=0
26+
-Dcassandra.initial_token=0
27+
-Dcassandra.num_tokens=1
28+
-Dcassandra.consistent.rangemovement=false
1729
healthcheck:
1830
!!merge <<: *healthcheck-defaults
1931
test: ["CMD-SHELL", "cqlsh -e 'describe cluster'"]
@@ -24,7 +36,11 @@ services:
2436
- "3306:3306"
2537
environment:
2638
MYSQL_ROOT_PASSWORD: root
27-
command: --max-connections=500
39+
command:
40+
- --max-connections=500
41+
- --innodb-flush-log-at-trx-commit=0 # fsync redo log every 1s, not per commit
42+
- --innodb-doublewrite=0 # torn-page protection irrelevant for tests
43+
- --skip-log-bin # no replication / PITR for tests
2844
volumes:
2945
- ./mysql-init:/docker-entrypoint-initdb.d
3046
healthcheck:
@@ -38,7 +54,16 @@ services:
3854
environment:
3955
POSTGRES_USER: temporal
4056
POSTGRES_PASSWORD: temporal
41-
command: postgres -c max_connections=500
57+
command:
58+
- postgres
59+
- -c
60+
- max_connections=500
61+
- -c
62+
- fsync=off # test DB is ephemeral; skip per-commit fsync
63+
- -c
64+
- synchronous_commit=off # don't block on WAL flush
65+
- -c
66+
- full_page_writes=off # torn-page protection irrelevant for tests
4267
volumes:
4368
- ./postgresql-init:/docker-entrypoint-initdb.d
4469
healthcheck:
@@ -55,7 +80,7 @@ services:
5580
- cluster.routing.allocation.disk.watermark.high=256mb
5681
- cluster.routing.allocation.disk.watermark.flood_stage=128mb
5782
- discovery.type=single-node
58-
- ES_JAVA_OPTS=-Xms1g -Xmx1g
83+
- ES_JAVA_OPTS=-Xms512m -Xmx512m # default 1G; tests use little index data
5984
healthcheck:
6085
!!merge <<: *healthcheck-defaults
6186
test: ["CMD-SHELL", "curl -sf http://localhost:9200/_cluster/health || exit 1"]
@@ -71,7 +96,7 @@ services:
7196
- cluster.routing.allocation.disk.watermark.flood_stage=128mb
7297
- discovery.type=single-node
7398
- xpack.security.enabled=false
74-
- ES_JAVA_OPTS=-Xms1g -Xmx1g
99+
- ES_JAVA_OPTS=-Xms512m -Xmx512m # default 1G; tests use little index data
75100
healthcheck:
76101
!!merge <<: *healthcheck-defaults
77102
test: ["CMD-SHELL", "curl -sf http://localhost:9200/_cluster/health || exit 1"]
@@ -87,7 +112,7 @@ services:
87112
- cluster.routing.allocation.disk.watermark.flood_stage=128mb
88113
- discovery.type=single-node
89114
- DISABLE_SECURITY_PLUGIN=true
90-
- OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
115+
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m # default 1G; tests use little index data
91116
healthcheck:
92117
!!merge <<: *healthcheck-defaults
93118
test: ["CMD-SHELL", "curl -sf http://localhost:9200/_cluster/health || exit 1"]
@@ -103,7 +128,7 @@ services:
103128
- cluster.routing.allocation.disk.watermark.flood_stage=128mb
104129
- discovery.type=single-node
105130
- DISABLE_SECURITY_PLUGIN=true
106-
- OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
131+
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m # default 1G; tests use little index data
107132
healthcheck:
108133
!!merge <<: *healthcheck-defaults
109134
test: ["CMD-SHELL", "curl -sf http://localhost:9200/_cluster/health || exit 1"]

0 commit comments

Comments
 (0)