How-to find out the SQL MI number of CPU vCores

Published Jul 29 2021 05:23 AM 1,928 Views
Microsoft

Continuing with the series of blog posts on how to find out the necessary information about Azure SQL Managed Instance (SQL MI) for your automation scripts and tools, started with How-to find out the SQL MI Service Tier basic details with T-SQL, this article will focus on extracting information on the CPU vCores from Azure SQL Managed Instance.

 

You can find and reference the whole series with the following link http://aka.ms/sqlmi-howto.

 

There are multiple ways in determining the number of vCPU Cores in Azure SQL Managed Instance and we are providing you with a couple of them, since besides the used DMV, they vary in their security requirements – starting with VIEW SERVER STATE (the most common requirement) and going down to a much simpler access to the [master] database and the underlying SQL MI server resource statistics DMV.



Using sys.dm_os_nodes Dynamic Management View

For a lot of time, a traditional way of looking into the available hardware/virtualized resources on SQL Server was the sys.dm_os_nodes DMV, which shows the information on the SQLOS and mimic hardware processor locality. The sys.dm_os_nodes DMV gives details on such components as worker count, CPU & Scheduler affinity masks, and serves to determine average number of tasks per scheduler per node, thus allowing to determine a potential raise of pressure on the scheduler.

Using this DMV is a valid way for determining the number of available CPU vCores, like is being shown below - by listing ONLINE nodes only, while the details are stored in the [cpu_count] column:

 

 

SELECT 'This SQL Managed Instance has ' + CAST(cpu_count AS VARCHAR(10)) + ' CPU vCores.' as CPU_vCores
FROM sys.dm_os_nodes WITH (NOLOCK)
WHERE node_state_desc = N'ONLINE'
OPTION (RECOMPILE);

 

 

CPU vCores.pngThe result for my small Azure SQL MI with 4 CPU vCores is shown on the image on the left, representing text with information that there are indeed 4 CPU vCores.


Notice that currently a VIEW SERVER STATE permission is required in order to use this method.

 

Using sys.dm_os_schedulers Dynamic Management View

Another great way of determining the number of the CPU vCores is by using the DMV sys.dm_os_schedulers, which will list detailed information for each of the CPU schedulers, and each of the schedulers is mapped to an individual processor. To get the correct result, we are filtering just the schedulers that are visible online:

 

 

SELECT 'This SQL Managed Instance has ' + CAST(COUNT(*) AS VARCHAR(10)) + '  CPU vCores.' as CPU_vCores
FROM sys.dm_os_schedulers
WHERE status = 'VISIBLE ONLINE';

 

 

CPU vCores.pngThis query returns the same result is returned as previous one, delivering the correct information on the number CPU vCores.

Same as for the sys.dm_os_nodes DMV, a VIEW SERVER STATE permission is required to use this method.

 

Using sys.dm_os_job_object Dynamic Management View

The number of CPU vCores is also discoverable through the sys.dm_os_job_object DMV, that is at the moment of this article publishing is exclusive to our PaaS offerings - Azure SQL Database & Azure SQL Managed Instance. 

This DMV displays the information about the configuration of the Job Object where SQL Managed Instance is running, providing with details on the accessible resources. A job object is a Windows construct that implements CPU, memory, and IO resource governance at the operating system level. For more information about job objects, see Job Objects.

To get the information on the CPU vCores we need to use the [cpu_rate] column, dividing the output through 100.

 

 

SELECT 'This SQL Managed Instance has ' + CAST(cpu_rate / 100 AS VARCHAR(10)) + ' CPU Vcores.' as CPU_vCores
FROM sys.dm_os_job_object;

 

 

CPU vCores.pngSame as for both previous methods, a VIEW SERVER STATE permission is required to use this method.

 

 

Using sys.server_resource_stats DMV in the [master] database

The last method we shall consider in this post is the one that falls back to already known DMV - sys.server_resource_stats that returns CPU usage, IO, and storage data for Azure SQL Managed Instance. By extracting the last available data from the [virtual_core_count] column we shall obtain the desired information on the number of CPU vCores:

 

 

SELECT TOP(1) 'This SQL Managed Instance has ' + CAST(virtual_core_count AS VARCHAR(10)) + ' CPU vCores.' as CPU_vCores
FROM master.sys.server_resource_stats WITH (NOLOCK)
ORDER BY end_time DESC
OPTION (RECOMPILE);

 

 

