Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dep_grpc_lib = git https://github.com/Bluehouse-Technology/grpc_lib
TEST_DEPS = grpc_client
dep_grpc_client = git https://github.com/Bluehouse-Technology/grpc_client

include erlang.mk
include $(if $(ERLANG_MK_FILENAME),$(ERLANG_MK_FILENAME),erlang.mk)

LOAD_TEST_NUM_WORKERS=200
LOAD_TEST_NUM_REQS_PER_WORKER=1000
Expand Down
53 changes: 53 additions & 0 deletions Makefile.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
PROJECT = grpc
PROJECT_DESCRIPTION = gRPC in Erlang
PROJECT_VERSION = 0.1.0

# Whitespace to be used when creating files from templates.
SP = 4

DEPS = cowboy grpc_lib
# Use the cowboy version that has support for trailers.
dep_cowboy_commit = master
dep_grpc_lib = git https://github.com/Bluehouse-Technology/grpc_lib

TEST_DEPS = grpc_client
dep_grpc_client = git https://github.com/Bluehouse-Technology/grpc_client

include $(if $(ERLANG_MK_FILENAME),$(ERLANG_MK_FILENAME),erlang.mk)

LOAD_TEST_NUM_WORKERS=200
LOAD_TEST_NUM_REQS_PER_WORKER=1000

grpc_load_test: test-deps start_test_server run_grpc_load_test stop_test_server
rpc_load_test: test-deps start_test_server run_rpc_load_test stop_test_server

start_test_server:
@echo "Starting test server..."
@cd test && erlc run_load_test.erl && erlc statistics.erl && \
erlc statistics_server.erl && cd ..
@erl -sname grpc_test_server@localhost -pa $(SHELL_PATHS) -pz test -s run_load_test start_grpc_server -detached

stop_test_server:
@echo "Stopping test server..."
@erl -sname erpc_test_node_killer -noinput +B \
-eval 'rpc:async_call(grpc_test_server@localhost, erlang, halt, []), timer:sleep(1000), erlang:halt().'

run_grpc_load_test:
@echo "Starting grpc test client..."
@cd test && erlc run_load_test.erl && erlc statistics.erl && \
erlc statistics_client.erl && cd ..
erl -sname grpc_test_client -pa $(SHELL_PATHS) -pz test -s run_load_test start_client -- \
-num_workers ${LOAD_TEST_NUM_WORKERS} \
-server localhost \
-num_requests_per_worker ${LOAD_TEST_NUM_REQS_PER_WORKER} \
-rpc_type grpc

run_rpc_load_test:
@echo "Starting native rpc test client..."
@cd test && erlc run_load_test.erl && erlc statistics.erl && \
erlc statistics_client.erl && cd ..
erl -sname grpc_test_client -pa $(SHELL_PATHS) -pz test -s run_load_test start_client -- \
-num_workers ${LOAD_TEST_NUM_WORKERS} \
-server grpc_test_server@localhost \
-num_requests_per_worker ${LOAD_TEST_NUM_REQS_PER_WORKER} \
-rpc_type native
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% Middleware example that logs to disk
-module(route_guide_middleware).
-module(route_guide_logging_middleware).
-behaviour(cowboy_middleware).

-export([execute/2]).
Expand Down
12 changes: 6 additions & 6 deletions src/grpc.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application,grpc,
[{description,"gRPC in Erlang"},
{vsn,"0.2.0"},
{modules,[]},
{registered, []},
{env, []},
{applications,[gpb,cowboy]}]}.
[{description,"gRPC in Erlang"},
{vsn,"0.2.0"},
{modules,[]},
{registered,[]},
{env,[]},
{applications,[gpb,cowboy]}]}.
17 changes: 14 additions & 3 deletions src/grpc_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ start(Name, Transport, Port, Services, Options) ->
#{auth_fun => AuthFun,
services => Services}}]}]),
ProtocolOpts = #{env => #{dispatch => Dispatch},
%% inactivity_timeout => infinity,
inactivity_timeout => infinity,
idle_timeout => infinity,
preface_timeout => infinity,
settings_timeout => infinity,
shutdown_timeout => infinity,
linger_timeout => infinity,
request_timeout => infinity,
stream_handlers => [grpc_stream_handler,
cowboy_stream_h],
middlewares => Middlewares},
%io:fwrite("Sending protocol options: ~p.~n", [ProtocolOpts]),
case Transport of
tcp ->
cowboy:start_clear(Name, [{port, Port}], ProtocolOpts);
Expand Down Expand Up @@ -95,7 +102,7 @@ make_stream(#{headers := Headers,
scheme := Scheme,
path := Path,
method := Method} = Req) ->
maps:fold(fun process_header/3,
Processed = maps:fold(fun process_header/3,
#{cowboy_req => Req,
authority => Authority,
scheme => Scheme,
Expand All @@ -113,7 +120,11 @@ make_stream(#{headers := Headers,
start_time => erlang:system_time(1),
content_type => undefined,
user_agent => undefined,
timeout => infinity}, Headers).
timeout => infinity}, Headers),
maps:update_with(
headers,
fun(Hdrs) -> maps:put(<<"content-type">>,maps:get(content_type, Processed), Hdrs) end,
Processed).

process_header(<<"grpc-timeout">>, Value, Acc) ->
Acc#{timeout => Value};
Expand Down