nic-6443 commented on code in PR #12604: URL: https://github.com/apache/apisix/pull/12604#discussion_r2339439485
########## apisix/admin/standalone.lua: ########## @@ -420,6 +430,29 @@ function _M.init_worker() end events:register(update_config, EVENT_UPDATE, EVENT_UPDATE) + -- due to the event module can not broadcast events between http and stream subsystems, + -- we need to poll the shared dict to keep the config in sync + local last_sync_time = ngx_time() + local function sync_config() + local now = ngx_time() + if now - last_sync_time < 1 then + return + end + + local config, err = get_config() + if not config then + if err ~= NOT_FOUND_ERR then + core.log.error("failed to get config: ", err) + end + else + if config[METADATA_LAST_MODIFIED] > last_sync_time then + update_config(config) + end + end + last_sync_time = now Review Comment: > I thought maybe we could just store METADATA_LAST_MODIFIED in this local variable. Then use the rule whether the shdict stored config is higher than the local timestamp to check if the config should be sync again. However, if we remove `last_sync_time`, we will not be able to control this timer to run once per second. This means that apisix will loop through the execution of the two functions `shareddict:get` and `json.decode`. I think this will consume more computing resources than comparing two local variables. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org