Breaking change of listener's rate_limit config

This commit is contained in:
Feng Lee 2019-10-18 18:52:57 +08:00
parent a09b87fc94
commit a0e72fd040
2 changed files with 40 additions and 45 deletions

View File

@ -562,8 +562,8 @@ zone.external.hibernate_after = 60s
## Publish limit for the external MQTT connections. ## Publish limit for the external MQTT connections.
## ##
## Value: Number,Duration ## Value: Number,Duration
## Example: 10 messages per minute. ## Example: 100 messages per 10 seconds.
## zone.external.publish_limit = 10,1m ## zone.external.publish_limit = 100,10s
## Enable ACL check. ## Enable ACL check.
## ##
@ -874,14 +874,11 @@ listener.tcp.external.active_n = 100
## Value: String ## Value: String
listener.tcp.external.zone = external listener.tcp.external.zone = external
## Rate limit for the external MQTT/TCP connections. Format is 'rate,burst'. ## Rate limit for the external MQTT/TCP connections. Format is 'limit,duration'.
## ##
## Value: rate,burst ## Value: limit,duration
## - rate: The average limit value for per second ## Default: 100KB incoming per 10 seconds.
## - burst: The maximum allowed for each check, To avoid frequent restriction ## listener.tcp.external.rate_limit = 100KB,10s
## this value is recommended to be set to `(max_packet_size * active_n)/2`
## Unit: Bps
## listener.tcp.external.rate_limit = 1024,52428800
## The access control rules for the MQTT/TCP listener. ## The access control rules for the MQTT/TCP listener.
## ##
@ -1010,12 +1007,9 @@ listener.tcp.internal.zone = internal
## ##
## See: listener.tcp.$name.rate_limit ## See: listener.tcp.$name.rate_limit
## ##
## Value: rate,burst ## Value: limit,duration
## - rate: The average limit value for per second ## Default: 1MB incoming per second.
## - burst: The maximum allowed for each check, To avoid frequent restriction ## listener.tcp.internal.rate_limit = 1MB,1s
## this value is recommended to be set to `(max_packet_size * active_n)/2`
## Unit: Bps
## listener.tcp.internal.rate_limit = 1000000,524288000
## The TCP backlog of internal MQTT/TCP Listener. ## The TCP backlog of internal MQTT/TCP Listener.
## ##
@ -1123,12 +1117,9 @@ listener.ssl.external.access.1 = allow all
## Rate limit for the external MQTT/SSL connections. ## Rate limit for the external MQTT/SSL connections.
## ##
## Value: rate,burst ## Value: limit,duration
## - rate: The average limit value for per second ## Default: 100KB incoming per 10 seconds.
## - burst: The maximum allowed for each check, To avoid frequent restriction ## listener.ssl.external.rate_limit = 100KB,10s
## this value is recommended to be set to `(max_packet_size * active_n)/2`
## Unit: Bps
## listener.ssl.external.rate_limit = 1024,52428800
## Enable the Proxy Protocol V1/2 if the EMQ cluster is deployed behind ## Enable the Proxy Protocol V1/2 if the EMQ cluster is deployed behind
## HAProxy or Nginx. ## HAProxy or Nginx.
@ -1360,12 +1351,9 @@ listener.ws.external.max_conn_rate = 1000
## Rate limit for the MQTT/WebSocket connections. ## Rate limit for the MQTT/WebSocket connections.
## ##
## Value: rate,burst ## Value: limit,duration
## - rate: The average limit value for per second ## Default: 100KB incoming per 10 seconds.
## - burst: The maximum allowed for each check, To avoid frequent restriction ## listener.ws.external.rate_limit = 100KB,10s
## this value is recommended to be set to `(max_packet_size * 1)/2`
## Unit: Bps
## listener.ws.external.rate_limit = 1024,524288
## Zone of the external MQTT/WebSocket listener belonged to. ## Zone of the external MQTT/WebSocket listener belonged to.
## ##
@ -1571,12 +1559,9 @@ listener.wss.external.max_conn_rate = 1000
## Rate limit for the MQTT/WebSocket/SSL connections. ## Rate limit for the MQTT/WebSocket/SSL connections.
## ##
## Value: rate,burst ## Value: limit,duration
## - rate: The average limit value for per second ## Default: 100KB incoming per 10 seconds.
## - burst: The maximum allowed for each check, To avoid frequent restriction ## listener.wss.external.rate_limit = 100KB,10s
## this value is recommended to be set to `(max_packet_size * 1)/2`
## Unit: Bps
## listener.wss.external.rate_limit = 1024,524288
## Zone of the external MQTT/WebSocket/SSL listener belonged to. ## Zone of the external MQTT/WebSocket/SSL listener belonged to.
## ##

