Quantcast
Channel: SQL Server Compact Forum
Viewing all articles
Browse latest Browse all 193

What strategy is used to pick the next connection if multiple candidates wait for a lock? Could one starve to death?

$
0
0

I am seeing SQL Server reporting deadlock errors and after some investigation, I found that they are not really deadlocks, but rather connections running into timeouts while waiting for a lock.

I have an application that uses multiple threads and connections (each thread has its own connection) to insert new data. All threads basically populate the same tables (say ORDER and ORDERITEMs), so the sequence of events is:

  1. Thread #1: INSERT INTO ORDER (order locked)
  2. Thread #2: INSERT INTO ORDER (blocked)
  3. Thread #3: INSERT INTO ORDER (blocked)
  4. ...(e.g. thread#1 insert into orderitem) ...
  5. Thread #1: COMMIT (releases lock)
  6. Thread #3: continues work
  7. ...
  8. Thread #3: COMMIT
  9. Thread #2: continues work

Apparently, SQL Server has picked Thread #3 to continue, rather than Thread #2, although it was waiting longer. 

What I am seeing in my logs is that every now and then under high load a thread would starve to death waiting to be picked. Other threads that came in later get served, continue their work and finish after 200-400 msecs. 

Is my understanding correct? Is there a way to influence this (other than increasing the timeout, which does not actually solve the issue)?

J.-



Viewing all articles
Browse latest Browse all 193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>