0

Let's say you have 200 users on your website, all posting a comment and pressing at the same time on the 'save' button.

  1. Will the 200 comments be put in a queue and inserted one by one?
  2. If yes: does that mean the lower your position is in the queue, the longer you have to wait until your commet is saved?

Database: mysql.

Swag
  • 2,090
  • 9
  • 33
  • 63

2 Answers2

0

Yes, one by one. Because every request creating new connection and updating indexes. Yes, your response waiting queue.

But if you are not using FK, unique key, etc. it doesn't take long time (less then second). So indexes are very important for prevent table/index locking.

mkysoft
  • 5,392
  • 1
  • 21
  • 30
  • Can you explain me a scenario how those inserts can lead to table or index locking with 'Repeatable Read' as database isolation? – Swag Mar 14 '16 at 18:49
  • "Repeatable Read" are here http://stackoverflow.com/questions/4034976/difference-between-read-commit-and-repeatable-read It is not possible to use "Repeatable Read" in web application. Because after response your connection die. If you make it anyway, it is depending on db. I don't have detail information but may be it dublicate indexes for transaction. Also MyIsam cannot support transactions. – mkysoft Mar 14 '16 at 19:12
0

200 users mean separate 200 connections to the database.

Having said that, each insert is processed separately.
Note: This is a bit clearer if you use transactions. You are able to commit or rollback individual transactions.

200 inserts is a pretty small load for a mysql server, so the waiting time won't be extremely visible.

To some extent, inserts can be 'parallelized' by using different threads, concurrent inserts along with row-locking (table-locking prevents this)

But yes, they are put in a queue and will get inserted in a FIFO manner.

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
  • Can you maybe explain why you removed the parallel/concurrent insert? Sounds pretty cool. Is that faster? – Swag Mar 14 '16 at 18:52
  • Well, nothing is really parallel when it comes to CPU. There is at least a cycle in between :) As for the speed, you might want to look into Master-Master replication. But it all comes down to your table structure and optimization. You can gain a lot by properly configuring a MySQL server (and changing the default values to what you *really* need). – Alex Tartan Mar 14 '16 at 19:11