Sql server 2022 transaction performance

Andrija Huzjak 16 Reputation points
2023-02-21T10:31:51.5733333+00:00

Investigating significant decrease of my app performance after database migration from Microsoft Sql Server 2019 (15.0.2095.3) to Microsoft Sql Server 2022 (16.0.1000.6). Database is on new machine which is 5y newer, with all benchmarks much better. Database contains exactly the same data / indexes.

After testing / benchmarking hardware, operating system and different queries on both servers this looks like good benchmark which shows where the bottleneck is:

  1. Create 100k of trivial update statements like this:
update RObject set CustomSpeed = 23, AverageSpeed = 9 where Id = 1077752 and SectId = 11009409
  1. Run client statistics from SSMS on Microsoft Sql Server 2019, if we wrap 100k updates in one transaction Total execution time drops from 7s to 4s.

2019

  1. Run client statistics from SSMS on Microsoft Sql Server 2022, if we wrap 100k updates in one transaction Total execution time drops from 595s to 3s.

User's image

So something with transactions is slowing it down! When I have 100k transactions on 2019 its 2x slower, but when I have 100k transactions on 2022 its ~200x slower. Crucial columns to watch are Number of transactions and Total execution time. Notice that new machine 25% better without transactions, but with transactions its two orders of magnitude worse. This is crazy.

Some considerations:

  1. IMPLICIT_TRANSACTIONS are off for both.
  2. Query Store was enabled on 2022, but turning it off did nothing.
  3. Delayed durability is disabled on both servers.
  4. Both queries are run on machine where test database located, but if I run again from other machine results are very similar, did that just to eliminate SSMS version / option differences.
  5. Update to 16.0.4003 did not help.
  6. Setting windows server Power Mode to High performance did not help.
  7. Sql 2019 is on Windows Server 2016 and Sql 2022 si on Windows Server 2022.

EDIT:

Installed server 2019 just to be sure, it works even slower, so it must be something with OS / drivers / hw. All hw benchmarks are good, something affecting transactions like some cpu operation missing or not in drivers??? I guess next step will be install older windows server.

EDIT2:

It works great on same hw but with Windows 11. There is some problem with using Windows 11 drivers for Windows Server 2022. Cpu / mem & nvme benchmarks were good, but something is messing with transactions performance. Hardware is ROG STRIX B550-F GAMING + AMD Ryzen 7 5700G.

This may be fixed if official Windows Server 2022 drivers are published for that chipset/cpu.

SQL Server | Other
{count} vote

4 answers

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2023-02-21T19:27:18.1933333+00:00

    It may not fix your issue, but I highly recommend you update 2022 to a current patch level and test again.

    https://learn.microsoft.com/en-US/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate1


  2. Erland Sommarskog 121.7K Reputation points MVP Volunteer Moderator
    2023-02-21T22:54:07.4766667+00:00

    Apparently you have some setting on SQL 2019 that you have forgotten to set on your SQL 2022 instance. The difference on SQL 2022 seems a lot closer to what I would expect than the one you have on SQL 2019. Check your trace flags etc.

    You can also try a clean install of SQL 2019 and see if you get the same fantastic results as you get on your current instance.

    And in any case, wrapping that many single statements in a transaction (or transactions with 1000 statements or so in each) has always been best practice.


  3. Seeya Xi-MSFT 16,586 Reputation points
    2023-02-22T06:36:00.4366667+00:00

    Hi @Andrija Huzjak ,

    Please read this blog for the directions outlined in it for your reference.

    https://blog.sqlauthority.com/2020/02/10/sql-server-top-reasons-for-slow-performance/

    Best regards,

    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


  4. Erland Sommarskog 121.7K Reputation points MVP Volunteer Moderator
    2023-02-22T19:13:54.3266667+00:00

    Except log file latency, which I don't know why it would be bad on better hardware, but will try to check,

    Well, very apparently there is an issue with your I/O subsystem. Without an explicit transaction, each statement is its own transaction, and SQL Server has to wait for the transaction log to be hardened. You can use sys.dm_exec_session_wait_stats to see which are the top waits for your session. It sounds like you would have a lot of WRITELOG waits.

    For what it's worth, I have a demo from one of my sessions, which is good for testing here. This is a loop that performs around 20000 updates, and I have it both with transactions with 1000 rows at a time, and without transactions.

    Running directly on my laptop I get this:

    SQL 2022 without transactions: 3689 ms.
    SQL 2022 with transactions: 3411 ms.
    SQL 2019 without transactions: 3230 ms.
    SQL 2019 with transactions: 2681 ms.

    On this laptop, I also have two VMs, one with SQL 2019 and one with SQL 2022. Here is the data:

    SQL 2022 without transactions: 7491 ms.
    SQL 2022 with transactions: 3307 ms.
    SQL 2019 without transactions: 7506 ms.
    SQL 2019 with transactions: 2901 ms.

    As you can see that with this complex setup, the cost for single-statement transaction increases considerably.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.