Skip to content

Commit 7434a62

Browse files
committed
Make DBs run on ramdisk and optimize rspec parallelism
Since in a dev scenario we dont care about data loss we can speed up the tests majorly by running the DBs on a ramdisk. Also since the DB consumes CPU during the test its not good to start rspec executes equal to the number of CPU cores since the sume of load excedes that by a lot. So we leave 20% spare for the DB to have less CPU preemtive scheduling and all in all finish the rspecs faster. An environment variable was introduced PARALLEL_TEST_PROCESSORS_MULTIPLE that can be set to any floating point value and multiplies the CPU core count times PARALLEL_TEST_PROCESSORS_MULTIPLE. It defaults to 0.8.
1 parent 40ddd8d commit 7434a62

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"nginx"
2121
],
2222
"workspaceFolder": "/workspace",
23-
"onCreateCommand": "bash .devcontainer/scripts/codespaces_start.sh",
23+
"onCreateCommand": "bash .devcontainer/scripts/startup.sh",
2424
"customizations": {
2525
// Configure properties specific to VS Code.
2626
"vscode": {
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ POSTGRES_PID=$!
5454
setupMariadb &
5555
MARIADB_PID=$!
5656

57-
wait $POSTGRES_PID
58-
wait $MARIADB_PID
59-
6057
# CC config
6158
mkdir -p tmp
6259
cp -a config/cloud_controller.yml tmp/cloud_controller.yml
@@ -120,4 +117,5 @@ yq -i e '.diego.bbs.ca_file="spec/fixtures/certs/bbs_ca.crt"' tmp/cloud_controll
120117

121118
yq -i e '.packages.max_package_size=2147483648' tmp/cloud_controller.yml
122119

123-
# Exit if any error happened
120+
wait $POSTGRES_PID
121+
wait $MARIADB_PID

devenv.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ help_command() {
1818

1919
# Create a clean development environment
2020
create_command(){
21-
docker-compose -p "" down
21+
docker compose -p "" down
2222
docker buildx bake -f docker-compose.yml &
23-
docker-compose -p "" pull &
23+
docker compose -p "" pull &
2424
wait $(jobs -p)
25-
docker-compose -p "" up -d --build
26-
./.devcontainer/scripts/setupDevelopmentEnvironment.sh
25+
docker compose -p "" up -d --build
26+
./.devcontainer/scripts/startup.sh
2727
}
2828

2929
# Start containers
3030
start_command(){
31-
docker-compose -p "" start
31+
docker compose -p "" start
3232
}
3333

3434
# Stop containers
3535
stop_command(){
36-
docker-compose -p "" stop
36+
docker compose -p "" stop
3737
}
3838

3939
# Remove containers
4040
destroy_command(){
41-
docker-compose -p "" down
41+
docker compose -p "" down
4242
}
4343

4444
# Call Setup IDEs Script
@@ -72,7 +72,7 @@ fi
7272
# Check Prerequisites
7373
export should_exit=0
7474
# Check Path Exists
75-
for p in docker docker-compose ruby bundle mysql psql yq; do
75+
for p in docker ruby bundle mysql psql yq; do
7676
if ! command -v "${p}" >/dev/null 2>&1; then
7777
echo "Error: Dependency \"$p\" is not installed" && export should_exit=1
7878
fi

docker-compose.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ services:
77
environment:
88
POSTGRES_PASSWORD: supersecret
99
command:
10-
# logs every statement sent to the server. Slow, but helpful. Fills up disk Quickly !
1110
- "postgres"
12-
# - "-c"
13-
# - "log_statement=all"
11+
- "-c"
12+
- "fsync=off"
13+
- "-c"
14+
- "synchronous_commit=off"
15+
- "-c"
16+
- "full_page_writes=off"
17+
- "-c"
18+
- "log_statement=all"
19+
tmpfs:
20+
- /var/lib/postgresql/data
1421
ports:
1522
- "127.0.0.1:5432:5432"
1623
networks:
@@ -28,6 +35,12 @@ services:
2835
image: mysql:8.2
2936
environment:
3037
MYSQL_ROOT_PASSWORD: supersecret
38+
command:
39+
- "--innodb-flush-method=nosync"
40+
- "--innodb-flush-log-at-trx-commit=0"
41+
- "--innodb-doublewrite=0"
42+
tmpfs:
43+
- /var/lib/mysql
3144
ports:
3245
- "127.0.0.1:3306:3306"
3346
healthcheck:

lib/tasks/spec.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace :spec do
4444
def run_specs_parallel(path, env_vars='')
4545
command = <<~CMD
4646
#{env_vars} bundle exec parallel_rspec \
47+
-n `ruby -e 'require "etc"; puts (Etc.nprocessors * (ENV["PARALLEL_TEST_PROCESSORS_MULTIPLE"] || 0.8).to_f).to_i'` \
4748
--test-options '--order rand' \
4849
--single spec/integration/ \
4950
--single spec/acceptance/ \

0 commit comments

Comments
 (0)