Load testing SQL Server using HammerDB


This tutorial shows how to use HammerDB to perform load testing on aCompute Engine SQL Server instance. You can learn how to installa SQL Server instance by using the following tutorials:

There are a number of load-testing tools available. Some are free and opensource, while others require licenses.HammerDB is an open source tool that generally works well todemonstrate the performance of your SQL Server database. This tutorial coversthe basic steps to use HammerDB, but there are other tools available, and youshould select the tools that align best to your specific workloads.

Objectives

This tutorial covers the following objectives:

  • Configuring SQL Server for load testing
  • Installing and running HammerDB
  • Collecting runtime statistics
  • Running the Transaction Processing Benchmark derived from the TPC "C" specification (TPROC-C) load test

Costs

In addition to any existing SQL Server instances running onCompute Engine, thistutorial uses billable components of Google Cloud, including:

  • Compute Engine
  • Windows Server

ThePricing Calculator can generate a costestimate based on your projected usage. The provided link shows the costestimate for the products used in this tutorial, which can average 16 dollars(US) per day.

New Google Cloud users might beeligible for afree trial.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. If you aren't using Windows on your local machine, install a third-party Remote Desktop Protocol (RDP) client. For more information, seeMicrosoft Remote Desktop clients.

Configuring the SQL Server instance for load testing

Before you start, you should double check that your Windowsfirewallrules are set up to allow traffic from the IP address of the new Windows instance youcreated. Then, create a new database for TPCC load testing and configure a useraccount using the following steps:

  1. Right-click theDatabases folder in SQL Server Management Studio, andthen chooseNew Database.
  2. Name the new database "TPCC".
  3. Set the initial size of the data file to 190,000 MB and the log file to65,000 MB.
  4. Set theAutogrowth limits to higher values by clicking the ellipsisbuttons, as shown in the following screenshot:

    Setting Autogrowth limits

  5. Set the data file to grow by 64 MB to unlimited size.

  6. Set the log file to disable auto-growth.

  7. ClickOK.

  8. In theNew Database dialog, in the left pane, choose theOptionspage.

  9. SetCompatibility level toSQL Server 2022 (160).

  10. Set theRecovery model toSimple, so that the loading doesn't fill upthe transaction logs.

    Setting recovery model to Simple

  11. ClickOK to create the TPCC database, which can take a few minutes tocomplete.

  12. The preconfigured SQL Server image comes with only Windows Authenticationenabled, so you will need to enable mixed mode authentication within SSMS, byfollowingthis guide.

  13. Follow these steps to create a new SQL Server user account on your database server that has theDBOwner permission. Name the account "loaduser" and give it a securepassword.

  14. Take note of your SQL Server internal IP address by using theGet-NetIPAddress commandlet, because it's important for performance and securityto use the internal IP.

Installing HammerDB

You can run HammerDB directly on your SQL Server instance. However, for a moreaccurate test, create a new Windows instance and test the SQL Server instanceremotely.

Note: You might need to disableInternet Explorer Enhanced SecurityConfiguration before downloading files to your Windows Server instance.

Creating an instance

Follow these steps to create a new Compute Engine instance:

  1. In the Google Cloud console, go to theCreate an instance page.

    Go to Create an instance

  2. ForName, enterhammerdb-instance.

  3. In theMachine configuration section, select themachine type with at least half the number of CPUs as your databaseinstance.

  4. In theBoot disk section, clickChange, and then do the following:

    1. On thePublic images tab, choose a Windows Server operating system.
    2. In theVersion list, clickWindows Server 2022 Datacenter.
    3. In theBoot disk type list, selectStandard persistent disk.
    4. To confirm your boot disk options, clickSelect.
  5. To create and start the VM, clickCreate.

Installing the software

When it's ready, use an RDP client to connect to your new Windows Server instanceand install the following software:

Running HammerDB

After you install HammerDB, run thehammerdb.bat file. HammberDB doesnot show up in the Start menu's applications list. Use the following commandto run HammerDB:

Note: In this tutorial we've used HammerDB 4.10. If you are using a later version some options may have changed.
C:\Program Files\HammerDB-VERSION\hammerdb.bat

ReplaceVERSION with the version of the installed HammerDB.

Creating the connection and schema

