有想過使用pid當做key, 但現在使用nginx 1.7.2 lua沒有支持pid的api,,,,,,, 除了upgrade nginx,,,,還有其他可行方式?!
hopestar於 2016年5月24日星期二 UTC+8上午11時58分00秒寫道:
我的解决办法是把你worker 的pid作为key,
在执行的时候判断是不是当前的worker,从而做到只有一个worker在执行。
在 2016年5月23日星期一 UTC+8下午5:31:36,Eric Chen写道:
使用情境是worker啟動會檢查一個標記,來決定要不要跑一段代碼,現在遇到一個問題
當啟動或是重啟nginx, worker process會變成zombie process 會被master不斷重新fork.
init_worker_by_lua_file代碼:
local dict = ngx.shared.config
local ok, err = dict.get("my_variable")
if ok then
do something.....
else
do something.....
end
......
ps command 結果
41487 ? Rs 3:22 nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2214 ? S 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2215 ? S 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2216 ? R 0:00 \_ [nginx]
2217 ? S 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2219 ? S 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2223 ? S 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2227 ? S 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2228 ? S 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2229 ? S 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
2236 ? R 0:00 \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -c nginx.conf
是因為worker瞬間access同一個share dict引起的問題?
或是這樣情境需要一個lock來保護?