Bugs: Browse | Submit New | Admin

[#26415] mysql dbd memory leak

Date:
2009-06-24 13:36
Priority:
3
Submitted By:
Qi Lu (qi_lu)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
mysql dbd memory leak

Detailed description
I am using dbd-mysql (0.4.2) and dbi 0.4.1 on Window XP/Vista/2003. I found memory leak. My Ruby version is 1.8.6. For
my test code which is listed below, it can leak more than 3M a day. Here is the test code:

require 'rubygems'
require 'dbi'

host = 'localhost'
db = 'leaktest'
port = 3306
user = 'leaktest'
pw = 'kael4'
connection = DBI.connect("DBI:Mysql:#{host};database=#{db};port=#{port}", "#{user}",
"#{pw}")

i = 1
name = 'test'
while true do
  value = name + i.to_s
  sql = "insert into test (name) values ('#{value}');"
  #sth = connection.execute(sql)
  rows = connection.do(sql)
  sleep 0.5
  #sth.finish
  i += 1
end

here are the statement to setup database and table:

mysql> create database leaktest;
mysql> use leaktest;
mysql> create table test ( ID int(11) NOT NULL auto_increment, name varchar(20) not null, CONSTRAINT PK_test_id PRIMARY
KEY (ID) );
mysql> grant select,update,insert,delete,execute,create,drop,alter on leaktest.* to leaktest@localhost identified
by 'kael4';


The leak occurs by using either 'do' or 'execute' (need finish sth) methods. let it run more than one day. you will
see the leak. If the table is more complex, it is easier to reproduce. For above test, if it sleeps more time, it leaks
less. but my application code need insert record quite often.

Qi

ps. this code does not leak (or much less) in SQL server database (dbd-odbc)

Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-09-13 18:55
Sender: Erik Hollensbe

Sorry about taking so long to get back to you on this, working
a new job and moved across country in the last two months.

Two things make me think this is not an issue with DBI, and are
more likely related to the mysql gem:

The ODBC driver does not exhibit this behavior.

Looking at the code, no actual fetches are performed and the
MySQL handle is cleaned up on finish (Which is what do() does,
and you are manually doing it with execute()). The code path
followed is more-or-less exactly the same with the ODBC code.
Everything else is completely internal to the statement object
that is created, and should be cleaned up upon garbage
collection.

I'll leave this up for a month or so to give people the opportunity
to prove me wrong.
Date: 2009-06-24 14:22
Sender: Erik Hollensbe

I will look into this later today. Thank you for letting me know.

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item