diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34b6d748..00b60ee4 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 }} + dart_grpc_bench: + runs-on: ubuntu-latest + needs: + - set-image-name + - changed + if: fromJSON(needs.changed.outputs.base) || contains(needs.changed.outputs.files, 'dart_grpc_bench/') + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build dart_grpc_bench + run: ./build.sh dart_grpc_bench + env: + GRPC_IMAGE_NAME: ${{ needs.set-image-name.outputs.name }} + + - name: Benchmark dart_grpc_bench + run: ./bench.sh dart_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@v3 + 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:dart_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/dart_grpc_bench/.dockerignore b/dart_grpc_bench/.dockerignore new file mode 100644 index 00000000..d35754ed --- /dev/null +++ b/dart_grpc_bench/.dockerignore @@ -0,0 +1,8 @@ +.dockerignore +Dockerfile +build/ +.dart_tool/ +.git/ +.github/ +.gitignore +.packages \ No newline at end of file diff --git a/dart_grpc_onhold/Dockerfile b/dart_grpc_bench/Dockerfile similarity index 66% rename from dart_grpc_onhold/Dockerfile rename to dart_grpc_bench/Dockerfile index 850b398b..a7c325c8 100644 --- a/dart_grpc_onhold/Dockerfile +++ b/dart_grpc_bench/Dockerfile @@ -1,17 +1,22 @@ -FROM dart:2.19.4 AS build +FROM dart:stable AS build WORKDIR /app COPY dart_grpc_bench/pubspec.yaml /app/pubspec.yaml -COPY proto /app/proto - RUN dart pub get + +COPY proto /app/proto COPY dart_grpc_bench /app + # Ensure packages are still up-to-date if anything has changed -RUN dart pub get --offline -RUN apt update && apt install -y protobuf-compiler -RUN dart pub global activate protoc_plugin -RUN mkdir -p lib/src/generated -RUN protoc --plugin=protoc-gen-dart=$HOME/.pub-cache/bin/protoc-gen-dart --proto_path=/app/proto/helloworld --dart_out=grpc:lib/src/generated -Iproto /app/proto/helloworld/helloworld.proto +RUN dart pub get --offline \ + && apt update && apt install -y protobuf-compiler \ + && dart pub global activate protoc_plugin \ + && mkdir -p lib/src/generated + +RUN protoc --plugin=protoc-gen-dart=$HOME/.pub-cache/bin/protoc-gen-dart \ + --proto_path=/app/proto/helloworld \ + --dart_out=grpc:lib/src/generated \ + -Iproto /app/proto/helloworld/helloworld.proto RUN dart compile exe bin/server.dart -o bin/server diff --git a/dart_grpc_onhold/bin/server.dart b/dart_grpc_bench/bin/server.dart similarity index 84% rename from dart_grpc_onhold/bin/server.dart rename to dart_grpc_bench/bin/server.dart index ced7ed45..2c9b0c98 100644 --- a/dart_grpc_onhold/bin/server.dart +++ b/dart_grpc_bench/bin/server.dart @@ -18,11 +18,12 @@ import 'dart:io'; import 'dart:isolate'; import 'package:grpc/grpc.dart'; +import 'package:http2/http2.dart'; -import 'package:helloworld/src/generated/helloworld.pb.dart'; import 'package:helloworld/src/generated/helloworld.pbgrpc.dart'; class GreeterService extends GreeterServiceBase { + @override Future sayHello(ServiceCall call, HelloRequest request) async { return HelloReply()..response = request.request; @@ -35,7 +36,7 @@ Future main(List args) async { if (cpus > 1) { for (var serve = 0; serve < cpus; serve++) { - Isolate.spawn(_startServer, []); + Isolate.spawn(_startServer, [cpus]); } } // Bind one server in current Isolate @@ -46,7 +47,12 @@ Future main(List args) async { } void _startServer([List? args]) async { - final server = Server([GreeterService()]); + final server = Server.create( + services: [GreeterService()], + ); await server.serve( - address: InternetAddress.anyIPv4, port: 50051, shared: true); + port: 50051, + shared: true, + http2ServerSettings: ServerSettings(concurrentStreamLimit: args?[0]) + ); } diff --git a/dart_grpc_onhold/pubspec.lock b/dart_grpc_bench/pubspec.lock similarity index 87% rename from dart_grpc_onhold/pubspec.lock rename to dart_grpc_bench/pubspec.lock index e5e21b8c..f911fbd8 100644 --- a/dart_grpc_onhold/pubspec.lock +++ b/dart_grpc_bench/pubspec.lock @@ -13,10 +13,18 @@ packages: dependency: "direct main" description: name: async - sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" url: "https://pub.dev" source: hosted - version: "2.10.0" + version: "2.11.0" + clock: + dependency: transitive + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" collection: dependency: transitive description: @@ -61,10 +69,10 @@ packages: dependency: "direct main" description: name: grpc - sha256: a73c16e4f6a4a819be892bb2c73cc1d0b00e36095f69b0738cc91a733e3d27ba + sha256: e93ee3bce45c134bf44e9728119102358c7cd69de7832d9a874e2e74eb8cab40 url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.2.4" http: dependency: transitive description: @@ -77,10 +85,10 @@ packages: dependency: transitive description: name: http2 - sha256: "58805ebc6513eed3b98ee0a455a8357e61d187bf2e0fdc1e53120770f78de258" + sha256: "38db0c4aa9f1cd238a5d2e86aa0cc7cc91c77e0c6c94ba64bbe85e4ff732a952" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.2.0" http_parser: dependency: transitive description: @@ -125,10 +133,10 @@ packages: dependency: "direct main" description: name: protobuf - sha256: "01dd9bd0fa02548bf2ceee13545d4a0ec6046459d847b6b061d8a27237108a08" + sha256: "68645b24e0716782e58948f8467fd42a880f255096a821f9e7d0ec625b00c84d" url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "3.1.0" source_span: dependency: transitive description: @@ -162,4 +170,4 @@ packages: source: hosted version: "1.3.1" sdks: - dart: ">=2.19.0 <4.0.0" + dart: ">=3.1.0 <4.0.0" diff --git a/dart_grpc_bench/pubspec.yaml b/dart_grpc_bench/pubspec.yaml new file mode 100644 index 00000000..8a500ac3 --- /dev/null +++ b/dart_grpc_bench/pubspec.yaml @@ -0,0 +1,9 @@ +name: helloworld + +environment: + sdk: ^3.1.0 + +dependencies: + async: ^2.11.0 + grpc: ^3.2.4 + protobuf: ^3.1.0 diff --git a/dart_grpc_onhold/.dockerignore b/dart_grpc_onhold/.dockerignore deleted file mode 100644 index 91da415d..00000000 --- a/dart_grpc_onhold/.dockerignore +++ /dev/null @@ -1,3 +0,0 @@ -.dockerignore -Dockerfile -.dart_tool/ \ No newline at end of file diff --git a/dart_grpc_onhold/pubspec.yaml b/dart_grpc_onhold/pubspec.yaml deleted file mode 100644 index f06dc33d..00000000 --- a/dart_grpc_onhold/pubspec.yaml +++ /dev/null @@ -1,9 +0,0 @@ -name: helloworld - -environment: - sdk: '>=2.19.0 <3.0.0' - -dependencies: - async: ^2.10.0 - grpc: ^3.1.0 - protobuf: ^2.1.0