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