From ad29377a5e4f62b636613d521943feb15a4fb594 Mon Sep 17 00:00:00 2001 From: Hiroki Noda Date: Thu, 10 Mar 2022 06:34:46 +0900 Subject: [PATCH] Add D benchmark (#202) * add d bench - wip * use a working D image * Update Co-authored-by: Trisfald --- .github/workflows/build.yml | 36 +++++++++++++++++++++++++++++++ d_grpc_bench/.dockerignore | 1 + d_grpc_bench/Dockerfile | 29 +++++++++++++++++++++++++ d_grpc_bench/dub.json | 10 +++++++++ d_grpc_bench/dub.selections.json | 12 +++++++++++ d_grpc_bench/source/GreeterImpl.d | 15 +++++++++++++ d_grpc_bench/source/server.d | 21 ++++++++++++++++++ 7 files changed, 124 insertions(+) create mode 100644 d_grpc_bench/.dockerignore create mode 100644 d_grpc_bench/Dockerfile create mode 100644 d_grpc_bench/dub.json create mode 100644 d_grpc_bench/dub.selections.json create mode 100644 d_grpc_bench/source/GreeterImpl.d create mode 100644 d_grpc_bench/source/server.d diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2b2fe98c..a6c99330 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -240,6 +240,42 @@ jobs: GRPC_IMAGE_NAME: ${{ needs.set-image-name.outputs.name }} + d_grpc_bench: + runs-on: ubuntu-latest + needs: + - set-image-name + - changed + if: fromJSON(needs.changed.outputs.base) || contains(needs.changed.outputs.files, 'd_grpc_bench/') + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Build d_grpc_bench + run: ./build.sh d_grpc_bench + env: + GRPC_IMAGE_NAME: ${{ needs.set-image-name.outputs.name }} + + - name: Benchmark d_grpc_bench + run: ./bench.sh d_grpc_bench + env: + GRPC_BENCHMARK_DURATION: 30s + GRPC_IMAGE_NAME: ${{ needs.set-image-name.outputs.name }} + + - if: github.ref == 'refs/heads/master' + name: Log in to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - if: github.ref == 'refs/heads/master' + name: If on master push image to GHCR + run: docker push $GRPC_IMAGE_NAME:d_grpc_bench-complex_proto + env: + GRPC_IMAGE_NAME: ${{ needs.set-image-name.outputs.name }} + + dotnet_grpc_bench: runs-on: ubuntu-latest needs: diff --git a/d_grpc_bench/.dockerignore b/d_grpc_bench/.dockerignore new file mode 100644 index 00000000..94143827 --- /dev/null +++ b/d_grpc_bench/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/d_grpc_bench/Dockerfile b/d_grpc_bench/Dockerfile new file mode 100644 index 00000000..5c24db76 --- /dev/null +++ b/d_grpc_bench/Dockerfile @@ -0,0 +1,29 @@ +FROM dlang2/ldc-ubuntu:1.26.0 + +RUN apt update && apt install -y protobuf-compiler git cmake g++ + +WORKDIR /app +RUN git clone --depth 1 --branch master --recurse-submodules https://github.com/huntlabs/grpc-dlang +WORKDIR /app/grpc-dlang +# Building the protocol buffer compiler for D +RUN dub build protobuf:protoc-gen-d +# Building the gRPC plugin for D +WORKDIR /app/grpc-dlang/compiler +RUN mkdir build +WORKDIR /app/grpc-dlang/compiler/build +RUN cmake .. && make -j4 +RUN cp deps/protobuf/protoc* /usr/local/bin +RUN cp grpc_dlang_plugin /usr/local/bin +# Building the core library +WORKDIR /app/grpc-dlang +RUN dub build + +COPY proto /app/proto +COPY d_grpc_bench /app +WORKDIR /app +RUN protoc --plugin=$(find / -name 'protoc-gen-d' -type f | head -n 1) --d_out=/app/source --proto_path=/app/proto/helloworld helloworld.proto +RUN protoc --plugin=protoc-gen-grpc=/usr/local/bin/grpc_dlang_plugin --grpc_out=/app/source/helloworld --proto_path=/app/proto/helloworld helloworld.proto + +RUN dub build -b release + +ENTRYPOINT [ "/app/server" ] diff --git a/d_grpc_bench/dub.json b/d_grpc_bench/dub.json new file mode 100644 index 00000000..ab37b3fb --- /dev/null +++ b/d_grpc_bench/dub.json @@ -0,0 +1,10 @@ +{ + "name": "server", + "description": "A simple example for gRPC.", + "license": "MIT", + "targetType": "executable", + "dependencies": { + "grpc" :{"path": "grpc-dlang"} + }, + "dflags-ldc": ["-flto=full"] +} diff --git a/d_grpc_bench/dub.selections.json b/d_grpc_bench/dub.selections.json new file mode 100644 index 00000000..9123ab54 --- /dev/null +++ b/d_grpc_bench/dub.selections.json @@ -0,0 +1,12 @@ +{ + "fileVersion": 1, + "versions": { + "grpc": {"path":"grpc-dlang"}, + "hunt": "1.7.15", + "hunt-extra": "1.2.3", + "hunt-http": "0.8.1", + "hunt-net": "0.7.1", + "hunt-openssl": "1.0.5", + "protobuf": "0.6.2" + } +} diff --git a/d_grpc_bench/source/GreeterImpl.d b/d_grpc_bench/source/GreeterImpl.d new file mode 100644 index 00000000..5612850a --- /dev/null +++ b/d_grpc_bench/source/GreeterImpl.d @@ -0,0 +1,15 @@ +module GreeterImpl; + +import helloworld.helloworld; +import helloworld.helloworldRpc; +import grpc; + +/** + * + */ +class GreeterImpl : GreeterBase { + override Status SayHello(HelloRequest request, ref HelloReply reply) { + reply.response = request.request; + return Status.OK; + } +} diff --git a/d_grpc_bench/source/server.d b/d_grpc_bench/source/server.d new file mode 100644 index 00000000..a944cca3 --- /dev/null +++ b/d_grpc_bench/source/server.d @@ -0,0 +1,21 @@ +module server; + +import GreeterImpl; +import grpc; +import hunt.logging; +import std.stdio; + +void main() +{ + string host = "0.0.0.0"; + ushort port = 50051; + + GrpcServer server = new GrpcServer(); + server.listen(host , port); + server.register(new GreeterImpl.GreeterImpl()); + server.start(); + + writeln("Server started on ", host, ":", port); + + getchar(); +}