Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Administration - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 6525

Concurrency Woes.

$
0
0
Morning All,I have this utter pile of rubbish system that is not going anywhere soon. Sadly.The original developers who we (before my time) paid tons of money to for this opted not to use an identity field on tables, and instead, have a single table of numbers, for each table that requires and ID. This beautiful table looks something like this:[Table: ID_GENERATOR_STORAGE]ID_NAME VALUE------------- ------------------User 34556Address 78231Purchase 123412313For this to 'work' there is a stored procedure, for some unknown reason in a different database, called GetNextID.GetNextID does something like this:[code="sql"]SET NOCOUNT ON; begin transaction; declare @val bigint; select @val = [VALUE] FROM ID_GENERATOR_STORAGE WITH (HOLDLOCK, UPDLOCK) WHERE ID_NAME=@id_name; IF @@ROWCOUNT = 0 begin set @return = -1; commit; return; end else begin set @return = (@val+1); UPDATE ID_GENERATOR_STORAGE SET VALUE=@val+@step_size WHERE ID_NAME=@id_name; commit; return; end[/code]Please do note the hint on ID_GENERATOR_STORAGE: holdlock and updlock.Needless to say this highly concurrent system is neither! Especially during peak times such as 9am (opening up time) and 3pm (crap its 3pm, I better do some work!).There is zero approval to make this work sensibly, I just have to work around this problem.With that; is there *anything* I can do to improve the blocking situation that is experienced daily.There are 58 Rows in ID_GENERATOR_STORAGE. This DB was ported from MySQL about 7 years ago but is now in SQL Server 2008. At some point it will be moved on to a 2014 Enterprise box, so I am not against any 2014 only solutions if they exist.The other problem that compounds this issue is the client timeout, there is a mixture of inline sql, prepared statements and stored procedures... Often, the user, who is rightly impatient because their application has hung whilst waiting on a new ID kills their app (or even their citrix session) which leaves a transaction open which means the blocking never clears up.So, I am at a loss as to how to improve this nonsense.Cheers All,Alex

Viewing all articles
Browse latest Browse all 6525

Trending Articles