#326 ✓resolved
Matthew W

Queries via do_mysql block the whole interpreter, even when executed inside a thread (making concurrent db access impossible)

Reported by Matthew W | May 29th, 2008 @ 05:47 PM

Queries via do_mysql block the whole interpreter, even when executed inside a thread.

For an example, see:

> d = DataObject::Mysql::Connection.new('user=root')
=> #<DataObject::Mysql::Connection:0x741058 ...>

> d.open
=> true

> command = d.create_command('select sleep(10)')
=> #<DataObject::Mysql::Command:0x7384d0 ...>

> Thread.new { command.execute_reader.entries }

...Here there is a long 10 second pause while the whole interpreter hangs while mysql runs my 'sleep 10' command...

=> #<Thread:0x7102a0 run>

This is against the latest (0.2.4) do_mysql gem.

Note that this makes using a connection pool quite pointless - because only one query can ever run at a time across all connections.

In addition to fixing this, one needs to make sure (IIRC) that you don't hold the Global Interpreter Lock over the portion of the C extension code that waits for the query result. In this situation, while you can fire off queries in separate threads without blocking the main interpreter, only one thread can ever actually execute a mysql command at the same time, and this makes connection pools and concurrent DB access equally pointless. See Mysql/Ruby for an example of this behaviour.

You can test for a fix, by opening 2 separate connections, firing off threads which run 'select sleep(10)' queries on both connections, and checking with 'show processlist' from the mysql console, that both queries are indeed executing concurrently.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages