Skip to content

Commit 6b5e1b5

Browse files
adrian-kongJason Mobarak
andauthored
Locked stdin and out for rust sbp2json (#1161)
* locked stdin and out for rust sbp2json * updated benchmark thresholds * updated python dockerfile to slim-buster * updated rust dockerfile version 1.55 -> 1.61 * installing musl-tools in docker * changed to build musl-tools for linux Co-authored-by: Jason Mobarak <[email protected]>
1 parent 8d504df commit 6b5e1b5

File tree

10 files changed

+25
-18
lines changed

10 files changed

+25
-18
lines changed

python/Dockerfile.benchmark

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.7-slim-stretch
1+
FROM python:3.7-slim-buster
22

33
ENV DEBIAN_FRONTEND=noninteractive
44
RUN apt-get update \

rust/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.55-slim-buster
1+
FROM rust:1.61-slim-buster
22

33
ARG DEBIAN_FRONTEND=noninterative
44

@@ -13,14 +13,15 @@ RUN mkdir -p $SCCACHE_DIR
1313

1414
RUN \
1515
apt-get update \
16-
&& apt-get install -y libssl-dev pkg-config curl build-essential make \
16+
&& apt-get install -y libssl-dev pkg-config curl build-essential make musl-tools \
1717
&& curl -sSL -o /tmp/sccache.tgz "${SCCACHE_URL}" \
1818
&& mkdir /tmp/sccache \
1919
&& tar --strip-components=1 -C /tmp/sccache -xzf /tmp/sccache.tgz \
2020
&& mv /tmp/sccache/sccache /usr/local/bin \
2121
&& chmod +x /usr/local/bin/sccache \
2222
&& rustup component add rustfmt \
2323
&& rustup component add clippy \
24+
&& rustup target add x86_64-unknown-linux-musl \
2425
&& rm -rf /var/lib/apt/lists/* \
2526
&& rm -rf /tmp/sccache /tmp/sccache.tgz
2627

rust/sbp2json/src/bin/json2json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ fn main() -> Result<()> {
5353

5454
let stdin: Box<dyn Read> = match options.input {
5555
Some(path) => Box::new(File::open(path)?),
56-
_ => Box::new(io::stdin()),
56+
_ => Box::new(io::stdin().lock()),
5757
};
5858

5959
let stdout: Box<dyn Write> = match options.output {
6060
Some(path) => Box::new(File::create(path)?),
61-
_ => Box::new(io::stdout()),
61+
_ => Box::new(io::stdout().lock()),
6262
};
6363

6464
if options.float_compat {

rust/sbp2json/src/bin/json2sbp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ fn main() -> Result<()> {
4848

4949
let stdin: Box<dyn Read> = match options.input {
5050
Some(path) => Box::new(File::open(path)?),
51-
_ => Box::new(io::stdin()),
51+
_ => Box::new(io::stdin().lock()),
5252
};
5353

5454
let stdout: Box<dyn Write> = match options.output {
5555
Some(path) => Box::new(File::create(path)?),
56-
_ => Box::new(io::stdout()),
56+
_ => Box::new(io::stdout().lock()),
5757
};
5858

5959
json2sbp(stdin, stdout, options.buffered, options.fatal_errors)

rust/sbp2json/src/bin/sbp2json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ fn main() -> Result<()> {
5757

5858
let stdin: Box<dyn Read> = match options.input {
5959
Some(path) => Box::new(File::open(path)?),
60-
_ => Box::new(io::stdin()),
60+
_ => Box::new(io::stdin().lock()),
6161
};
6262

6363
let stdout: Box<dyn Write> = match options.output {
6464
Some(path) => Box::new(File::create(path)?),
65-
_ => Box::new(io::stdout()),
65+
_ => Box::new(io::stdout().lock()),
6666
};
6767

6868
if options.float_compat {

scripts/ci_benchmark.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ docker run \
5353
--rm \
5454
--name rust-sbp2json-run \
5555
rust-sbp2json \
56-
cargo build --release
56+
cargo build --release --target=x86_64-unknown-linux-musl
5757

5858
sudo chown "$USER:$USER" "$HOME/.docker-cache"
5959
sudo chown -R "$USER:$USER" "$HOME/.docker-cache/cargo"
6060
sudo chown -R "$USER:$USER" "$PWD"
6161

62-
rust_bins="$HOME/.docker-cache/cargo/work/release"
62+
rust_bins="$HOME/.docker-cache/cargo/work/x86_64-unknown-linux-musl/release"
6363

6464
mkdir -p bin
6565

scripts/ci_build_rust.bash

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ else
1919
exit 1
2020
fi
2121

22-
cargo build --all --release
23-
24-
cd target/release
22+
if [ "$RUNNER_OS" == "Linux" ]; then
23+
cargo build --all --release --target=x86_64-unknown-linux-musl
24+
cd target/x86_64-unknown-linux-musl/release
25+
else
26+
cargo build --all --release
27+
cd target/release
28+
fi
2529

2630
strip "${EXECUTABLES[@]}"
2731

scripts/ci_prepare_python.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ sudo apt-get install -y \
2828
python3 python3-dev python3-distutils \
2929
python3.9 python3.9-dev python3.9-distutils \
3030
python3.10 python3.10-dev python3.10-distutils \
31+
musl-tools \
3132
tox dpkg-dev wget
3233

3334
pip3 install wheel setuptools

scripts/ci_prepare_rust.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -ex
44

55
if [ "$RUNNER_OS" == "Linux" ]; then
66
sudo apt-get -qq update
7-
sudo apt-get -qq install -y pkg-config build-essential libudev-dev
7+
sudo apt-get -qq install -y pkg-config build-essential libudev-dev musl-tools
8+
rustup target add x86_64-unknown-linux-musl
89
elif [ "$RUNNER_OS" == "macOS" ]; then
910
brew install cmake
1011
elif [ "$RUNNER_OS" == "Windows" ]; then

test_data/benchmark_main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
# How much faster Rust should be than other implementations
1313
RATIOS_SBP2JSON = {
14-
"haskell": 2.19,
15-
"python": 24.96,
14+
"haskell": 2.08,
15+
"python": 17.48,
1616
}
1717

1818
RATIOS_JSON2SBP = {
1919
"haskell": 2.05,
2020
}
2121

2222
RATIOS_JSON2JSON = {
23-
"haskell": 2.78,
23+
"haskell": 2.60,
2424
}
2525

2626
FAILED = [False]

0 commit comments

Comments
 (0)