CPU vCores.pngAn important distinction to this method is that it only requires the access to the [master] database and even though this one must be given very carefully, it is quite different from VIEW SERVER STATE and is a preferred way of getting the details on the CPU vCores, because it shows actual used detail, which was updated seconds/minutes ago.

In this blog post we have provided you with just 4 T-SQL scripts allowing you to extract the number of CPU vCores for your SQL MI environment. In the next post of this series, we shall focus on the memory.

%3CLINGO-SUB%20id%3D%22lingo-sub-2594971%22%20slang%3D%22en-US%22%3EHow-to%20find%20out%20the%20SQL%20MI%20number%20of%20CPU%20vCores%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2594971%22%20slang%3D%22en-US%22%3E%3CP%3EContinuing%20with%20the%20series%20of%20blog%20posts%20on%20how%20to%20find%20out%20the%20necessary%20information%20about%20Azure%20SQL%20Managed%20Instance%20(SQL%20MI)%20for%20your%20automation%20scripts%20and%20tools%2C%20started%20with%20%3CA%20title%3D%22How-to%20find%20out%20the%20SQL%20MI%20Service%20Tier%20basic%20details%20with%20T-SQL%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql%2Fhow-to-find-out-the-sql-mi-service-tier-basic-details-with-t-sql%2Fba-p%2F2520706%22%20target%3D%22_self%22%3EHow-to%20find%20out%20the%20SQL%20MI%20Service%20Tier%20basic%20details%20with%20T-SQL%3C%2FA%3E%2C%20this%20article%20will%20focus%20on%20extracting%20information%20on%20the%20vCPU%20cores%20from%20Azure%20SQL%20Managed%20Instance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20multiple%20ways%20in%20determining%20the%20number%20of%20vCPU%20Cores%20in%20Azure%20SQL%20Managed%20Instance%20and%20we%20are%20providing%20you%20with%20a%20couple%20of%20them%2C%20since%20besides%20the%20used%20DMV%2C%20they%20vary%20in%20their%20security%20requirements%20%E2%80%93%20starting%20with%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Fgrant-server-permissions-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EVIEW%20SERVER%20STATE%3C%2FA%3E%20(the%20most%20common%20requirement)%20and%20going%20down%20to%20a%20much%20simpler%20access%20to%20the%20%3CSTRONG%3E%5Bmaster%5D%3C%2FSTRONG%3E%20database%20and%20the%20underlying%20SQL%20MI%20server%20resource%20statistics%20DMV.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-2092151791%22%20id%3D%22toc-hId-2092152815%22%3E%3CBR%20%2F%3E%3CBR%20%2F%3EUsing%20sys.dm_os_nodes%20Dynamic%20Management%20View%3C%2FH3%3E%0A%3CP%3EFor%20a%20lot%20of%20time%2C%20a%20traditional%20way%20of%20looking%20into%20the%20available%20hardware%2Fvirtualized%20resources%20on%20SQL%20Server%20was%20the%20%3CA%20title%3D%22sys.dm_os_nodes%20DMV%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-nodes-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_nodes%3C%2FA%3E%26nbsp%3BDMV%2C%20which%20shows%20the%20information%20on%20the%20SQLOS%20and%20mimic%20hardware%20processor%20locality.%20The%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-nodes-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_nodes%3C%2FA%3E%26nbsp%3BDMV%20gives%20details%20on%20such%20components%20as%20worker%20count%2C%20CPU%20%26amp%3B%20Scheduler%20affinity%20masks%2C%20and%20serves%20to%20determine%20average%20number%20of%20tasks%20per%20scheduler%20per%20node%2C%20thus%20allowing%20to%20determine%20a%20potential%20raise%20of%20pressure%20on%20the%20scheduler.%3CBR%20%2F%3E%3CBR%20%2F%3EUsing%20this%20DMV%20is%20a%20valid%20way%20for%20determining%20the%20number%20of%20available%20CPU%20vCores%2C%20like%20is%20being%20shown%20below%20-%20by%20listing%20ONLINE%20nodes%20only%2C%20while%20the%20details%20are%20stored%20in%20the%20%5B%3CSTRONG%3Ecpu_count%3C%2FSTRONG%3E%5D%20column%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20'This%20SQL%20Managed%20Instance%20has%20'%20%2B%20CAST(cpu_count%20AS%20VARCHAR(10))%20%2B%20'%20CPU%20vCores.'%20as%20CPU_vCores%0AFROM%20sys.dm_os_nodes%20WITH%20(NOLOCK)%0AWHERE%20node_state_desc%20%3D%20N'ONLINE'%0AOPTION%20(RECOMPILE)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22CPU%20vCores.png%22%20style%3D%22width%3A%20247px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299184i0F54B46AA5DFDDAB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22CPU%20vCores.png%22%20alt%3D%22CPU%20vCores.png%22%20%2F%3E%3C%2FSPAN%3EThe%20result%20for%20my%20small%20Azure%20SQL%20MI%20with%204%20CPU%20vCores%20is%20shown%20on%20the%20image%20on%20the%20left%2C%20representing%20text%20with%20information%20that%20there%20are%20indeed%204%20CPU%20vCores.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3ENotice%20that%20currently%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Fgrant-server-permissions-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EVIEW%20SERVER%20STATE%3C%2FA%3E%20permission%20is%20required%20in%20order%20to%20use%20this%20method.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-284697328%22%20id%3D%22toc-hId-284698352%22%3EUsing%20sys.dm_os_schedulers%20Dynamic%20Management%20View%3C%2FH3%3E%0A%3CP%3EAnother%20great%20way%20of%20determining%20the%20number%20of%20the%20CPU%20vCores%20is%20by%20using%20the%20DMV%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-schedulers-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_schedulers%3C%2FA%3E%2C%20which%20will%20list%20detailed%20information%20for%20each%20of%20the%20CPU%20schedulers%2C%20and%20each%20of%20the%20schedulers%20is%20mapped%20to%20an%20individual%20processor.%20To%20get%20the%20correct%20result%2C%20we%20are%20filtering%20just%20the%20schedulers%20that%20are%20visible%20online%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20'This%20SQL%20Managed%20Instance%20has%20'%20%2B%20CAST(COUNT(*)%20AS%20VARCHAR(10))%20%2B%20'%20%20CPU%20vCores.'%20as%20CPU_vCores%0AFROM%20sys.dm_os_schedulers%0AWHERE%20status%20%3D%20'VISIBLE%20ONLINE'%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22CPU%20vCores.png%22%20style%3D%22width%3A%20247px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299184i0F54B46AA5DFDDAB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22CPU%20vCores.png%22%20alt%3D%22CPU%20vCores.png%22%20%2F%3E%3C%2FSPAN%3EThis%20query%20returns%20the%20same%20result%20is%20returned%20as%20previous%20one%2C%20delivering%20the%20correct%20information%20on%20the%20number%20CPU%20vCores.%3CBR%20%2F%3E%3CBR%20%2F%3ESame%20as%20for%20the%20%3CSTRONG%3Esys.dm_os_nodes%3C%2FSTRONG%3E%20DMV%2C%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Fgrant-server-permissions-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EVIEW%20SERVER%20STATE%3C%2FA%3E%20permission%20is%20required%20to%20use%20this%20method.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1522757135%22%20id%3D%22toc-hId--1522756111%22%3EUsing%20sys.dm_os_job_object%20Dynamic%20Management%20View%3C%2FH3%3E%0A%3CP%3EThe%20number%20of%20CPU%20vCores%20is%20also%20discoverable%20through%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-job-object-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_job_object%3C%2FA%3E%20DMV%2C%20that%20is%20at%20the%20moment%20of%20this%20article%20publishing%20is%20exclusive%20to%20our%20PaaS%20offerings%20-%20Azure%20SQL%20Database%20%26amp%3B%20Azure%20SQL%20Managed%20Instance.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20DMV%20displays%20the%20information%20about%20the%20configuration%20of%20the%20Job%20Object%20where%20SQL%20Managed%20Instance%20is%20running%2C%20providing%20with%20details%20on%20the%20accessible%20resources.%26nbsp%3B%3CSPAN%3EA%20job%20object%20is%20a%20Windows%20construct%20that%20implements%20CPU%2C%20memory%2C%20and%20IO%20resource%20governance%20at%20the%20operating%20system%20level.%20For%20more%20information%20about%20job%20objects%2C%20see%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fdesktop%2FProcThread%2Fjob-objects%22%20data-linktype%3D%22absolute-path%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EJob%20Objects%3C%2FA%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ETo%20get%20the%20information%20on%20the%20CPU%20vCores%20we%20need%20to%20use%20the%20%5B%3CSTRONG%3Ecpu_rate%3C%2FSTRONG%3E%5D%20column%2C%20dividing%20the%20output%20through%20100.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20'This%20SQL%20Managed%20Instance%20has%20'%20%2B%20CAST(cpu_rate%20%2F%20100%20AS%20VARCHAR(10))%20%2B%20'%20CPU%20Vcores.'%20as%20CPU_vCores%0AFROM%20sys.dm_os_job_object%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22CPU%20vCores.png%22%20style%3D%22width%3A%20247px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299184i0F54B46AA5DFDDAB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22CPU%20vCores.png%22%20alt%3D%22CPU%20vCores.png%22%20%2F%3E%3C%2FSPAN%3ESame%20as%20for%20both%20previous%20methods%2C%20a%20VIEW%20SERVER%20STATE%20permission%20is%20required%20to%20use%20this%20method.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-964755698%22%20id%3D%22toc-hId-964756722%22%3EUsing%20sys.server_resource_stats%20DMV%20in%20the%20%5Bmaster%5D%20database%3C%2FH3%3E%0A%3CP%3EThe%20last%20method%20we%20shall%20consider%20in%20this%20post%20is%20the%20one%20that%20falls%20back%20to%20already%20known%20DMV%20-%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-catalog-views%2Fsys-server-resource-stats-azure-sql-database%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.server_resource_stats%3C%2FA%3E%26nbsp%3Bthat%20r%3CSPAN%3Eeturns%20CPU%20usage%2C%20IO%2C%20and%20storage%20data%20for%20Azure%20SQL%20Managed%20Instance.%20By%20extracting%20the%20last%20available%20data%20from%20the%20%5B%3CSTRONG%3Evirtual_core_count%3C%2FSTRONG%3E%5D%20column%20we%20shall%20obtain%20the%20desired%20information%20on%20the%20number%20of%20CPU%20vCores%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20TOP(1)%20'This%20SQL%20Managed%20Instance%20has%20'%20%2B%20CAST(virtual_core_count%20AS%20VARCHAR(10))%20%2B%20'%20CPU%20vCores.'%20as%20CPU_vCores%0AFROM%20master.sys.server_resource_stats%20WITH%20(NOLOCK)%0AORDER%20BY%20end_time%20DESC%0AOPTION%20(RECOMPILE)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22CPU%20vCores.png%22%20style%3D%22width%3A%20247px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299184i0F54B46AA5DFDDAB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22CPU%20vCores.png%22%20alt%3D%22CPU%20vCores.png%22%20%2F%3E%3C%2FSPAN%3EAn%20important%20distinction%20to%20this%20method%20is%20that%20it%20only%20requires%20the%20access%20to%20the%20%5Bmaster%5D%20database%20and%20even%20though%20this%20one%20must%20be%20given%20very%20carefully%2C%20it%20is%20quite%20different%20from%20VIEW%20SERVER%20STATE%20and%20is%20a%20preferred%20way%20of%20getting%20the%20details%20on%20the%20CPU%20vCores%2C%20because%20it%20shows%20actual%20used%20detail%2C%20which%20was%20updated%20seconds%2Fminutes%20ago.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIn%20this%20blog%20post%20we%20have%20provided%20you%20with%20just%204%20T-SQL%20scripts%20allowing%20you%20to%20extract%20the%20number%20of%20CPU%20vCores%20for%20your%20SQL%20MI%20environment.%20In%20the%20next%20post%20of%20this%20series%2C%20we%20shall%20focus%20on%20the%20memory.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2594971%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22CPU%20vCores.png%22%20style%3D%22width%3A%20247px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299184i0F54B46AA5DFDDAB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22CPU%20vCores.png%22%20alt%3D%22CPU%20vCores.png%22%20%2F%3E%3C%2FSPAN%3EDiscover%204%20different%20ways%20of%20finding%20out%20the%20number%20of%20CPU%20vCores%20in%20Azure%20SQL%20Managed%20Instance%20with%20the%20help%20of%20T-SQL.%20With%20the%20help%20of%204%20different%20DMVs%20and%202%20access%20methods%20(VIEW%20SERVER%20STATE)%20and%20access%20to%20the%20%5Bmaster%5D%20database%2C%20obtain%20your%20current%20CPU%20configuration%20for%20your%20needs%2C%20such%20as%20reporting%20or%20performance%20tuning%2C%20for%20example.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2594971%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20SQL%20Managed%20Instance%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Sep 21 2021 07:10 AM
Updated by:
www.000webhost.com