When the application is running, the first step is to configure the connectionto build the schema.

  1. Double-clickSQL Server in theBenchmark panel.
  2. SelectTPROC-C.From theHammerDB site:
    TPROC-C is the OLTP workload implemented in HammerDB derived from the TPROC-C specification with modification to make running HammerDB straightforward and cost-effective on any of the supported database environments. The HammerDB TPROC-C workload is an open source workload derived from the TPROC-C Benchmark Standard and as such is not comparable to published TPROC-C results, as the results comply with a subset rather than the full TPROC-C Benchmark Standard. The name for the HammerDB workload TPROC-C means "Transaction Processing Benchmark derived from the TPC "C" specification".
  3. ClickOK

    Setting TPROC-C benchmark options

  4. ClickSchema and then double-clickOptions.

  5. Fill out the form using your IP address, username, and password as shown in the following image:

    Setting TPROC-C build options

  6. Set theSQL Server ODBC Driver to OBDC Driver 18 for SQL Server

  7. In this case, theNumber of Warehouses (the scale) is set to 460, butyou can choose a different value. Some guidelines suggest 10 to 100 warehousesper CPU. For this tutorial, set this value to 10 times the number of cores:160 for a 16-core instance.

  8. ForVirtual Users to Build Schema, choose a number that is between 1- and2-times the number of client vCPUs. You can click the grey bar next to theslider to increment the number.

  9. Clear theUse BPC Option

  10. ClickOK

  11. Double-click theBuild option below theSchema Build section tocreate the schema and load the tables. When that completes, click the redflash light icon in the top center of the screen to destroy the virtual userand move to the next step.

Note: If the build fails due to the SQL Server ODBC Driver, open theODBC Data Sources application in Windows and check the available ODBC driversunder the Drivers tab.

If you created your database with theSimple recovery model, you mightwant to change it back toFull at this point to get a more accurate test of aproduction scenario. This change doesn't take effect until after you take afull or differential backup to trigger the start of the new log chain.

Important: If you plan to run multiple tests,make a full backup of your newTPROC-C database,so that you can restore it later. Backing up can save you time compared tocreating the database again by using the tool. If you revert the database to aFull recovery model, you should backup the transaction logs to clear them outafter each test.

Creating the driver script

HammerDB uses the driver script to orchestrate the flow of SQLstatements to the database to generate the required load.

  1. In theBenchmark panel, expand theDriver Script section anddouble-clickOptions.
  2. Verify the settings match what you used in theSchema Build dialog.
  3. ChooseTimed Driver Script.
  4. TheCheckpoint when complete option forces the database to writeeverything to disk at the end of the test, so check this only if you plan onrunning multiple tests in a row.
  5. To ensure a thorough test, setMinutes of Rampup Time to 5 andMinutes for Test Duration to 20.
  6. ClickOK to exit the dialog.
  7. Double-clickLoad in theDriver Script section of theBenchmarkpanel to activate the driver script.

Setting TPROC-C driver options

Creating virtual users

Creating a realistic load typically requires running scripts as multipledifferent users. Create some virtual users for the test.

  1. Expand theVirtual Users section and double-clickOptions.
  2. If you set your warehouse count (scale) to 160, then set theVirtual Users to 16, because the TPROC-C guidelines recommend a 10x ratioto prevent row locking. Select theShow Output checkbox to enable errormessages in the console.
  3. ClickOK

Collecting runtime statistics

HammerDB and SQL Server don't easily collect detailed runtime statistics foryou. Although the statistics are available deep within SQL Server, they need tobe captured and calculated on a regular basis. If you do not already have aprocedure or tool to help capture this data, you can use the procedure in thissection to capture some useful metrics during your testing. The results will bewritten to a CSV file in the Windowstemp directory. You can copy the data toa Google Sheet using thePaste Special >Paste CSV option.

To use this procedure, you first must temporarily enableOLE Automation Procedures to write the file to disk.Remember to disable it after testing:

sp_configure 'show advanced options', 1;GORECONFIGURE;GOsp_configure 'Ole Automation Procedures', 1;GORECONFIGURE;GO
Note: Although this procedure is very small, it can affect the total throughputreported by a fraction of a percent.

Here's the code to create thesp_write_performance_counters procedure in SQLServer Management Studio. Before starting the load test, you will execute thisprocedure in Management Studio.:

