Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InsertToList() performance #2391

Open
neildodson opened this issue Apr 15, 2024 · 2 comments
Open

InsertToList() performance #2391

neildodson opened this issue Apr 15, 2024 · 2 comments

Comments

@neildodson
Copy link

Version: 1.8.10
Storage: Hangfire.SqlServer
ConfigurationLogic: any
Custom Filters: none

Description:
When inserting to a list, an exclusive lock is taken on all existing rows with the same key by means of selecting them:

select [Key] from [{_storage.SchemaName}].List with (xlock, forceseek)

I was a bit confused about why this happens - as a shared application lock has already been taken on the key before this Sql statement runs...
The reason I ask is that when the list for a give key becomes long, all the previous rows are selected, meaning an insert at position 1 million requires selecting the previous 999,999 rows - and that doesn't perform well..

@neildodson
Copy link
Author

neildodson commented Apr 15, 2024

just counting them seems to take the lock as well, btw...

select count([key]) from hangfire.list with (xlock, forceseek)
where [Key] = @key;

but it still doesn't scale up

@neildodson
Copy link
Author

Hmm, what I assumed initially isn't right - in the default case (where DisableGlobalLocks is true and UseFineGrainedLocks is false) in fact application locks aren't taken for any type of storage update...

if (!_storage.Options.DisableGlobalLocks || _storage.Options.UseFineGrainedLocks)

I guess that's because the SQL server locking semantics are adequate for all these cases, and the (xlock) hints are needed to make that true (right?).. But why is it necessary to lock all the list predecessors before inserting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant