Merge pull request #10525 from qzhuyan/perf/william/avoid-new-map-when-get-mqtt-caps
perf(config): avoid build new map in emqx_mgmt_caps:get_caps
This commit is contained in:
commit
e4f501417b
|
@ -20,8 +20,8 @@ esac
|
|||
|
||||
{
|
||||
echo "HOCON_ENV_OVERRIDE_PREFIX=EMQX_"
|
||||
echo "EMQX_ZONES__DEFAULT__MQTT__RETRY_INTERVAL=2s"
|
||||
echo "EMQX_ZONES__DEFAULT__MQTT__MAX_TOPIC_ALIAS=10"
|
||||
echo "EMQX_MQTT__RETRY_INTERVAL=2s"
|
||||
echo "EMQX_MQTT__MAX_TOPIC_ALIAS=10"
|
||||
echo "EMQX_AUTHORIZATION__SOURCES=[]"
|
||||
echo "EMQX_AUTHORIZATION__NO_MATCH=allow"
|
||||
} >> .ci/docker-compose-file/conf.cluster.env
|
||||
|
|
|
@ -167,8 +167,8 @@ jobs:
|
|||
--set image.pullPolicy=Never \
|
||||
--set image.tag=$EMQX_TAG \
|
||||
--set emqxAclConfig="" \
|
||||
--set emqxConfig.EMQX_ZONES__DEFAULT__MQTT__RETRY_INTERVAL=2s \
|
||||
--set emqxConfig.EMQX_ZONES__DEFAULT__MQTT__MAX_TOPIC_ALIAS=10 \
|
||||
--set emqxConfig.EMQX_MQTT__RETRY_INTERVAL=2s \
|
||||
--set emqxConfig.EMQX_MQTT__MAX_TOPIC_ALIAS=10 \
|
||||
--set emqxConfig.EMQX_AUTHORIZATION__SOURCES=[] \
|
||||
--set emqxConfig.EMQX_AUTHORIZATION__NO_MATCH=allow \
|
||||
deploy/charts/${{ matrix.profile }} \
|
||||
|
@ -185,8 +185,8 @@ jobs:
|
|||
--set image.pullPolicy=Never \
|
||||
--set image.tag=$EMQX_TAG \
|
||||
--set emqxAclConfig="" \
|
||||
--set emqxConfig.EMQX_ZONES__DEFAULT__MQTT__RETRY_INTERVAL=2s \
|
||||
--set emqxConfig.EMQX_ZONES__DEFAULT__MQTT__MAX_TOPIC_ALIAS=10 \
|
||||
--set emqxConfig.EMQX_MQTT__RETRY_INTERVAL=2s \
|
||||
--set emqxConfig.EMQX_MQTT__MAX_TOPIC_ALIAS=10 \
|
||||
--set emqxConfig.EMQX_AUTHORIZATION__SOURCES=[] \
|
||||
--set emqxConfig.EMQX_AUTHORIZATION__NO_MATCH=allow \
|
||||
deploy/charts/${{ matrix.profile }} \
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
max_qos_allowed => emqx_types:qos(),
|
||||
retain_available => boolean(),
|
||||
wildcard_subscription => boolean(),
|
||||
subscription_identifiers => boolean(),
|
||||
shared_subscription => boolean(),
|
||||
exclusive_subscription => boolean()
|
||||
}.
|
||||
|
@ -58,18 +57,17 @@
|
|||
exclusive_subscription
|
||||
]).
|
||||
|
||||
-define(DEFAULT_CAPS, #{
|
||||
max_packet_size => ?MAX_PACKET_SIZE,
|
||||
max_clientid_len => ?MAX_CLIENTID_LEN,
|
||||
max_topic_alias => ?MAX_TOPIC_AlIAS,
|
||||
max_topic_levels => ?MAX_TOPIC_LEVELS,
|
||||
max_qos_allowed => ?QOS_2,
|
||||
retain_available => true,
|
||||
wildcard_subscription => true,
|
||||
subscription_identifiers => true,
|
||||
shared_subscription => true,
|
||||
exclusive_subscription => false
|
||||
}).
|
||||
-define(DEFAULT_CAPS_KEYS, [
|
||||
max_packet_size,
|
||||
max_clientid_len,
|
||||
max_topic_alias,
|
||||
max_topic_levels,
|
||||
max_qos_allowed,
|
||||
retain_available,
|
||||
wildcard_subscription,
|
||||
shared_subscription,
|
||||
exclusive_subscription
|
||||
]).
|
||||
|
||||
-spec check_pub(
|
||||
emqx_types:zone(),
|
||||
|
@ -88,7 +86,7 @@ check_pub(Zone, Flags) when is_map(Flags) ->
|
|||
error ->
|
||||
Flags
|
||||
end,
|
||||
maps:with(?PUBCAP_KEYS, get_caps(Zone))
|
||||
get_caps(?PUBCAP_KEYS, Zone)
|
||||
).
|
||||
|
||||
do_check_pub(#{topic_levels := Levels}, #{max_topic_levels := Limit}) when
|
||||
|
@ -111,7 +109,7 @@ do_check_pub(_Flags, _Caps) ->
|
|||
) ->
|
||||
ok_or_error(emqx_types:reason_code()).
|
||||
check_sub(ClientInfo = #{zone := Zone}, Topic, SubOpts) ->
|
||||
Caps = maps:with(?SUBCAP_KEYS, get_caps(Zone)),
|
||||
Caps = get_caps(?SUBCAP_KEYS, Zone),
|
||||
Flags = lists:foldl(
|
||||
fun
|
||||
(max_topic_levels, Map) ->
|
||||
|
@ -152,10 +150,12 @@ do_check_sub(_Flags, _Caps, _, _) ->
|
|||
ok.
|
||||
|
||||
get_caps(Zone) ->
|
||||
lists:foldl(
|
||||
fun({K, V}, Acc) ->
|
||||
Acc#{K => emqx_config:get_zone_conf(Zone, [mqtt, K], V)}
|
||||
end,
|
||||
#{},
|
||||
maps:to_list(?DEFAULT_CAPS)
|
||||
get_caps(?DEFAULT_CAPS_KEYS, Zone).
|
||||
get_caps(Keys, Zone) ->
|
||||
maps:with(
|
||||
Keys,
|
||||
maps:merge(
|
||||
emqx_config:get([mqtt]),
|
||||
emqx_config:get_zone_conf(Zone, [mqtt])
|
||||
)
|
||||
).
|
||||
|
|
|
@ -267,13 +267,14 @@ t_chan_info(_) ->
|
|||
t_chan_caps(_) ->
|
||||
?assertMatch(
|
||||
#{
|
||||
exclusive_subscription := false,
|
||||
max_packet_size := 1048576,
|
||||
max_clientid_len := 65535,
|
||||
max_qos_allowed := 2,
|
||||
max_topic_alias := 65535,
|
||||
max_topic_levels := Level,
|
||||
retain_available := true,
|
||||
shared_subscription := true,
|
||||
subscription_identifiers := true,
|
||||
wildcard_subscription := true
|
||||
} when is_integer(Level),
|
||||
emqx_channel:caps(channel())
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Reduce resource usage per MQTT packet handling.
|
||||
|
Loading…
Reference in New Issue