USE [master]GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO/***LogFile path has to be in a directory that SQL Server can Write To.*/CREATE PROCEDURE [dbo].[sp_write_performance_counters] @LogFile varchar (2000) = 'C:\\WINDOWS\\TEMP\\sqlPerf.log', @SecondsToRun int =1600, @RunIntervalSeconds int = 2ASBEGIN--File writing variablesDECLARE @OACreate INT, @OAFile INT, @FileName VARCHAR(2000), @RowText VARCHAR(500), @Loops int, @LoopCounter int, @WaitForSeconds varchar (10)--Variables to save last counter valuesDECLARE @LastTPS BIGINT, @LastLRS BIGINT, @LastLTS BIGINT, @LastLWS BIGINT, @LastNDS BIGINT, @LastAWT BIGINT, @LastAWT_Base BIGINT, @LastALWT BIGINT, @LastALWT_Base BIGINT--Variables to save current counter valuesDECLARE @TPS BIGINT, @Active BIGINT, @SCM BIGINT, @LRS BIGINT, @LTS BIGINT, @LWS BIGINT, @NDS BIGINT, @AWT BIGINT, @AWT_Base BIGINT, @ALWT BIGINT, @ALWT_Base BIGINT, @ALWT_DIV BIGINT, @AWT_DIV BIGINTSELECT @Loops = case when (@SecondsToRun % @RunIntervalSeconds) > 5 then @SecondsToRun / @RunIntervalSeconds + 1 else @SecondsToRun / @RunIntervalSeconds endSET @LoopCounter = 0SELECT @WaitForSeconds = CONVERT(varchar, DATEADD(s, @RunIntervalSeconds , 0), 114)SELECT @FileName = @LogFile + FORMAT ( GETDATE(), '-MM-dd-yyyy_m', 'en-US' ) + '.txt'--Create the File Handler and Open the FileEXECUTE sp_OACreate 'Scripting.FileSystemObject', @OACreate OUTEXECUTE sp_OAMethod @OACreate, 'OpenTextFile', @OAFile OUT, @FileName, 2, True, -2--Write the HeaderEXECUTE sp_OAMethod @OAFile, 'WriteLine', NULL,'Transactions/sec, Active Transactions, SQL Cache Memory (KB), Lock Requests/sec, Lock Timeouts/sec, Lock Waits/sec, Number of Deadlocks/sec, Average Wait Time (ms), Average Latch Wait Time (ms)'--Collect Initial Sample ValuesSET ANSI_WARNINGS OFFSELECT  @LastTPS= max(case when counter_name = 'Transactions/sec' then cntr_value end),  @LastLRS = max(case when counter_name = 'Lock Requests/sec' then cntr_value end),  @LastLTS = max(case when counter_name = 'Lock Timeouts/sec' then cntr_value end),  @LastLWS = max(case when counter_name = 'Lock Waits/sec' then cntr_value end),  @LastNDS = max(case when counter_name = 'Number of Deadlocks/sec' then cntr_value end),  @LastAWT = max(case when counter_name = 'Average Wait Time (ms)' then cntr_value end),  @LastAWT_Base = max(case when counter_name = 'Average Wait Time base' then cntr_value end),  @LastALWT = max(case when counter_name = 'Average Latch Wait Time (ms)' then cntr_value end),  @LastALWT_Base = max(case when counter_name = 'Average Latch Wait Time base' then cntr_value end)FROM sys.dm_os_performance_countersWHERE counter_name IN ('Transactions/sec','Lock Requests/sec','Lock Timeouts/sec','Lock Waits/sec','Number of Deadlocks/sec','Average Wait Time (ms)','Average Wait Time base','Average Latch Wait Time (ms)','Average Latch Wait Time base') AND instance_name IN( '_Total' ,'')SET ANSI_WARNINGS ONWHILE @LoopCounter<= @LoopsBEGINWAITFOR DELAY @WaitForSecondsSET ANSI_WARNINGS OFFSELECT  @TPS= max(case when counter_name = 'Transactions/sec' then cntr_value end)   ,  @Active = max(case when counter_name = 'Active Transactions' then cntr_value end)   ,  @SCM = max(case when counter_name = 'SQL Cache Memory (KB)' then cntr_value end)   ,  @LRS = max(case when counter_name = 'Lock Requests/sec' then cntr_value end)   ,  @LTS = max(case when counter_name = 'Lock Timeouts/sec' then cntr_value end)   ,  @LWS = max(case when counter_name = 'Lock Waits/sec' then cntr_value end)   ,  @NDS = max(case when counter_name = 'Number of Deadlocks/sec' then cntr_value end)   ,  @AWT = max(case when counter_name = 'Average Wait Time (ms)' then cntr_value end)   ,  @AWT_Base = max(case when counter_name = 'Average Wait Time base' then cntr_value end)   ,  @ALWT = max(case when counter_name = 'Average Latch Wait Time (ms)' then cntr_value end)   ,  @ALWT_Base = max(case when counter_name = 'Average Latch Wait Time base' then cntr_value end)FROM sys.dm_os_performance_countersWHERE counter_name IN ('Transactions/sec','Active Transactions','SQL Cache Memory (KB)','Lock Requests/sec','Lock Timeouts/sec','Lock Waits/sec','Number of Deadlocks/sec','Average Wait Time (ms)','Average Wait Time base','Average Latch Wait Time (ms)','Average Latch Wait Time base') AND instance_name IN( '_Total' ,'')SET ANSI_WARNINGS ONSELECT  @AWT_DIV = case when (@AWT_Base - @LastAWT_Base) > 0 then (@AWT_Base - @LastAWT_Base) else 1 end ,    @ALWT_DIV = case when (@ALWT_Base - @LastALWT_Base) > 0 then (@ALWT_Base - @LastALWT_Base) else 1 endSELECT @RowText = '' + convert(varchar, (@TPS - @LastTPS)/@RunIntervalSeconds) + ', ' +          convert(varchar, @Active) + ', ' +          convert(varchar, @SCM) + ', ' +          convert(varchar, (@LRS - @LastLRS)/@RunIntervalSeconds) + ', ' +          convert(varchar, (@LTS - @LastLTS)/@RunIntervalSeconds) + ', ' +          convert(varchar, (@LWS - @LastLWS)/@RunIntervalSeconds) + ', ' +          convert(varchar, (@NDS - @LastNDS)/@RunIntervalSeconds) + ', ' +          convert(varchar, (@AWT - @LastAWT)/@AWT_DIV) + ', ' +          convert(varchar, (@ALWT - @LastALWT)/@ALWT_DIV)SELECT  @LastTPS = @TPS,    @LastLRS = @LRS,    @LastLTS = @LTS,    @LastLWS = @LWS,    @LastNDS = @NDS,    @LastAWT = @AWT,    @LastAWT_Base = @AWT_Base,    @LastALWT = @ALWT,    @LastALWT_Base = @ALWT_BaseEXECUTE sp_OAMethod @OAFile, 'WriteLine', Null, @RowTextSET @LoopCounter = @LoopCounter + 1END--CLEAN UPEXECUTE sp_OADestroy @OAFileEXECUTE sp_OADestroy @OACreateprint 'Completed Logging Performance Metrics to file: ' + @FileNameENDGO

