summaryrefslogtreecommitdiff
path: root/p11p-daemon/src
diff options
context:
space:
mode:
authorLinus Nordberg <linus@sunet.se>2020-02-14 12:18:31 +0100
committerLinus Nordberg <linus@sunet.se>2020-02-14 12:18:31 +0100
commit089ae7c716352ba6690aa701deee8f5aeaa06655 (patch)
tree55e758f0413dbac48afcb0035477349e4f7197ac /p11p-daemon/src
parent920995ca6e2ef7c4993b0196c2556409eade04d1 (diff)
better balance settings
Diffstat (limited to 'p11p-daemon/src')
-rw-r--r--p11p-daemon/src/p11p_client.erl11
-rw-r--r--p11p-daemon/src/p11p_config.erl20
-rw-r--r--p11p-daemon/src/p11p_manager.erl6
3 files changed, 16 insertions, 21 deletions
diff --git a/p11p-daemon/src/p11p_client.erl b/p11p-daemon/src/p11p_client.erl
index fd101c5..5fd3ff1 100644
--- a/p11p-daemon/src/p11p_client.erl
+++ b/p11p-daemon/src/p11p_client.erl
@@ -115,10 +115,6 @@ handle_call({request, Request},
pass
end
of
- ack ->
- {reply, ack, State};
- nack ->
- {reply, nack, State};
pass ->
lager:debug("~p: sending request from ~p to prxoy app ~p", [self(), FromPid, Port]),
D = p11p_rpc:serialise(Request),
@@ -126,13 +122,14 @@ handle_call({request, Request},
0 -> <<?RPC_VERSION:8, D/binary>>;
_ -> D
end,
- {ok, _} = do_send(Port, Buf),
-
+ {ok, _} = send_request(Port, Buf),
{reply,
{ok, size(Buf)},
State#state{replyto = FromPid,
timer = start_timer(State#state.timeout, Port),
- send_count = Sent + 1}}
+ send_count = Sent + 1}};
+ Ret ->
+ {reply, Ret, State}
end;
handle_call(Call, _From, State) ->
diff --git a/p11p-daemon/src/p11p_config.erl b/p11p-daemon/src/p11p_config.erl
index c4bfbcd..13723ce 100644
--- a/p11p-daemon/src/p11p_config.erl
+++ b/p11p-daemon/src/p11p_config.erl
@@ -31,7 +31,7 @@
name :: string(),
timeout :: non_neg_integer(),
failover :: non_neg_integer(), % How many failover attempts.
- balance :: [non_neg_integer()],
+ balance :: [integer()],
modules = #{} :: #{string() => p11module()}
}).
-type token() :: #token{}.
@@ -177,15 +177,16 @@ new_token({Name, Settings}) ->
name = Name,
timeout = proplists:get_value(timeout, Settings, 25000),
failover = proplists:get_value(failover, Settings, maps:size(Modules) - 1),
- balance = balance(proplists:get_value(balance, Settings, []),
- maps:size(Modules)),
+ balance = lists:map(fun(N) -> case N of 0 -> -1; _ -> N end end,
+ balance(proplists:get_value(balance, Settings, []),
+ maps:size(Modules))),
modules = Modules
}.
-balance([], _) ->
- [];
+balance([], NModules) ->
+ balance([0], NModules - 1);
balance(List, NModules) ->
- List ++ [1 || _ <- lists:seq(1, NModules - length(List))].
+ List ++ [0 || _ <- lists:seq(1, NModules - length(List))].
conf_modules(L) ->
conf_modules(L, #{}).
@@ -230,7 +231,7 @@ tokens_init_test_() ->
{token,"vtoken0",
25000,
1,
- [3,1],
+ [3,-1],
#{"bogusmod0_0" =>
{p11module,"bogusmod0_0", "/path/to/bogusmod0_0", []},
"bogusmod0_1" =>
@@ -239,13 +240,10 @@ tokens_init_test_() ->
{token,"vtoken1",
12000,
3,
- [],
+ [-1],
#{"bogusmod1_0" =>
{p11module,"bogusmod1_0", "/path/to/bogusmod1_0", []},
"bogusmod1_1" =>
{p11module,"bogusmod1_1", "/path/to/bogusmod1_1", [{"MYENV", "myenv"}]}}}
},
Conf)] end}.
-%% modules_for_token_test_() ->
-%% {setup,
-%% fun() ->
diff --git a/p11p-daemon/src/p11p_manager.erl b/p11p-daemon/src/p11p_manager.erl
index 209d08e..6f9e977 100644
--- a/p11p-daemon/src/p11p_manager.erl
+++ b/p11p-daemon/src/p11p_manager.erl
@@ -85,6 +85,8 @@ handle_call({client_for_token, Server, TokNameIn}, _From,
lager:debug("all clients: ~p", [ClientsIn]),
{Clients, BalanceCount} =
case VTokenIn#vtoken.balance_count of
+ -1 ->
+ {ClientsIn, -1};
0 ->
lager:debug("~p: balancing: next client", [self()]),
Rotated = rotate_clients(ClientsIn),
@@ -92,9 +94,7 @@ handle_call({client_for_token, Server, TokNameIn}, _From,
{Rotated, First#client.balance - 1};
N when N > 0 ->
lager:debug("~p: balancing: ~B more invocations", [self(), N]),
- {ClientsIn, N - 1};
- -1 ->
- {ClientsIn, -1}
+ {ClientsIn, N - 1}
end,
Current = hd(Clients),
case Current#client.pid of