Skip to content

Commit

Permalink
Add D benchmark (LesnyRumcajs#202)
Browse files Browse the repository at this point in the history
* add d bench - wip

* use a working D image

* Update

Co-authored-by: Trisfald <[email protected]>
  • Loading branch information
kubo39 and Trisfald authored Mar 9, 2022
1 parent fc62fb0 commit ad29377
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions d_grpc_bench/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
29 changes: 29 additions & 0 deletions d_grpc_bench/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
10 changes: 10 additions & 0 deletions d_grpc_bench/dub.json
Original file line number Diff line number Diff line change
@@ -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"]
}
12 changes: 12 additions & 0 deletions d_grpc_bench/dub.selections.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
15 changes: 15 additions & 0 deletions d_grpc_bench/source/GreeterImpl.d
Original file line number Diff line number Diff line change
@@ -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;
}
}
21 changes: 21 additions & 0 deletions d_grpc_bench/source/server.d
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit ad29377

Please sign in to comment.