1
0
mirror of https://github.com/cmur2/nginx-metrics-graphite.git synced 2024-12-22 12:54:23 +01:00

Improve docs regarding ngx.shared.DICT thread-safety

This commit is contained in:
cn 2018-11-05 13:34:43 +01:00
parent 07d3d51705
commit 9af8e8990e

View File

@ -34,7 +34,8 @@ function MetricsGraphite.init(carbon_hosts, interval, mbase)
} }
-- initialize/reset counters -- 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("main_loop_worker", 0)
self.stats:set("requests", 0) -- total number self.stats:set("requests", 0) -- total number
@ -64,7 +65,8 @@ function MetricsGraphite.init(carbon_hosts, interval, mbase)
end end
function MetricsGraphite:worker() 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 if self.stats:incr("main_loop_worker", 1) ~= 1 then
return return
end end