Skip to content

Commit

Permalink
Scripts for running locally in docker and adjust SqlServer to match o…
Browse files Browse the repository at this point in the history
…thers (#266)

- Adds some scripts to ease running tests locally in docker containers.
- Adjusts SqlServer patterns to match other DBs.
  • Loading branch information
bpkroth authored Mar 23, 2023
1 parent 5e1b094 commit 494781c
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
"no_proxy": "${localEnv:no_proxy}",
"MAVEN_CONFIG": "${localEnv:HOME}/.m2",
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
"CONTAINER_WORKSPACE_FOLDER": "${containerWorkspaceFolder}",
"CONTAINER_WORKSPACE_FOLDER": "${containerWorkspaceFolder}"
},
// Set *default* container specific settings.json values on container create.
"customizations": {
"vscode": {
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"GitHub.copilot",
"eamodio.gitlens",
"vscjava.vscode-java-pack",
"EditorConfig.EditorConfig"
]
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ jobs:
benchmark: [ 'tpcc', 'tpch' ]
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
image: mcr.microsoft.com/mssql/server:latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: SApassword1
Expand Down Expand Up @@ -347,11 +347,17 @@ jobs:
java-version: ${{env.JAVA_VERSION}}
distribution: 'temurin'

- name: Cleanup database
uses: docker://mcr.microsoft.com/mssql-tools:latest
with:
entrypoint: /opt/mssql-tools/bin/sqlcmd
args: -U sa -P SApassword1 -S sqlserver -b -Q "DROP DATABASE IF EXISTS benchbase;"

- name: Setup database
uses: docker://mcr.microsoft.com/mssql-tools:latest
with:
entrypoint: /opt/mssql-tools/bin/sqlcmd
args: -U sa -P SApassword1 -S sqlserver -b -Q "CREATE DATABASE benchbase_${{ matrix.benchmark }};"
args: -U sa -P SApassword1 -S sqlserver -b -Q "CREATE DATABASE benchbase;"

- name: Setup login
uses: docker://mcr.microsoft.com/mssql-tools:latest
Expand All @@ -363,7 +369,7 @@ jobs:
uses: docker://mcr.microsoft.com/mssql-tools:latest
with:
entrypoint: /opt/mssql-tools/bin/sqlcmd
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';"
args: -U sa -P SApassword1 -S sqlserver -b -Q "USE benchbase; CREATE USER benchuser01 FROM LOGIN benchuser01; EXEC sp_addrolemember 'db_owner', 'benchuser01';"

- name: Run benchmark
# Note: user/pass should match those used in sample configs.
Expand Down
2 changes: 1 addition & 1 deletion config/sqlserver/sample_tpcc_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Connection details -->
<type>sqlserver</type>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>jdbc:sqlserver://localhost:1433;encrypt=false;database=benchbase_tpcc;</url>
<url>jdbc:sqlserver://localhost:1433;encrypt=false;database=benchbase;</url>
<username>benchuser01</username>
<password>P@ssw0rd</password>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
Expand Down
2 changes: 1 addition & 1 deletion config/sqlserver/sample_tpch_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Connection details -->
<type>sqlserver</type>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>jdbc:sqlserver://localhost:1433;encrypt=false;database=benchbase_tpch;</url>
<url>jdbc:sqlserver://localhost:1433;encrypt=false;database=benchbase;</url>
<username>benchuser01</username>
<password>P@ssw0rd</password>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
Expand Down
23 changes: 23 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Docker Use

Scripts in this directory can be used to quickly run a benchmark against a sample database.

For instance:

```bash
# Set which database to target.
export BENCHBASE_PROFILE='sqlserver'
# Set which profiles to build.
export BENCHBASE_PROFILES=$BENCHBASE_PROFILE
# Whether or not to rebuild the package/image.
export CLEAN_BUILD="false"
# When rebuilding, whether or not to run the unit tests.
export SKIP_TESTS="true"

# Set which benchmark to run.
benchmark='tpcc'

./docker/build-run-benchmark-with-docker.sh $benchmark
```

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.
14 changes: 12 additions & 2 deletions docker/benchbase/build-full-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,24 @@ function create_image() {
# Make (hard-linked) copies of the build results that we can put into the image.
pushd "$scriptdir/fullimage/"
rm -rf tmp/
mkdir -p tmp/docker-build-stage/
mkdir -p tmp/config/
mkdir -p tmp/profiles/
cp -a "$rootdir/config/plugin.xml" tmp/config/
for profile in $profiles; do
if ! [ -f "$rootdir/profiles/$profile/benchbase.jar" ]; then
echo "ERROR: build for $profile appears to have failed." >&2
exit 1
fi
cp -al "$rootdir/profiles/$profile" tmp/docker-build-stage/
cp -al "$rootdir/profiles/$profile" tmp/profiles/

# Consolidate the configs across profiles.
cp -a "$rootdir/profiles/$profile/config/$profile" tmp/config/
rm -rf tmp/profiles/$profile/config
ln -s ../../config/$profile "tmp/profiles/$profile/config"
ln -s . tmp/profiles/$profile/config/$profile
ln -s ../plugin.xml tmp/config/$profile/
done

# Make a copy of the entrypoint script that changes the default profile to
# execute for singleton images.
cp -a entrypoint.sh tmp/entrypoint.sh
Expand Down
2 changes: 1 addition & 1 deletion docker/benchbase/devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LABEL org.opencontainers.image.source = "https://github.com/cmu-db/benchbase/"
# Also add a few nice cli tools.
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends sudo vim-nox neovim less bash-completion colordiff git \
&& apt-get -y install --no-install-recommends sudo vim-nox neovim less bash-completion colordiff git jq \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Add a containeruser that allows vscode/codespaces to map the local host user
Expand Down
5 changes: 2 additions & 3 deletions docker/benchbase/fullimage/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ VOLUME /benchbase/results
# Only copy the content necessary for running (not building) benchbase over to the image.
# These files should have been built using the devcontainer by the
# build-full-image.sh script.
COPY ./entrypoint.sh /entrypoint.sh
COPY ./docker-build-stage/ /benchbase/profiles/
COPY . /benchbase/

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/benchbase/entrypoint.sh"]
CMD ["--help"]
17 changes: 15 additions & 2 deletions docker/benchbase/run-full-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,31 @@ rootdir=$(readlink -f "$scriptdir/../../")

cd "$scriptdir"
. ./common-env.sh
./build-full-image.sh
if ! docker image ls --quiet benchbase-$BENCHBASE_PROFILE:latest | grep -q .; then
# Missing image, need to build it.
CLEAN_BUILD=true
fi

if [ "$CLEAN_BUILD" != 'false' ]; then
./build-full-image.sh
fi

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

SRC_DIR="$PWD"
if [ -n "$LOCAL_WORKSPACE_FOLDER" ]; then
SRC_DIR="$LOCAL_WORKSPACE_FOLDER"
fi

cd "$rootdir"
mkdir -p results/
set -x
docker run -it --rm \
"${EXTRA_DOCKER_ARGS:-}" \
--env=http_proxy="${http_proxy:-}" --env=https_proxy="${https_proxy:-}" \
--env BENCHBASE_PROFILE="$BENCHBASE_PROFILE" \
--user "$CONTAINERUSER_UID:$CONTAINERUSER_GID" \
-v "$PWD/results:/benchbase/results" benchbase-$BENCHBASE_PROFILE:latest $*
-v "$SRC_DIR/results:/benchbase/results" benchbase-$BENCHBASE_PROFILE:latest $*
set +x
33 changes: 33 additions & 0 deletions docker/build-run-benchmark-with-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -eu
set -x

benchmark="${1:-noop}"

# Let these pass through from the .env file from the devcontainer.
export BENCHBASE_PROFILE="${BENCHBASE_PROFILE:-postgres}"
export BENCHBASE_PROFILES="$BENCHBASE_PROFILE"

# When we are running the full image we don't generally want to have to rebuild it repeatedly.
export CLEAN_BUILD="${CLEAN_BUILD:-false}"

# Move to the repo root.
scriptdir=$(dirname "$(readlink -f "$0")")
rootdir=$(readlink -f "$scriptdir/..")
cd "$rootdir"

if [ ! -x "docker/${BENCHBASE_PROFILE}-latest/up.sh" ]; then
echo "ERROR: No docker up.sh script available for '$BENCHBASE_PROFILE'"
fi

pushd "docker/${BENCHBASE_PROFILE}-latest"
./up.sh
popd

SKIP_TESTS=${SKIP_TESTS:-true} EXTRA_DOCKER_ARGS="--network=host" \
./docker/benchbase/run-full-image.sh \
--config "config/sample_${benchmark}_config.xml" --bench "$benchmark" \
--create=true --load=true --execute=true \
--sample 1 --interval-monitor 1000 \
--json-histograms results/histograms.json
3 changes: 0 additions & 3 deletions docker/sqlserver-2019-latest/up.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
sqlserver:
container_name: sqlserver
hostname: sqlserver
image: mcr.microsoft.com/mssql/server:2019-latest
image: mcr.microsoft.com/mssql/server:latest
environment:
ACCEPT_EULA: Y
SA_PASSWORD: SApassword1
Expand Down
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions docker/sqlserver-latest/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -eu

docker compose up -d

network=$(docker ps --format "{{.Names}} {{.Networks}}" | awk '( $1 ~ /^'$BENCHBASE_PROFILE'/ ) { print $2 }')

# Also setup the database for use with the sample configs.
# See Also: .github/workflows/maven.yml

function run_sqlcmd_in_docker() {
set -x
docker run --rm --network=$network --entrypoint /opt/mssql-tools/bin/sqlcmd mcr.microsoft.com/mssql-tools:latest \
-U sa -P SApassword1 -S sqlserver -b "$@"
set +x
}

# Cleanup database
run_sqlcmd_in_docker -Q "DROP DATABASE IF EXISTS benchbase;"

# Setup database
run_sqlcmd_in_docker -Q "CREATE DATABASE benchbase;"

# Setup login
run_sqlcmd_in_docker -Q "CREATE LOGIN benchuser01 WITH PASSWORD='P@ssw0rd';" || true

# Setup access
run_sqlcmd_in_docker -Q "USE benchbase; CREATE USER benchuser01 FROM LOGIN benchuser01; EXEC sp_addrolemember 'db_owner', 'benchuser01';" || true

0 comments on commit 494781c

Please sign in to comment.