From: Michael N. <uu...@rz...> - 2002-07-05 13:37:39
|
Matthew Bloch wrote: > Hello; > > I've just noticed an undesirable interaction between multithreaded Ruby > applications and the MySQL C API (if not other DB APIs); my web spider > application was running along fine but suddenly after an unpredictable number > of minutes, hours etc. it would stop dead. I think the problem is that I use > a "lock tables" statement which, if used with Ruby threads, blocks the whole > Ruby process until the table is unlocked. Trouble is if the 'thread' holding > the lock is an internal Ruby thread in the same process it'll never get run > to unlock it :-/ > > Is there a general way around this problem with the mysql_ API? My > impression is no, since I can't find any way of telling mysql to use > non-blocking semantics through its C API. Anyhow even if we leave it like > this it's probably worth adding a note about this pitfall to the docs. If only your Ruby application accesses the Mysql database and you want to lock a table only for one thread, use a Mutex instead of locking the whole table. But if you lock a table because other processes (outside the Ruby world) should not modify the table while one Ruby thread modifies it, I see no other chance than using processes (start new Ruby interpreter) instead of threads. Or have you tried to use an own connection (DBI.connect) for each thread? Regards, Michael |