Skip to content

Latest commit

 

History

History

helloworld_transcoding

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Helloworld with HTTP/json transcoding in grpc-elixir

Usage

  1. Install deps and compile
$ mix do deps.get, compile
  1. Run the server
$ mix run --no-halt
  1. Run the client script
$ mix run priv/client.exs

HTTP Transcoding

# Say hello
$ curl -H 'accept: application/json' http://localhost:50051/v1/greeter/test

# Say hello from
$ curl -XPOST -H 'Content-type: application/json' -d '{"name": "test", "from": "anon"}' http://localhost:50051/v1/greeter

Regenerate Elixir code from proto

  1. Modify the proto priv/protos/helloworld.proto

  2. Install protoc here

mix deps.get
  1. Generate google.api.http extensions:
$ mix protobuf.generate --include-path=priv/protos --output-path=./lib priv/protos/google/api/annotations.proto priv/protos/google/api/http.proto
  1. Generate the code:
$ mix protobuf.generate --include-path=priv/protos --plugins=ProtobufGenerate.Plugins.GRPCWithOptions --output-path=./lib priv/protos/helloworld.proto

Refer to protobuf-elixir for more information.

How to start server when starting your application?

Pass start_server: true as an option for the GRPC.Server.Supervisor in your supervision tree.

Benchmark

Using ghz

$ MIX_ENV=prod iex -S mix
# Now cowboy doesn't work well with concurrency in a connection, like --concurrency 6 --connections 1
$ ghz --insecure --proto priv/protos/helloworld.proto --call helloworld.Greeter.SayHello -d '{"name":"Joe"}' -z 10s  --concurrency 6 --connections 6 127.0.0.1:50051
# The result is for branch improve-perf
Summary:
  Count:	124239
  Total:	10.00 s
  Slowest:	18.85 ms
  Fastest:	0.18 ms
  Average:	0.44 ms
  Requests/sec:	12423.71

# Go
Summary:
  Count:	258727
  Total:	10.00 s
  Slowest:	5.39 ms
  Fastest:	0.09 ms
  Average:	0.19 ms
  Requests/sec:	25861.68