You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: samples/features/in-memory-database/memory-optimized-tempdb-metadata/MemoryOptimizedTempDBMetadata-TSQL.ipynb
"TempDB metadata contention has historically been a bottleneck to scalability for many workloads running on SQL Server. SQL Server 2019 introduces a new feature that is part of the [In-Memory Database](https://docs.microsoft.com/sql/relational-databases/in-memory-database) feature family, memory-optimized tempdb metadata, which effectively removes this bottleneck and unlocks a new level of scalability for tempdb-heavy workloads. In SQL Server 2019, the system tables involved in managing temp table metadata can be moved into latch-free non-durable memory-optimized tables.\r\n",
29
+
"\r\n",
30
+
"To learn more about tempdb metadata contention, along with other types of tempdb contention, check out the blog article [TEMPDB - Files and Trace Flags and Updates, Oh My!](https://techcommunity.microsoft.com/t5/SQL-Server/TEMPDB-Files-and-Trace-Flags-and-Updates-Oh-My/ba-p/385937). Keep reading to explore the new memory-optimized tempdb metadata feature."
"Contention in tempdb happens when a large number of concurrent threads are attemping to create, modify or drop temp tables. In order to simulate this situation, you'll need to have a SQL Server instance that has multiple cores (4 or more is recommended), and a way to simulate multiple concurrent threads. For this example, we'll be using the ostress.exe tool to generate multiple concurrent threads. If you have an existing multi-core SQL Server instance, you can follow the T-SQL instructions to set up the demo, otherwise you can try the docker container steps instead. \r\n",
42
+
"\r\n",
43
+
"First, download the demo files to your local computer.\r\n",
44
+
"\r\n",
45
+
"### Docker Container Setup\r\n",
46
+
"Note that the docker commands may take some time to execute, but you will not see progress here until they are complete.\r\n",
47
+
"\r\n",
48
+
"1. Make sure you have your docker environment configured, more information [here](https://docs.docker.com/get-started/). \r\n",
49
+
"> NOTE\r\n",
50
+
"> <br>If you are using Docker Desktop for Windows or Mac, the default configuration will limit your containers to 2 cores, regardless of the number of cores on your computer. Be sure to configure docker to allow at least 4 cores and 4GB of RAM for this demo to run properly. To do this, right click on the Docker Desktop icon in the status bar and choose Settings -> Advanced.\r\n",
51
+
"2. Pull the demo container with the following command:"
"text": "Using default tag: latest\nlatest: Pulling from bluefooted/sql2019tempdbdemo\nDigest: sha256:035a1bda5539bfe68ad1b2f032a6e389cea91a0cd880e75b83ef186c46b2e34f\nStatus: Image is up to date for bluefooted/sql2019tempdbdemo:latest\ndocker.io/bluefooted/sql2019tempdbdemo:latest\n",
69
+
"output_type": "stream"
70
+
}
71
+
],
72
+
"execution_count": 3
73
+
},
74
+
{
75
+
"cell_type": "markdown",
76
+
"source": [
77
+
"3. Start the demo container with the following command:"
"> <br> If you see the following error, you may already have run the docker run command with this image:\r\n",
105
+
"<br> <br> *docker: Error response from daemon: Conflict. The container name \"/sql2019tempdbdemo\" is already in use by container \"3f662e0fd9b8cbdc1013e874722e066aa8e81ec3a07423fc3ab95cb75e640af9\". You have to remove (or rename) that container to be able to reuse that name.\r\n",
106
+
"See 'docker run --help'.*\r\n",
107
+
"\r\n",
108
+
"If you see this message, you can start the container instead with the following command:"
"### Existing SQL Server Instance Setup (skip if you are using the demo container)\r\n",
142
+
"\r\n",
143
+
"If you already have a SQL Server instance with a minimum of 4 cores, you can download and restore the AdventureWorks database and use the scripts in this repo to configure the database. Follow the steps in the T-SQL notebook to complete this setup.\r\n",
"The first thing to figure out before you turn on this new feature is whether or not you are experiencing TempDB metadata contention. The main symptom of this contention is a number of sessions in `Suspended` state with a wait type of `PAGELATCH_xx` and a wait resource of a page that hosts a TempDB system table, such as `2:1:118`. In order to know whether or not the page is part of a TempDB system table, you can use the new dynamic management function `sys.dm_db_page_info()` in SQL Server 2019 or later, or the older `DBCC PAGE` command in older versions. For this demo, let's focus on `sys.dm_db_page_info()`. Note that this command will take some time to complete, you'll want to proceed to the next step before it completes.\r\n",
156
+
"\r\n",
157
+
"First, start the workload using the `ostress.exe` tool that is included in the downloads. Note that if you are not using the demo container, you will need to change the server name and login information."
"While the above script is running, switch over to the T-SQL notebook and run the script to monitor your workload for page contention. You should see several sessions with a `wait_type` of `PAGELATCH_EX` or `PAGELATCH_SH`, often with an `object_name` of `sysschobjs`.\r\n",
184
+
"\r\n",
185
+
"> NOTE\r\n",
186
+
"> <br>If this query does not return any results, make sure the command above is still running. If it is not running, start it and try the query again. If you still do not see any sessions waiting, you may need to increase the number of CPUs available to your server, and/or increase the number of concurrent threads by increasing the `-n` parameter in the command. This demo was tested with 4 cores and 16 concurrent sessions, which should yield the expected results. If you would like more time to examine the contention, you can increase the `-r` parameter, which will increase the number of iterations."
"## Improve performance with Memory-Optimized TempDB Metadata\r\n",
196
+
"\r\n",
197
+
"Now that you have observed TempDB metadata contention, let's see how SQL Server 2019 addresses this contention. Switch over to the T-SQL notebook to review and run the script to enable Memory-Optimized TempDB Metadata.\r\n",
198
+
"\r\n",
199
+
"Once you have run the T-SQL command, you will need to restart the service. If you are using the demo container, you can do so with the following command:"
"Once the server is restarted, you can use queries in the T-SQL notebook to verify that the feature has been enabled.\r\n",
226
+
"\r\n",
227
+
"> NOTE\r\n",
228
+
"> <br> It's a good idea to run a few T-SQL queries after the restart to make sure the server is up and running before you attempt the scenario again.\r\n",
229
+
"\r\n",
230
+
"Now that we have enabled Memory-Optimized TempDB Metadata, let's try running the workload again:"
"While this is running, switch over to the T-SQL notebook to run the monitoring script again. This time, you should not see any sessions waiting on `PAGELATCH_EX` or `PAGELATCH_SH`. Also, the script should complete faster than before the change was made."
0 commit comments