My question is not specific but it is abstract. I often deal with background DB processing in my projects, but still have no good strategy how to do that properly.
For example, we have a table with lot of records, several hundred thousand records or event millions. Background daemon permanently modifies the data of this table. It updates and inserts records based on other data got from outside. To save a time, I use multi-INSERTs to save a time, because I even can not imagine how long may take updating records one by one. Also, since background process runs in multi threading mode, I forced to use WRITE LOCK on that table. If I don't do that, then I recevinig lot of deadlock errors, because each multiinsert blocks gaps and autoincrements in table and they can not execute independently. WRITE LOCK puts all queries in the queue and they executed sequentially, next query waits while previous is completed. May be here is my first mistake, but I found no other effective method to run multi-inserts in multithread mode. Simple schema of daemon looks like:
MAIN PROCESS
-- WORKER 1: Receiving data over HTTP --> INSERT table VALUES (..., ..., ...)
-- WORKER 2: Receiving data over HTTP --> INSERT table VALUES (..., ..., ...)
-- WORKER 3: Receiving data over HTTP --> INSERT table VALUES (..., ..., ...)
From the other side we have an user interface that displays data from the table. It performs SELECT query from our table. But as I said if background process is running, WRITE lock is activated. That means READ operations are also should to wait while lock is active. For the user it looks like a whole server hanged.
That why I writing this question. Are there any strategies to modify big amounts of data together with ability of reading it?