View File

@ -939,14 +939,14 @@ end}.
("shared_subscription", Val) -> ("shared_subscription", Val) ->
{shared_subscription, Val}; {shared_subscription, Val};
("publish_limit", Val) -> ("publish_limit", Val) ->
[Limit, Duration] = string:tokens(Val, ", "), [L, D] = string:tokens(Val, ", "),
PubLimit = case cuttlefish_duration:parse(Duration, s) of Limit = list_to_integer(L),
Secs when is_integer(Secs) -> Duration = case cuttlefish_duration:parse(D, s) of
{list_to_integer(Limit) / Secs, list_to_integer(Limit)}; Secs when is_integer(Secs) -> Secs;
{error, Reason} -> {error, Reason} -> error(Reason)
error(Reason)
end, end,
{publish_limit, PubLimit}; Rate = Limit / Duration,
{publish_limit, {Rate, Limit}};
("force_gc_policy", Val) -> ("force_gc_policy", Val) ->
[Count, Bytes] = string:tokens(Val, "| "), [Count, Bytes] = string:tokens(Val, "| "),
GcPolicy = case cuttlefish_bytesize:parse(Bytes) of GcPolicy = case cuttlefish_bytesize:parse(Bytes) of
@ -1644,10 +1644,20 @@ end}.
end end
end, end,
Ratelimit = fun(undefined) -> RateLimit = fun(undefined) ->
undefined; undefined;
(S) -> (Val) ->
list_to_tuple([list_to_integer(Token) || Token <- string:tokens(S, ",")]) [L, D] = string:tokens(Val, ", "),
Limit = case cuttlefish_bytesize:parse(L) of
Sz when is_integer(Sz) -> Sz;
{error, Reason} -> error(Reason)
end,
Duration = case cuttlefish_duration:parse(D, s) of
Secs when is_integer(Secs) -> Secs;
{error, Reason1} -> error(Reason1)
end,
Rate = Limit / Duration,
{Rate, Limit}
end, end,
LisOpts = fun(Prefix) -> LisOpts = fun(Prefix) ->
@ -1658,7 +1668,7 @@ end}.
{active_n, cuttlefish:conf_get(Prefix ++ ".active_n", Conf, undefined)}, {active_n, cuttlefish:conf_get(Prefix ++ ".active_n", Conf, undefined)},
{tune_buffer, cuttlefish:conf_get(Prefix ++ ".tune_buffer", Conf, undefined)}, {tune_buffer, cuttlefish:conf_get(Prefix ++ ".tune_buffer", Conf, undefined)},
{zone, Atom(cuttlefish:conf_get(Prefix ++ ".zone", Conf, undefined))}, {zone, Atom(cuttlefish:conf_get(Prefix ++ ".zone", Conf, undefined))},
{rate_limit, Ratelimit(cuttlefish:conf_get(Prefix ++ ".rate_limit", Conf, undefined))}, {rate_limit, RateLimit(cuttlefish:conf_get(Prefix ++ ".rate_limit", Conf, undefined))},
{proxy_protocol, cuttlefish:conf_get(Prefix ++ ".proxy_protocol", Conf, undefined)}, {proxy_protocol, cuttlefish:conf_get(Prefix ++ ".proxy_protocol", Conf, undefined)},
{proxy_protocol_timeout, cuttlefish:conf_get(Prefix ++ ".proxy_protocol_timeout", Conf, undefined)}, {proxy_protocol_timeout, cuttlefish:conf_get(Prefix ++ ".proxy_protocol_timeout", Conf, undefined)},
{verify_protocol_header, cuttlefish:conf_get(Prefix ++ ".verify_protocol_header", Conf, undefined)}, {verify_protocol_header, cuttlefish:conf_get(Prefix ++ ".verify_protocol_header", Conf, undefined)},