> Is your current version of mysql locking tables by default?
mysql uses table locking - it isn't an option, that's the way mysql works when you write to table (see chapters 13.2.8-9 and I.4)
locking doesn't appear with selects and sometimes with inserts (new mysql versions use versioning to do concurrent inserts)
> Normally, you don't have to lock tables,
I didn't mean locking table by sql command. I meant this atomic locking which mysql does when you write to table.
When you do show processlist you can watch state field for queries. If you issue a long update query and a concurrent select query on the same table you can see that select query has state "locked", because it waits for update to complete.
You can also watch "show status" which in version 3.23.33+ shows Table_locks_waited and Table_locks_immediate.
Typically when you have short queries you will have locks_waited much smaller than locks_immediate (ie. 30 waited and 60000 immediate on my system during single evening hour), which means that only few queries had to wait for other queries to complete.
On busy hours on my forum waited/immediated is about 1/50 (compare with above 1/2000). Also slow_queries (that is queries longer than long_query_time variable, default 10sec) is getting large (normally <10, it grows >1000)
> I don't think there would be any way to change the scripts if
> tables are always locked from and insert,select,update etc.
> as your forums grow the amount of traffic will keep tables
> almost continuosly locked
If you move b_counter to new table updates of b_counter won't be locking w3t_posts for selects.
New table would be smaller so updates would also run quicker.
I will turn off read counter for a while to see if it's the main reason of locks.
A few tips from mysql manual which I think could be helpful:
-Try to avoid complex SELECT queries on tables that are updated a lot. This is to avoid problems with table locking
-Get Your Data as Small as Possible
-If you very often need to calculate things based on information from a lot of rows (like counts of things), it's probably much better to introduce a new table and update the counter in real time. An update of type UPDATE table set count=count+1 where index_column=constant is very fast! This is really important when you use databases like MySQL that only have table locking (multiple readers / single writers).
- Use HEAP tables to get more speed when possible. (I've changed w3t_Online to heap - it doesn't help a lot, but why not, heap tables are created for this kind of tasks)
-In some circumstances it can be beneficial to split into two a table that is scanned very often. This is especially true if it is a dynamic format table and it is possible to use a smaller static format table that can be used to find the relevant rows when scanning the table.
Greetings,
Piotr