From fbac9ce43efee16b746f2e99ee8f501e996437be Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Sat, 22 Sep 2018 05:42:38 +0800 Subject: [PATCH 1/2] Improve the foce_gc_policy config. --- etc/emqx.conf | 6 ++++++ priv/emqx.schema | 11 ++++++++--- src/emqx_gc.erl | 2 -- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/etc/emqx.conf b/etc/emqx.conf index 3604f2efd..635ccf68c 100644 --- a/etc/emqx.conf +++ b/etc/emqx.conf @@ -544,6 +544,12 @@ zone.external.enable_acl = on ## Value: on | off zone.external.enable_stats = on +## Force MQTT connection/session process GC after this number of +## messages | bytes passed through. +## +## Numbers delimited by `|'. Zero or negative is to disable. +zone.external.force_gc_policy = 1000|1MB + ## Maximum MQTT packet size allowed. ## ## Value: Bytes diff --git a/priv/emqx.schema b/priv/emqx.schema index 9fcd97376..47ad97293 100644 --- a/priv/emqx.schema +++ b/priv/emqx.schema @@ -828,7 +828,7 @@ end}. %% messages | bytes passed through. %% Numbers delimited by `|'. Zero or negative is to disable. {mapping, "zone.$name.force_gc_policy", "emqx.zones", [ - {default, "0|0"}, + {default, "0|0KB"}, {datatype, string} ]}. @@ -841,8 +841,13 @@ end}. {mqtt_shared_subscription, Val}; ("force_gc_policy", Val) -> [Count, Bytes] = string:tokens(Val, "| "), - {force_gc_policy, #{count => list_to_integer(Count), - bytes => list_to_integer(Bytes)}}; + GcPolicy = case cuttlefish_bytesize:parse(Bytes) of + {error, Reason} -> + error(Reason); + Bytes1 -> + #{bytes => Bytes1, count => list_to_integer(Count)} + end, + {force_gc_policy, GcPolicy}; (Opt, Val) -> {list_to_atom(Opt), Val} end, diff --git a/src/emqx_gc.erl b/src/emqx_gc.erl index 65bbccad1..7e98eb37a 100644 --- a/src/emqx_gc.erl +++ b/src/emqx_gc.erl @@ -21,8 +21,6 @@ -module(emqx_gc). --author("Feng Lee "). - -export([init/1, inc/2, reset/0]). -type st() :: #{ cnt => {integer(), integer()} From 3dfe4168cb264550e1da9fecc9e763982f0c7f37 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Sat, 22 Sep 2018 06:24:41 +0800 Subject: [PATCH 2/2] Change '0KB' to '0MB' --- priv/emqx.schema | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/emqx.schema b/priv/emqx.schema index 7ad20ea15..c68903803 100644 --- a/priv/emqx.schema +++ b/priv/emqx.schema @@ -828,7 +828,7 @@ end}. %% messages | bytes passed through. %% Numbers delimited by `|'. Zero or negative is to disable. {mapping, "zone.$name.force_gc_policy", "emqx.zones", [ - {default, "0|0KB"}, + {default, "0 | 0MB"}, {datatype, string} ]}.