Skip to content

Commit 494781c

Browse files
authored
Scripts for running locally in docker and adjust SqlServer to match others (#266)
- Adds some scripts to ease running tests locally in docker containers. - Adjusts SqlServer patterns to match other DBs.
1 parent 5e1b094 commit 494781c

File tree

15 files changed

+130
-18
lines changed

15 files changed

+130
-18
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@
3232
"no_proxy": "${localEnv:no_proxy}",
3333
"MAVEN_CONFIG": "${localEnv:HOME}/.m2",
3434
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
35-
"CONTAINER_WORKSPACE_FOLDER": "${containerWorkspaceFolder}",
35+
"CONTAINER_WORKSPACE_FOLDER": "${containerWorkspaceFolder}"
3636
},
3737
// Set *default* container specific settings.json values on container create.
3838
"customizations": {
3939
"vscode": {
4040
"settings": {},
4141
// Add the IDs of extensions you want installed when the container is created.
4242
"extensions": [
43+
"GitHub.copilot",
44+
"eamodio.gitlens",
4345
"vscjava.vscode-java-pack",
4446
"EditorConfig.EditorConfig"
4547
]

.github/workflows/maven.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ jobs:
316316
benchmark: [ 'tpcc', 'tpch' ]
317317
services:
318318
sqlserver:
319-
image: mcr.microsoft.com/mssql/server:2019-latest
319+
image: mcr.microsoft.com/mssql/server:latest
320320
env:
321321
ACCEPT_EULA: Y
322322
SA_PASSWORD: SApassword1
@@ -347,11 +347,17 @@ jobs:
347347
java-version: ${{env.JAVA_VERSION}}
348348
distribution: 'temurin'
349349

350+
- name: Cleanup database
351+
uses: docker://mcr.microsoft.com/mssql-tools:latest
352+
with:
353+
entrypoint: /opt/mssql-tools/bin/sqlcmd
354+
args: -U sa -P SApassword1 -S sqlserver -b -Q "DROP DATABASE IF EXISTS benchbase;"
355+
350356
- name: Setup database
351357
uses: docker://mcr.microsoft.com/mssql-tools:latest
352358
with:
353359
entrypoint: /opt/mssql-tools/bin/sqlcmd
354-
args: -U sa -P SApassword1 -S sqlserver -b -Q "CREATE DATABASE benchbase_${{ matrix.benchmark }};"
360+
args: -U sa -P SApassword1 -S sqlserver -b -Q "CREATE DATABASE benchbase;"
355361

356362
- name: Setup login
357363
uses: docker://mcr.microsoft.com/mssql-tools:latest
@@ -363,7 +369,7 @@ jobs:
363369
uses: docker://mcr.microsoft.com/mssql-tools:latest
364370
with:
365371
entrypoint: /opt/mssql-tools/bin/sqlcmd
366-
args: -U sa -P SApassword1 -S sqlserver -b -Q "USE benchbase_${{ matrix.benchmark }}; CREATE USER benchuser01 FROM LOGIN benchuser01; EXEC sp_addrolemember 'db_owner', 'benchuser01';"
372+
args: -U sa -P SApassword1 -S sqlserver -b -Q "USE benchbase; CREATE USER benchuser01 FROM LOGIN benchuser01; EXEC sp_addrolemember 'db_owner', 'benchuser01';"
367373

368374
- name: Run benchmark
369375
# Note: user/pass should match those used in sample configs.

config/sqlserver/sample_tpcc_config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- Connection details -->
55
<type>sqlserver</type>
66
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
7-
<url>jdbc:sqlserver://localhost:1433;encrypt=false;database=benchbase_tpcc;</url>
7+
<url>jdbc:sqlserver://localhost:1433;encrypt=false;database=benchbase;</url>
88
<username>benchuser01</username>
99
<password>P@ssw0rd</password>
1010
<isolation>TRANSACTION_SERIALIZABLE</isolation>

config/sqlserver/sample_tpch_config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- Connection details -->
55
<type>sqlserver</type>
66
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
7-
<url>jdbc:sqlserver://localhost:1433;encrypt=false;database=benchbase_tpch;</url>
7+
<url>jdbc:sqlserver://localhost:1433;encrypt=false;database=benchbase;</url>
88
<username>benchuser01</username>
99
<password>P@ssw0rd</password>
1010
<isolation>TRANSACTION_SERIALIZABLE</isolation>

docker/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Docker Use
2+
3+
Scripts in this directory can be used to quickly run a benchmark against a sample database.
4+
5+
For instance:
6+
7+
```bash
8+
# Set which database to target.
9+
export BENCHBASE_PROFILE='sqlserver'
10+
# Set which profiles to build.
11+
export BENCHBASE_PROFILES=$BENCHBASE_PROFILE
12+
# Whether or not to rebuild the package/image.
13+
export CLEAN_BUILD="false"
14+
# When rebuilding, whether or not to run the unit tests.
15+
export SKIP_TESTS="true"
16+
17+
# Set which benchmark to run.
18+
benchmark='tpcc'
19+
20+
./docker/build-run-benchmark-with-docker.sh $benchmark
21+
```
22+
23+
This will use the selected profile's `up.sh` script to start the database as a local container, and the [`run-full-image.sh`](./benchbase/run-full-image.sh) to optionally build benchbase and then run the benchmark against it.

docker/benchbase/build-full-image.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,24 @@ function create_image() {
5757
# Make (hard-linked) copies of the build results that we can put into the image.
5858
pushd "$scriptdir/fullimage/"
5959
rm -rf tmp/
60-
mkdir -p tmp/docker-build-stage/
60+
mkdir -p tmp/config/
61+
mkdir -p tmp/profiles/
62+
cp -a "$rootdir/config/plugin.xml" tmp/config/
6163
for profile in $profiles; do
6264
if ! [ -f "$rootdir/profiles/$profile/benchbase.jar" ]; then
6365
echo "ERROR: build for $profile appears to have failed." >&2
6466
exit 1
6567
fi
66-
cp -al "$rootdir/profiles/$profile" tmp/docker-build-stage/
68+
cp -al "$rootdir/profiles/$profile" tmp/profiles/
69+
70+
# Consolidate the configs across profiles.
71+
cp -a "$rootdir/profiles/$profile/config/$profile" tmp/config/
72+
rm -rf tmp/profiles/$profile/config
73+
ln -s ../../config/$profile "tmp/profiles/$profile/config"
74+
ln -s . tmp/profiles/$profile/config/$profile
75+
ln -s ../plugin.xml tmp/config/$profile/
6776
done
77+
6878
# Make a copy of the entrypoint script that changes the default profile to
6979
# execute for singleton images.
7080
cp -a entrypoint.sh tmp/entrypoint.sh

docker/benchbase/devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LABEL org.opencontainers.image.source = "https://github.com/cmu-db/benchbase/"
88
# Also add a few nice cli tools.
99
RUN apt-get update \
1010
&& apt-get -y upgrade \
11-
&& apt-get -y install --no-install-recommends sudo vim-nox neovim less bash-completion colordiff git \
11+
&& apt-get -y install --no-install-recommends sudo vim-nox neovim less bash-completion colordiff git jq \
1212
&& apt-get clean && rm -rf /var/lib/apt/lists/*
1313

1414
# Add a containeruser that allows vscode/codespaces to map the local host user

docker/benchbase/fullimage/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ VOLUME /benchbase/results
2222
# Only copy the content necessary for running (not building) benchbase over to the image.
2323
# These files should have been built using the devcontainer by the
2424
# build-full-image.sh script.
25-
COPY ./entrypoint.sh /entrypoint.sh
26-
COPY ./docker-build-stage/ /benchbase/profiles/
25+
COPY . /benchbase/
2726

28-
ENTRYPOINT ["/entrypoint.sh"]
27+
ENTRYPOINT ["/benchbase/entrypoint.sh"]
2928
CMD ["--help"]

docker/benchbase/run-full-image.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,31 @@ rootdir=$(readlink -f "$scriptdir/../../")
1010

1111
cd "$scriptdir"
1212
. ./common-env.sh
13-
./build-full-image.sh
13+
if ! docker image ls --quiet benchbase-$BENCHBASE_PROFILE:latest | grep -q .; then
14+
# Missing image, need to build it.
15+
CLEAN_BUILD=true
16+
fi
17+
18+
if [ "$CLEAN_BUILD" != 'false' ]; then
19+
./build-full-image.sh
20+
fi
1421

1522
if [ "$imagename" != 'benchbase' ]; then
1623
echo "ERROR: Unexpected imagename: $imagename" >&2
1724
fi
1825

26+
SRC_DIR="$PWD"
27+
if [ -n "$LOCAL_WORKSPACE_FOLDER" ]; then
28+
SRC_DIR="$LOCAL_WORKSPACE_FOLDER"
29+
fi
30+
1931
cd "$rootdir"
2032
mkdir -p results/
2133
set -x
2234
docker run -it --rm \
35+
"${EXTRA_DOCKER_ARGS:-}" \
2336
--env=http_proxy="${http_proxy:-}" --env=https_proxy="${https_proxy:-}" \
2437
--env BENCHBASE_PROFILE="$BENCHBASE_PROFILE" \
2538
--user "$CONTAINERUSER_UID:$CONTAINERUSER_GID" \
26-
-v "$PWD/results:/benchbase/results" benchbase-$BENCHBASE_PROFILE:latest $*
39+
-v "$SRC_DIR/results:/benchbase/results" benchbase-$BENCHBASE_PROFILE:latest $*
2740
set +x
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
set -x
5+
6+
benchmark="${1:-noop}"
7+
8+
# Let these pass through from the .env file from the devcontainer.
9+
export BENCHBASE_PROFILE="${BENCHBASE_PROFILE:-postgres}"
10+
export BENCHBASE_PROFILES="$BENCHBASE_PROFILE"
11+
12+
# When we are running the full image we don't generally want to have to rebuild it repeatedly.
13+
export CLEAN_BUILD="${CLEAN_BUILD:-false}"
14+
15+
# Move to the repo root.
16+
scriptdir=$(dirname "$(readlink -f "$0")")
17+
rootdir=$(readlink -f "$scriptdir/..")
18+
cd "$rootdir"
19+
20+
if [ ! -x "docker/${BENCHBASE_PROFILE}-latest/up.sh" ]; then
21+
echo "ERROR: No docker up.sh script available for '$BENCHBASE_PROFILE'"
22+
fi
23+
24+
pushd "docker/${BENCHBASE_PROFILE}-latest"
25+
./up.sh
26+
popd
27+
28+
SKIP_TESTS=${SKIP_TESTS:-true} EXTRA_DOCKER_ARGS="--network=host" \
29+
./docker/benchbase/run-full-image.sh \
30+
--config "config/sample_${benchmark}_config.xml" --bench "$benchmark" \
31+
--create=true --load=true --execute=true \
32+
--sample 1 --interval-monitor 1000 \
33+
--json-histograms results/histograms.json

0 commit comments

Comments
 (0)