From 9af8e8990ed1f3dd3f02d0901cacaa70431fdfab Mon Sep 17 00:00:00 2001 From: cn Date: Mon, 5 Nov 2018 13:34:43 +0100 Subject: [PATCH] Improve docs regarding ngx.shared.DICT thread-safety --- metrics_graphite.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/metrics_graphite.lua b/metrics_graphite.lua index c1b3737..d7dc6d3 100644 --- a/metrics_graphite.lua +++ b/metrics_graphite.lua @@ -34,7 +34,8 @@ function MetricsGraphite.init(carbon_hosts, interval, mbase) } -- initialize/reset counters - self.stats = ngx.shared.metrics_graphite -- TODO: unclear whether ngx.shared.DICT is thread-safe? + -- Note: ngx.shared.DICT is thread-safe, see https://github.com/openresty/lua-nginx-module#ngxshareddict + self.stats = ngx.shared.metrics_graphite self.stats:set("main_loop_worker", 0) self.stats:set("requests", 0) -- total number @@ -64,7 +65,8 @@ function MetricsGraphite.init(carbon_hosts, interval, mbase) end function MetricsGraphite:worker() - -- determine which worker should handle the main loop, relies on thread-safety of ngx.shared.DICT:incr + -- determine which worker should handle the main loop, relies on the atomicity of ngx.shared.DICT:incr + -- see https://github.com/openresty/lua-nginx-module#ngxshareddict if self.stats:incr("main_loop_worker", 1) ~= 1 then return end