提交 5bd87a1a authored 作者: Bret McDanel's avatar Bret McDanel

added "status" checking and not processing events if we are at the max sessions…

added "status" checking and not processing events if we are at the max sessions or max session rate.
The load detection is primitive, it only looks at sessions and not what the action is doing (which may not involve a session)
Additionally it does not look at the actual system load, so  if you have misconfigured your max sessions you may overdrive your box and cause problems



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@15224 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 b1b7d1fe
...@@ -166,6 +166,10 @@ ...@@ -166,6 +166,10 @@
event_subclass = e:getHeader("Event-Subclass") or "" event_subclass = e:getHeader("Event-Subclass") or ""
if(event_name == "HEARTBEAT") then if(event_name == "HEARTBEAT") then
-- check the system load
load = api:execute("status")
cur_sessions,rate_sessions,max_rate,max_sessions = string.match(load,"(%d+) session.s. (%d+)/(%d+)\n(%d+) session.s. max")
if ((tonumber(cur_sessions) < tonumber(max_sessions)) and (tonumber(rate_sessions) < tonumber(max_rate))) then
env = assert (luasql.mysql()) env = assert (luasql.mysql())
dbcon = assert (env:connect(DATABASE,USERNAME,PASSWORD,DBHOST)) dbcon = assert (env:connect(DATABASE,USERNAME,PASSWORD,DBHOST))
while true do while true do
...@@ -179,16 +183,17 @@ ...@@ -179,16 +183,17 @@
assert (dbcon:execute("UNLOCK TABLES")) assert (dbcon:execute("UNLOCK TABLES"))
apicmd,apiarg = string.match(row.action,"(%w+) (.*)") apicmd,apiarg = string.match(row.action,"(%w+) (.*)")
api:execute(apicmd,apiarg) api:execute(apicmd,apiarg)
end end -- while
dbcon:close() dbcon:close()
env:close() env:close()
end -- rate limiting
else if (event_name == "CUSTOM" and event_subclass == "lua::scheduled_event") then else if (event_name == "CUSTOM" and event_subclass == "lua::scheduled_event") then
action = e:getHeader("Action") or "" action = e:getHeader("Action") or ""
if (action == "stop") then if (action == "stop") then
logger("got stop message, Exiting") logger("got stop message, Exiting")
break break
end end
end end -- not a custom message
end end -- not a processable event
end end -- foreach event
end end -- main loop, DB connection established
\ No newline at end of file \ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论