2

Using Mimalloc and alpine build container

Dockerfile:

#docker build -t fast_min -f scratch/Dockerfile .
FROM rust:1.54.0-alpine as builder

# 1a: Prepare for static linking
RUN apk add --update musl gcc g++ musl-dev build-base alpine-sdk ccache
WORKDIR /usr/src

RUN rustup target add x86_64-unknown-linux-musl

RUN USER=root cargo new fasthash-benchmark
WORKDIR /usr/src/fasthash-benchmark
COPY * .
 
RUN cargo build --release --target x86_64-unknown-linux-musl

# 2: Copy the exe and extra files ("static") to an empty Docker image
FROM scratch
COPY --from=builder /usr/src/fasthash-benchmark/target/x86_64-unknown-linux-musl/release/fasthash-benchmark .
USER 1000
CMD ["./fasthash-benchmark"]

cargo.toml

[package]
name = "fasthash-benchmark"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fasthash = "0.4.0"
time = "0.1"
mimalloc = "0.1.26"

main.rs

extern crate time;
use fasthash::murmur3;
use time::PreciseTime;
use mimalloc::MiMalloc;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

fn main() {
    println!("Fasthash!");
    let seed = 0x1234_5789;
    let data = "This is going to be hashed";
    let mut i = 0;
    let mut vec = Vec::new();

    let start = PreciseTime::now();
    let iterations = 100000000;
    while i < iterations {
        let value = murmur3::hash32_with_seed(&mut data.as_bytes(),seed);
        vec.push(value);
        i = i + 1;
    }
    let end = PreciseTime::now();

    println!("Vec size: {}", vec.len());
    println!("{} seconds to hash {} times.", start.to(end), iterations);
}

Error: Error: Internal error occurred: Command "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-static" "-Wno-implicit-fallthrough" "-Wno-unknown-attributes" "-msse4.2" "-maes" "-mavx" "-mavx2" "-DT1HA0_RUNTIME_SELECT=1" "-DT1HA0_AESNI_AVAILABLE=1" "-Wall" "-Wextra" "-o" "/usr/src/fasthash-benchmark/target/x86_64-unknown-linux-musl/release/build/fasthash-sys-ac65a67e7296dad5/out/src/t1ha/src/t1ha0.o" "-c" "src/t1ha/src/t1ha0.c" with args "cc" did not execute successfully (status code exit status: 1).

I have switched this out for a rust native version: https://docs.rs/murmur3/0.5.1/murmur3/

But it is much much slower then fasthash, not that it's a bottleneck. I just want to understand how to fix something like this

JulianK
  • 21
  • 3

1 Answers1

1

There was a bug that prevented the compilation with musl which has already been fixed upstream but there has not been a new release of the crate yet.

You can depend on the git repository directly instead of a version that was released on crates.io.

[dependencies]
fasthash = { git = "https://github.com/flier/rust-fasthash" }
stefan0xC
  • 337
  • 5
  • 11