NServiceBus.Persistence.Sql icon indicating copy to clipboard operation
NServiceBus.Persistence.Sql copied to clipboard

Performance hit due to unneeded UPDATE to increment "Concurrency" counter when there are no saga state changes

Open ramonsmits opened this issue 5 years ago • 0 comments

When there are no saga state changes we will still do an UPDATE that increments the "Concurrency" column

https://github.com/Particular/NServiceBus.Persistence.Sql/blob/9affa576774df39fe4b746409329eb181e1dbab6/src/SqlPersistence/Saga/SqlDialect_MsSqlServer.cs#L71-L78

This causes an unneeded roundtrip to the database. Network IO is very slow thus has a performance impact

Considerations:

  • Currently, we only have pessimistic locking. With pessimistic locking there is no need at all to increment the counter.
  • With optimistic concurrency control, there is a side effect as multiple messages are processed. This likely is not a problem but there can be race conditions of emitted messages due to concurrent processing when falsely assuming ordered processing. However, this can also happen with pessimistic locking but less likely.

ramonsmits avatar May 20 '20 17:05 ramonsmits