feat(exhook): expose process pool_size for grpc client
This commit is contained in:
parent
2b7c311807
commit
143c685452
|
@ -25,6 +25,12 @@ exhook {
|
||||||
## Value: false | Duration
|
## Value: false | Duration
|
||||||
auto_reconnect = 60s
|
auto_reconnect = 60s
|
||||||
|
|
||||||
|
## The process pool size for gRPC client
|
||||||
|
##
|
||||||
|
## Default: Equals cpu cores
|
||||||
|
## Value: Integer
|
||||||
|
#pool_size = 16
|
||||||
|
|
||||||
servers = [
|
servers = [
|
||||||
# { name: "default"
|
# { name: "default"
|
||||||
# url: "http://127.0.0.1:9000"
|
# url: "http://127.0.0.1:9000"
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
, server/1
|
, server/1
|
||||||
, put_request_failed_action/1
|
, put_request_failed_action/1
|
||||||
, get_request_failed_action/0
|
, get_request_failed_action/0
|
||||||
|
, put_pool_size/1
|
||||||
|
, get_pool_size/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
|
@ -117,6 +119,9 @@ init([Servers, AutoReconnect, ReqOpts0]) ->
|
||||||
put_request_failed_action(
|
put_request_failed_action(
|
||||||
maps:get(request_failed_action, ReqOpts0, deny)
|
maps:get(request_failed_action, ReqOpts0, deny)
|
||||||
),
|
),
|
||||||
|
put_pool_size(
|
||||||
|
maps:get(pool_size, ReqOpts0, erlang:system_info(schedulers))
|
||||||
|
),
|
||||||
|
|
||||||
%% Load the hook servers
|
%% Load the hook servers
|
||||||
ReqOpts = maps:without([request_failed_action], ReqOpts0),
|
ReqOpts = maps:without([request_failed_action], ReqOpts0),
|
||||||
|
@ -291,6 +296,12 @@ put_request_failed_action(Val) ->
|
||||||
get_request_failed_action() ->
|
get_request_failed_action() ->
|
||||||
persistent_term:get({?APP, request_failed_action}).
|
persistent_term:get({?APP, request_failed_action}).
|
||||||
|
|
||||||
|
put_pool_size(Val) ->
|
||||||
|
persistent_term:put({?APP, pool_size}, Val).
|
||||||
|
|
||||||
|
get_pool_size() ->
|
||||||
|
persistent_term:get({?APP, pool_size}).
|
||||||
|
|
||||||
save(Name, ServerState) ->
|
save(Name, ServerState) ->
|
||||||
Saved = persistent_term:get(?APP, []),
|
Saved = persistent_term:get(?APP, []),
|
||||||
persistent_term:put(?APP, lists:reverse([Name | Saved])),
|
persistent_term:put(?APP, lists:reverse([Name | Saved])),
|
||||||
|
|
|
@ -108,9 +108,10 @@ load(Name, Opts0, ReqOpts) ->
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
channel_opts(Opts = #{url := URL}) ->
|
channel_opts(Opts = #{url := URL}) ->
|
||||||
|
ClientOpts = #{pool_size => emqx_exhook_mngr:get_pool_size()},
|
||||||
case uri_string:parse(URL) of
|
case uri_string:parse(URL) of
|
||||||
#{scheme := "http", host := Host, port := Port} ->
|
#{scheme := "http", host := Host, port := Port} ->
|
||||||
{format_http_uri("http", Host, Port), #{}};
|
{format_http_uri("http", Host, Port), ClientOpts};
|
||||||
#{scheme := "https", host := Host, port := Port} ->
|
#{scheme := "https", host := Host, port := Port} ->
|
||||||
SslOpts =
|
SslOpts =
|
||||||
case maps:get(ssl, Opts, undefined) of
|
case maps:get(ssl, Opts, undefined) of
|
||||||
|
@ -122,8 +123,12 @@ channel_opts(Opts = #{url := URL}) ->
|
||||||
{keyfile, maps:get(keyfile, MapOpts, undefined)}
|
{keyfile, maps:get(keyfile, MapOpts, undefined)}
|
||||||
])
|
])
|
||||||
end,
|
end,
|
||||||
{format_http_uri("https", Host, Port),
|
NClientOpts = ClientOpts#{
|
||||||
#{gun_opts => #{transport => ssl, transport_opts => SslOpts}}};
|
gun_opts =>
|
||||||
|
#{transport => ssl,
|
||||||
|
transport_opts => SslOpts}
|
||||||
|
},
|
||||||
|
{format_http_uri("https", Host, Port), NClientOpts};
|
||||||
_ ->
|
_ ->
|
||||||
error(bad_server_url)
|
error(bad_server_url)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -54,7 +54,8 @@ auto_reconnect() ->
|
||||||
|
|
||||||
request_options() ->
|
request_options() ->
|
||||||
#{timeout => env(request_timeout, 5000),
|
#{timeout => env(request_timeout, 5000),
|
||||||
request_failed_action => env(request_failed_action, deny)
|
request_failed_action => env(request_failed_action, deny),
|
||||||
|
pool_size => env(pool_size, erlang:system_info(schedulers))
|
||||||
}.
|
}.
|
||||||
|
|
||||||
env(Key, Def) ->
|
env(Key, Def) ->
|
||||||
|
@ -67,7 +68,7 @@ env(Key, Def) ->
|
||||||
-spec start_grpc_client_channel(
|
-spec start_grpc_client_channel(
|
||||||
binary(),
|
binary(),
|
||||||
uri_string:uri_string(),
|
uri_string:uri_string(),
|
||||||
grpc_client:options()) -> {ok, pid()} | {error, term()}.
|
grpc_client_sup:options()) -> {ok, pid()} | {error, term()}.
|
||||||
start_grpc_client_channel(Name, SvrAddr, Options) ->
|
start_grpc_client_channel(Name, SvrAddr, Options) ->
|
||||||
grpc_client_sup:create_channel_pool(Name, SvrAddr, Options).
|
grpc_client_sup:create_channel_pool(Name, SvrAddr, Options).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue