views:

62

answers:

3

I need to use a table for a queuing system. The table will be constantly be updated.

For example, multiple users on my website, will add their files for process, and I heard that when updates occur simultaneously from multiple users, the table becomes non responsive or something like that.

so do I need locking tables in this situation ? how do i apply a lock to a mysql table ?

+1  A: 

so do I need locking tables in this situation ?

All tables can be locked, there isn't a special type of table. That said, deal with the issue when you run into deadlocks. Isolation levels are a closely related topic as well.

how do i apply a lock to a mysql table ?

There's the LOCK TABLES syntax - this article covers how & why you'd want to lock tables.

OMG Ponies
+2  A: 

By constantly be updated do you mean it will be appended to 10,000 times per second? Even for middle-range servers, that still presents 10,000 opportunities per second for the table to be shared by other users.

It's only necessary to lock the table when several dependent operations need to occur as a unit. In most cases, it is sufficient to include the series of operations in a database transaction. If the "constant updates" are merely insert sometable values ( ...), then it will be easy to guarantee transaction consistency.

wallyk
A: 

When you do several updates at once, you can get into a deadlock situation. Engines such as InnoDB will detect this and fail one of your transactions (You can retry, but only the whole transaction).

You can avoid this by table locking, but it reduces concurrency.

Engines such as MyISAM (which does not support MVCC or transactions anyway) use table locking implicitly anyway. Such table locks exist only for the duration of a query; they're automatically released soonish after the table isn't needed any more (not necessarily as soon as possible, but quite soon)

I recommend you do not use LOCK TABLE unless you feel you really need to; if you get a deadlock, retry the transaction.

MarkR