Increased default buffer size for senders and added an option for it.
authorStanislaw Klekot <dozzie@jarowit.net>
Sat, 4 Mar 2017 21:44:08 +0000 (22:44 +0100)
committerStanislaw Klekot <dozzie@jarowit.net>
Sat, 4 Mar 2017 21:44:08 +0000 (22:44 +0100)
examples/statetip.toml
src/statip.app.src
src/statip_cli_handler.erl
src/statip_sender_client.erl

index d322f2a..7741255 100644 (file)
@@ -7,6 +7,8 @@
 #listen = ["*:3012"]
 # default expiry time (seconds) for incoming events
 #default_expiry = 43200
+# size of TCP buffer, which sets the maximum size of a single message
+#buffer_size = 16384
 
 [readers]
 # where to expose state to be read using HTTP API
index 76d56d2..6b566c9 100644 (file)
@@ -20,6 +20,7 @@
     %{configure, mfa()},
     {senders, [{"localhost", 3012}]},
     {readers, [{"localhost", 3082}]},
+    {senders_tcp_buffer_size, 16384}, % 16kB
     %{state_dir, "/var/lib/statetip"},
     {compaction_size, 10485760}, % 10MB, about 1 hour at 2.5kB/s
     {log_handlers, []}, % for statip_log; list of `{Module :: atom(), Args :: term()}'
index 7ff9797..77c7baa 100644 (file)
@@ -534,6 +534,7 @@ setup_applications(Config, Options) ->
 configure_statip(GlobalConfig, _Options) ->
   SetSpecs = [
     {[<<"senders">>, <<"listen">>], {statip, senders}},
+    {[<<"senders">>, <<"buffer_size">>], {statip, senders_tcp_buffer_size}},
     {[<<"readers">>, <<"listen">>], {statip, readers}},
     {[<<"state_log">>, <<"directory">>], {statip, state_dir}},
     {[<<"state_log">>, <<"compaction_size">>], {statip, compaction_size}},
@@ -569,6 +570,9 @@ config_check([_Section, <<"listen">>] = _Key, _EnvKey, Values) ->
   catch
     error:_ -> {error, invalid_value}
   end;
+config_check([<<"senders">>, <<"buffer_size">>] = _Key, _EnvKey, Size)
+when is_integer(Size), Size > 0 ->
+  ok;
 config_check([<<"state_log">>, <<"directory">>] = _Key, _EnvKey, Value)
 when is_binary(Value) ->
   ok;
index babc5e0..bc4a8b1 100644 (file)
   ok.
 
 take_over(Socket) ->
+  {ok, BufferSize} = application:get_env(statip, senders_tcp_buffer_size),
   {ok, Pid} = statip_sender_client_sup:spawn_worker(Socket),
   ok = gen_tcp:controlling_process(Socket, Pid),
-  ok = inet:setopts(Socket, [binary, {packet, line}, {active, once}]),
+  ok = inet:setopts(Socket, [
+    binary, {packet, line}, {buffer, BufferSize}, {active, once}
+  ]),
   ok.
 
 %%%---------------------------------------------------------------------------