Running the TPROC-C load test

In SQL Server Management Studio, execute the collection procedure using thefollowing script:

Use masterGoexec dbo.sp_write_performance_counters

On the Compute Engine instance where you installed HammerDB, startthe test in the HammerDB application:

  1. In theBenchmark panel, underVirtual Users double-clickCreateto create the virtual users, which will activate theVirtual User Outputtab.
  2. Double-clickRun just below theCreate option to kick off the test.
  3. When the test completes you will see the Transactions Per Minute (TPM)calculation in theVirtual User Output tab.
  4. You can find the results from your collection procedure in thec:\Windows\temp directory.
  5. Save all of these values to a Google Sheet and use them to compare multipletest runs.

Clean up

After you finish the tutorial, you can clean up the resources that you created so that they stop using quota and incurring charges. The following sections describe how to delete or turn off these resources.

Deleting the project

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

To delete the project:

    Caution: Deleting a project has the following effects:
    • Everything in the project is deleted. If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
    • Custom project IDs are lost. When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as anappspot.com URL, delete selected resources inside the project instead of deleting the whole project.

    If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects can help you avoid exceeding project quota limits.

  1. In the Google Cloud console, go to theManage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then clickDelete.
  3. In the dialog, type the project ID, and then clickShut down to delete the project.

Deleting instances

To delete a Compute Engine instance:

  1. In the Google Cloud console, go to theVM instances page.

    Go to VM instances

  2. Select the checkbox for the instance that you want to delete.
  3. To delete the instance, clickMore actions, clickDelete, and then follow the instructions.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-09 UTC.