Merge pull request #9954 from zmstone/0210-perf-do-not-make-gen_server-call-after-each-resource-ets-lookup
perf: avoid getting metrics (gen_server:call) for each resource lookup
This commit is contained in:
commit
910731c075
|
@ -46,7 +46,7 @@ emqx_bridge_api {
|
||||||
|
|
||||||
desc_param_path_enable {
|
desc_param_path_enable {
|
||||||
desc {
|
desc {
|
||||||
en: """Whether or not the bridge is enabled"""
|
en: """Whether to enable this bridge"""
|
||||||
zh: """是否启用桥接"""
|
zh: """是否启用桥接"""
|
||||||
}
|
}
|
||||||
label: {
|
label: {
|
||||||
|
|
|
@ -159,7 +159,7 @@ broker MUST support this feature."""
|
||||||
|
|
||||||
clean_start {
|
clean_start {
|
||||||
desc {
|
desc {
|
||||||
en: "Whether or not to start a clean session when reconnecting a remote broker for ingress bridge"
|
en: "Whether to start a clean session when reconnecting a remote broker for ingress bridge"
|
||||||
zh: "与 ingress MQTT 桥的远程服务器重连时是否清除老的 MQTT 会话。"
|
zh: "与 ingress MQTT 桥的远程服务器重连时是否清除老的 MQTT 会话。"
|
||||||
}
|
}
|
||||||
label: {
|
label: {
|
||||||
|
|
|
@ -57,7 +57,7 @@ It's enum with `stomp`, `mqttsn`, `coap`, `lwm2m`, `exproto`"""
|
||||||
|
|
||||||
gateway_enable_in_path {
|
gateway_enable_in_path {
|
||||||
desc {
|
desc {
|
||||||
en: """Whether or not gateway is enabled"""
|
en: """Whether to enable this gateway"""
|
||||||
|
|
||||||
zh: """是否开启此网关"""
|
zh: """是否开启此网关"""
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
config := resource_config(),
|
config := resource_config(),
|
||||||
state := resource_state(),
|
state := resource_state(),
|
||||||
status := resource_status(),
|
status := resource_status(),
|
||||||
metrics := emqx_metrics_worker:metrics()
|
metrics => emqx_metrics_worker:metrics()
|
||||||
}.
|
}.
|
||||||
-type resource_group() :: binary().
|
-type resource_group() :: binary().
|
||||||
-type creation_opts() :: #{
|
-type creation_opts() :: #{
|
||||||
|
|
|
@ -238,7 +238,7 @@ lookup(ResId) ->
|
||||||
ets_lookup(ResId) ->
|
ets_lookup(ResId) ->
|
||||||
case read_cache(ResId) of
|
case read_cache(ResId) of
|
||||||
{Group, Data} ->
|
{Group, Data} ->
|
||||||
{ok, Group, data_record_to_external_map_with_metrics(Data)};
|
{ok, Group, data_record_to_external_map(Data)};
|
||||||
not_found ->
|
not_found ->
|
||||||
{error, not_found}
|
{error, not_found}
|
||||||
end.
|
end.
|
||||||
|
@ -620,8 +620,8 @@ maybe_reply(Actions, undefined, _Reply) ->
|
||||||
maybe_reply(Actions, From, Reply) ->
|
maybe_reply(Actions, From, Reply) ->
|
||||||
[{reply, From, Reply} | Actions].
|
[{reply, From, Reply} | Actions].
|
||||||
|
|
||||||
-spec data_record_to_external_map_with_metrics(data()) -> resource_data().
|
-spec data_record_to_external_map(data()) -> resource_data().
|
||||||
data_record_to_external_map_with_metrics(Data) ->
|
data_record_to_external_map(Data) ->
|
||||||
#{
|
#{
|
||||||
id => Data#data.id,
|
id => Data#data.id,
|
||||||
mod => Data#data.mod,
|
mod => Data#data.mod,
|
||||||
|
@ -629,10 +629,14 @@ data_record_to_external_map_with_metrics(Data) ->
|
||||||
query_mode => Data#data.query_mode,
|
query_mode => Data#data.query_mode,
|
||||||
config => Data#data.config,
|
config => Data#data.config,
|
||||||
status => Data#data.status,
|
status => Data#data.status,
|
||||||
state => Data#data.state,
|
state => Data#data.state
|
||||||
metrics => get_metrics(Data#data.id)
|
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
-spec data_record_to_external_map_with_metrics(data()) -> resource_data().
|
||||||
|
data_record_to_external_map_with_metrics(Data) ->
|
||||||
|
DataMap = data_record_to_external_map(Data),
|
||||||
|
DataMap#{metrics => get_metrics(Data#data.id)}.
|
||||||
|
|
||||||
-spec wait_for_ready(resource_id(), integer()) -> ok | timeout | {error, term()}.
|
-spec wait_for_ready(resource_id(), integer()) -> ok | timeout | {error, term()}.
|
||||||
wait_for_ready(ResId, WaitTime) ->
|
wait_for_ready(ResId, WaitTime) ->
|
||||||
do_wait_for_ready(ResId, WaitTime div ?WAIT_FOR_RESOURCE_DELAY).
|
do_wait_for_ready(ResId, WaitTime div ?WAIT_FOR_RESOURCE_DELAY).
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Improve bridge performance
|
|
@ -0,0 +1 @@
|
||||||
|
优化桥接性能
|
|
@ -26,8 +26,8 @@ item() {
|
||||||
}
|
}
|
||||||
|
|
||||||
section() {
|
section() {
|
||||||
local section_name=$1
|
local prefix=$1
|
||||||
for i in "${changes_dir}"/"${section_name}"-*."${language}".md; do
|
for i in "${changes_dir}"/"${prefix}"-*."${language}".md; do
|
||||||
item "${i}"
|
item "${i}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ if [ "${language}" = "en" ]; then
|
||||||
## Enhancements
|
## Enhancements
|
||||||
|
|
||||||
$(section feat)
|
$(section feat)
|
||||||
|
$(section perf)
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue