NServiceBus.Persistence.Sql
NServiceBus.Persistence.Sql copied to clipboard
Performance hit due to unneeded UPDATE to increment "Concurrency" counter when there are no saga state changes
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.