feat(exhook): expose process pool_size for grpc client
This commit is contained in:
parent
b756e7d17a
commit
c170d076e3
|
@ -24,6 +24,11 @@
|
||||||
## Value: false | Duration
|
## Value: false | Duration
|
||||||
#exhook.auto_reconnect = 60s
|
#exhook.auto_reconnect = 60s
|
||||||
|
|
||||||
|
## The process pool size for gRPC client
|
||||||
|
##
|
||||||
|
## Default: Equals cpu cores
|
||||||
|
## Value: Integer
|
||||||
|
#exhook.pool_size = 16
|
||||||
|
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
## The Hook callback servers
|
## The Hook callback servers
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
end
|
end
|
||||||
end}.
|
end}.
|
||||||
|
|
||||||
|
{mapping, "exhook.pool_size", "emqx_exhook.pool_size", [
|
||||||
|
{datatype, integer}
|
||||||
|
]}.
|
||||||
|
|
||||||
{mapping, "exhook.server.$name.url", "emqx_exhook.servers", [
|
{mapping, "exhook.server.$name.url", "emqx_exhook.servers", [
|
||||||
{datatype, string}
|
{datatype, string}
|
||||||
]}.
|
]}.
|
||||||
|
|
|
@ -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),
|
||||||
|
@ -286,6 +291,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])),
|
||||||
|
|
|
@ -131,7 +131,8 @@ channel_opts(Opts) ->
|
||||||
transport_opts => SslOpts}};
|
transport_opts => SslOpts}};
|
||||||
_ -> #{}
|
_ -> #{}
|
||||||
end,
|
end,
|
||||||
{SvrAddr, ClientOpts}.
|
NClientOpts = ClientOpts#{pool_size => emqx_exhook_mngr:get_pool_size()},
|
||||||
|
{SvrAddr, NClientOpts}.
|
||||||
|
|
||||||
format_http_uri(Scheme, Host0, Port) ->
|
format_http_uri(Scheme, Host0, Port) ->
|
||||||
Host = case is_tuple(Host0) of
|
Host = case is_tuple(Host0) of
|
||||||
|
|
|
@ -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(
|
||||||
string(),
|
string(),
|
||||||
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