Hi, Ryan,
On Tue, Sep 22, 2009 at 1:02 PM, Ryan Pusztai <[email protected]> wrote:
> Hi Fabio,
>
> On Tue, Sep 22, 2009 at 11:11 AM, Fabio Mascarenhas <[email protected]>
> wrote:
>>
>> > So what was the plan for Orbit in a production environment? Did you
>> > expect
>> > the server to restart every so often? I am not meaning any disrespect I
>> > just
>> > feel my setup is not correct. I just want to deploy this application and
>> > not
>> > need to restart the service every so often.
>>
>> Maybe it was naive of my part, but I was expecting libmysql client to
>> keep the connection open as long as you wanted it to. This is like
>> having to reset your X session every eight hours or so. Imagine if the
>> rest of the operating system worked the same way, long-lived processes
>> would get reset every few hours or so.
>
> You are not naive at all, I would have expected that and MySQL is not
> working that way. I have been trouble shooting this issue for a while before
> I emailed the list because I thought it was my servers fault, only to find
> out that MySQL has this disconnection "feature". Thanks.
>
>> I am working on a solution, a connection wrapper, and will send it to
>> you later today.
>
> Wow I really appreciate it. Thanks so much. When you send it I am using
> LuaRocks as the install, so just let me know where to place the file. Also
> this will work in Xavante too right? I use Xavante for testing changes
> before rolling them out to users. This is not as critical, I am just
> wondering.
I added the following function to model.lua (it will be
orbit.model.recycle), it is already on the CVS and will be on the next
release of Orbit, which I am already preparing (version 2.1.0). The
first parameter is a function that produces a connection (what you
usually do to connect), the second is a timeout in seconds, which
defaults to six hours.
To use, replace the line where you open your connection with a call to
this function. For example, this (in the "blog" example):
mapper.conn = env:connect(unpack(database.conn_data))
Becomes this:
mapper.conn = orbit.model.recycle(function () return
env:connect(unpack(database.conn_data)) end)
And the connection will be automatically recycled every six hours. I
have tested it with low timeouts and it is working. Just copy it to
your model.lua, change your application and your problem with MySQL
should go away.
--------------
function recycle(fresh_conn, timeout)
local created_at = os.time()
local conn = fresh_conn()
timeout = timeout or 6 * 60 * 60
return setmetatable({}, { __index = function (tab, meth)
tab[meth] = function (tab, ...)
if created_at + timeout
< os.time() then
print("new conn")
created_at =
os.time()
conn = fresh_conn()
end
return conn[meth](conn,
...)
end
return tab[meth]
end
})
end
----------
> --
> Regards,
> Ryan
>
--
Fabio Mascarenhas, Lablua
http://www.lua.inf.puc-rio.br
_______________________________________________
Kepler-Project mailing list
[email protected]
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/