Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of memory with MariaDB #109

Open
krejkrejkrej opened this issue Jan 22, 2019 · 0 comments
Open

Out of memory with MariaDB #109

krejkrejkrej opened this issue Jan 22, 2019 · 0 comments

Comments

@krejkrejkrej
Copy link

Hi. I'm having a problem with out-of-memory errors when connecting repeatedly to a MariaDB. This is within Domoticz using:
Lua: 5.2.2
lua-sql-mysql - Version: 2.3.4-1
libmariadbclient18 - Version: 10.1.37-0+deb9u1
Debian Linux 9 in a Docker container.

I guess I'm seeing the same problem as in issue #105 , so let me add some more detail. There's a Lua script that is executed once a minute. After restarting Domoticz, the script happily fetches data for about 16 hours, after that I see:

2019-01-22 19:13:00.436 Error: EventSystem: in Hämta VP-data: [string "--..."]:40: LuaSQL: error connecting: Out of memory.

Line 40 is "env:connect()"
This is what the script does using Luasql:

-- connect to MariaDB
package.cpath = package.cpath .. ";/usr/lib/x86_64-linux-gnu/lua/5.2/luasql/?.so"
local mysql_driver = require "luasql.mysql"
local env  = assert(mysql_driver.mysql())
local conn = assert(env:connect('thermiq_db', 'thermiq_user', 'REMOVED', 'db.ejvind.se'))

-- execute the query
local cursor = assert(conn:execute([[
SELECT
   T_UTE,
   T_VATTEN, 
   (CASE WHEN kompr = 1 THEN 2100 ELSE 0 END + TS_P * 1000)  AS EFFEKT,
   (CASE WHEN ts_p = 0 THEN 0 
         WHEN ts_p > 0 AND varmvatten = 1 THEN 1 
         ELSE 4
     END)                                                    AS ELPATRON,
    (CASE WHEN kompr = 0 THEN 0
          WHEN kompr = 1 AND varmvatten = 0 THEN 1
          ELSE 2
     END)                                                    AS KOMPR_N  
FROM  thermiq_db.DATASTORE_RAW TR 
WHERE unix_timestamp(now()) - tid < 80 
  AND unix_timestamp(now()) - tid >= 20 
ORDER BY
   tid DESC 
LIMIT 1; ]]))

-- fetch the result
local row = assert(cursor:fetch ({}, "a"))

[..some processing stuff removed..]

-- close everything
print("Cursor: " .. tostring(cursor:close()))
print("Connection: " .. tostring(conn:close()))
print("Env: " .. tostring(env:close()))

local freeMem = collectgarbage('count');
print("GC Count : " .. freeMem/1024 .. " MB");

The memory allocation debug output shows that Lua constantly uses about 70 kB of memory.

Advice on what to change? Is more info needed to resolve the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant