awakesecurity / gRPC-haskell

Haskell gRPC support
https://hackage.haskell.org/package/grpc-haskell
Apache License 2.0
238 stars 75 forks source link

Performance issue #163

Closed MohsenNz closed 6 months ago

MohsenNz commented 6 months ago

Hi, I have performance issue in running arithmetic example server (I got 7030 ms latency tested in postman and more). Actually when I run it in the repo directory inside nix-shell everything is fine (cabal configure -f with-examples && cabal build then run the arithmetic server), but I coped the example code elsewhere and tried to configure it by my self. (I do that in 2 ways 1-nix way 2-cabal way) in both of them I got the problem. I'll just explain my nix way here: my flake.nix:

{
  outputs = _: 
    let
      system = "x86_64-linux";
      grpc-overlay = (import ./gRPC-haskell/release.nix).overlay;
      grpc-nixpkgs = (import ./gRPC-haskell/nixpkgs.nix) { inherit system; overlays = [ grpc-overlay ]; };
      myHaskellPackages = grpc-nixpkgs.haskellPackages.extend myAppOverlay;
      myAppOverlay = final: _prev: {
        arithmetic = final.callCabal2nix "arithmetic" ./. { };
      };
    in
    {
      devShells.${system}.default = myHaskellPackages.shellFor {
        packages = p : [
          p.arithmetic
        ];
        nativeBuildInputs = [
          myHaskellPackages.cabal-install
          myHaskellPackages.haskell-language-server
          myHaskellPackages.grpc-haskell
          myHaskellPackages.proto3-suite
          grpc-nixpkgs.zlib
          grpc-nixpkgs.grpc
        ];
      };
    };
}

enter to the dev shell:

λ nix develop

generate code:

λ compile-proto-file --proto arithmetic.proto --out .

build:

λ cabal build

run server

λ ./dist-newstyle/build/x86_64-linux/ghc-9.0.2/arithmetic-0.1.0.0/x/server/build/server/server

Now I test the RPC add in postman and I get, 11382 ms latency. The latency when I test it inside your repo is about 75 m e.g. What's wrong? (Also I've added all dependency needed, but if you need it, tell me to send you) It is my file structure:

.
├── app
│   └── Main.hs
├── arithmetic.cabal
├── Arithmetic.hs
├── arithmetic.proto
├── client
│   └── ArithmeticClient.hs
├── dist-newstyle
│    . . .
├── flake.lock
├── flake.nix
├── gRPC-haskell
│    . . .
└── server
    └── ArithmeticServer.hs
MohsenNz commented 6 months ago

OK, after adding ghc-options: -Wall -Werror -g -threaded -rtsopts -with-rtsopts=-N -O2 to the cabal file, the performance fixed... Thanks...