Mod_lua: dbh open to many connections to database

António Silva asilva at wirelessmundi.com
Tue Mar 23 15:49:51 UTC 2021


Hi,

After migrate an old server from debian jessie to debian buster, hit a problem of cpu load increasing and block the server at 100% of cpu usage. I notice that was the number of postgresql open process.

Doing a simple sipp of 40cps to stress the server I notice that the problem is in a lua script, the script check if the caller is a table (database postgres) and allows or not the call.
in debian jessie the db handles open (using db_cache status) are  less than 20, but now in debian buster it scales to more that 100, and I start to see error messages that postgress cannot open more connections (that is true I’ve limited to 100 connections).

Anyone experience this problem?

I also try to set the max-db-handles open to 50, in switch.xml, but it ignores this parameter - I think that is only use in internal modules and not for lua scripts… 
Can I limit the number of open connections when using FS dbh?
 

The function I get to fetch the result:
filename = "pgsql://host=/var/run/postgresql/ user=postgres dbname=list"

callback_query_fetch = function (row)
	if (single_row == true) then
		result = row
		return 1 -- break the loop
	end
	if (result == false) then result = {} end
	table.insert(result, row)
	return 0
end

function db.fetch_single(filename, sql)
	local dbh = freeswitch.Dbh(filename)
	result = false
	single_row = true
	if (dbh:query(sql, callback_query_fetch) == false) then
		dbh:release()
		return false
	end
	dbh:release()
	return result
end



--
Saludos / Regards / Cumprimentos
António Silva




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20210323/34598b68/attachment.html>


More information about the FreeSWITCH-users mailing list