diff options
Diffstat (limited to 'src/daq/nginx-lua/s5-nginx.lua')
-rw-r--r-- | src/daq/nginx-lua/s5-nginx.lua | 60 |
1 files changed, 23 insertions, 37 deletions
diff --git a/src/daq/nginx-lua/s5-nginx.lua b/src/daq/nginx-lua/s5-nginx.lua index 673ccba..f1e3719 100644 --- a/src/daq/nginx-lua/s5-nginx.lua +++ b/src/daq/nginx-lua/s5-nginx.lua @@ -35,15 +35,16 @@ -- http { -- ..... -- --- lua_shared_dict sfive 64k; --- lua_shared_dict sfive_locks 64k; +-- lua_shared_dict sfive 32k; -- lua_shared_dict sfive_data 64m; -- init_by_lua 's5 = require "s5-nginx.lua"'; -- init_worker_by_lua 's5.init_worker(5)'; +-- limit_conn_zone $server_name zone=perserver:32k; -- -- ..... -- -- server { +-- server_name somename; -- -- ..... -- @@ -55,7 +56,7 @@ -- allow 127.0.0.1; -- allow ::1; -- deny all; --- +-- limit_conn perserver 1; -- content_by_lua 's5.fetch()'; -- } -- @@ -64,8 +65,6 @@ -- } -- -locks = require "resty.lock" - local _SFIVE = {} ----------------------------------------------- @@ -106,43 +105,30 @@ function _SFIVE.log() end function _SFIVE.fetch() - local lock = locks:new("sfive_locks", { exptime = nil, timeout = 0.001 }) - local ok, err = lock:lock("fetch") - if not ok then - if err == "timeout" then - ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE) - else - ngx.log(ngx.ERR, "SFive(fetch): failed to acquire fetch lock: " .. err) - ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR) + ngx.log(ngx.INFO, "SFive(fetch): client connected") + while true do + logs = sfive_data:get_keys() + for i, k in ipairs(logs) do + local ok, err = ngx.say(sfive_data:get(k)) + if not ok then + ngx.log(ngx.ERR, "SFive(fetch): failed to send data set (" .. err .. ") - disconnecting client") + return + end + sfive_data:delete(k) end - else - ngx.log(ngx.INFO, "SFive(fetch): client connected") - while true do - logs = sfive_data:get_keys() - for i, k in ipairs(logs) do - local ok, err = ngx.say(sfive_data:get(k)) + ngx.flush() + local idx, err = sfive:get("log:idx") + if not idx then + ngx.log(ngx.ERR, "SFive(fetch): failed to get log index: " .. err) + else + if idx >= config.log_max_index then + local ok, err = sfive:replace("log:idx", 0) if not ok then - ngx.log(ngx.ERR, "SFive(fetch): failed to send data set (" .. err .. ") - disconnecting client") - lock:unlock("fetch") - return - end - sfive_data:delete(k) - end - ngx.flush() - local idx, err = sfive:get("log:idx") - if not idx then - ngx.log(ngx.ERR, "SFive(fetch): failed to get log index: " .. err) - else - if idx >= config.log_max_index then - local ok, err = sfive:replace("log:idx", 0) - if not ok then - ngx.log(ngx.ERR, "SFive(init): reseting log index counter failed: " .. err) - end + ngx.log(ngx.ERR, "SFive(init): reseting log index counter failed: " .. err) end end - ngx.sleep(0.1) end - lock:unlock("fetch") + ngx.sleep(0.1) end end |