# Concurrency slow down due to locking on SQL Server

**URL:** <https://discuss.hangfire.io/t/concurrency-slow-down-due-to-locking-on-sql-server/3092>\
**Category:** bug?\
**Tags:** sql-server\
**Created:** [March 21, 2017, 12:17am UTC](https://discuss.hangfire.io/t/concurrency-slow-down-due-to-locking-on-sql-server/3092 "2017-03-21T00:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tejasxp](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tejasxp](https://discuss.hangfire.io/u/tejasxp)\
**Post date:** [March 21, 2017, 12:17am UTC](https://discuss.hangfire.io/t/concurrency-slow-down-due-to-locking-on-sql-server/3092/1 "2017-03-21T00:17:28Z")

</div>

Hi -

I have a typical Hangfire + Sql Server setup (using Azure).

I have to crunch through around 160,000 jobs, my default concurrency is ~20 workers, but when all 20 workers are doing their work, pretty much all of hangfire comes down to a crawl.

DB load is very low (we use a P11 instance right now, DTU usage is less than 10%, other queries are just fine). I’ve traced this down to lock contentions.

This query:  
`SELECT sqltext.TEXT,* FROM sys.dm_exec_requests OUTER APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext where DB_NAME(database_id)='dbname' and blocking_session_id <>0`

yields ~6-7 blocked queries, waiting on resource `APPLICATION: 6:0:[HangFire:Set:Lock]:(cb774589)` – this appears to be a global lock.

I’m about to start digging into this code to figure out what can be done about it, but some pointers would be helpful. It appears that if I have a lot of short-running jobs, with a concurrency level of ~20, the hangfire subsystem overhead drags everything down.

---

<div class="post-metadata">

**Author:** ![tejasxp](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tejasxp](https://discuss.hangfire.io/u/tejasxp)\
**Post date:** [March 21, 2017, 3:44am UTC](https://discuss.hangfire.io/t/concurrency-slow-down-due-to-locking-on-sql-server/3092/2 "2017-03-21T03:44:00Z")

</div>

Adding a few seconds delay inside the job seems to stabilize things a bit

---

<div class="post-metadata">

**Author:** ![lhalfon](https://avatars.discourse-cdn.com/v4/letter/l/4da419/32.png) [@lhalfon](https://discuss.hangfire.io/u/lhalfon)\
**Post date:** [June 4, 2019, 2:21pm UTC](https://discuss.hangfire.io/t/concurrency-slow-down-due-to-locking-on-sql-server/3092/3 "2019-06-04T14:21:17Z")

</div>

Hi! what’s the configuratin for delay a few seconds the job?
