Windows OS Quantum vs. SQL OS QuantumSQL Server starts normally from Windows Services screen, but shows error through SQL Server Configuration Manager. Why?Very High wait time?SQL Server 2014 SP1 Setup Freezes Removing Temporary Files On Windows 10 x64Correct way to stop SQL Server (through automation)Unable To Log In Through Windows AuthenticationMuch slower SQL application performance after upgrading from Windows Server 2008 R2 to Windows Server 2012 R2Is Windows 10 compatible with SQL Server 2014 Developer MDS?Non-Yielding scheduler errorsNon-yielding Scheduler Error with dump caused by heavy queries on SQL 2016SQL Server Processor affinity with trace flag 8002 ON

How to redirect stdout to a file, and stdout+stderr to another one?

Do not cross the line!

Are Allah and Hashem one and the same?

Is this a group? If so, what group is it?

Will casting a card from the graveyard with Flashback add a quest counter on Pyromancer Ascension?

Alias for root of a polynomial

Why does the headset man not get on the tractor?

What information exactly does an instruction cache store?

Is it safe to use two single-pole breakers for a 240v circuit?

Can I say: "When was your train leaving?" if the train leaves in the future?

Is Valonqar prophecy unfulfilled?

Holding rent money for my friend which amounts to over $10k?

Under what charges was this character executed in Game of Thrones, The Bells?

Find the unknown area, x

Why does SSL Labs now consider CBC suites weak?

Was the dragon prowess intentionally downplayed in S08E04?

Extract the characters before last colon

Is there any way to adjust the damage type of the Eldritch Blast cantrip so that it does fire damage?

Can only the master initiate communication in SPI whereas in I2C the slave can also initiate the communication?

Can my Serbian girlfriend apply for a UK Standard Visitor visa and stay for the whole 6 months?

Is this possible when it comes to the relations of P, NP, NP-Hard and NP-Complete?

Motorola 6845 and bitwise graphics

How to describe a building set which is like LEGO without using the "LEGO" word?

Do Grothendieck universes matter for an algebraic geometer?



Windows OS Quantum vs. SQL OS Quantum


SQL Server starts normally from Windows Services screen, but shows error through SQL Server Configuration Manager. Why?Very High wait time?SQL Server 2014 SP1 Setup Freezes Removing Temporary Files On Windows 10 x64Correct way to stop SQL Server (through automation)Unable To Log In Through Windows AuthenticationMuch slower SQL application performance after upgrading from Windows Server 2008 R2 to Windows Server 2012 R2Is Windows 10 compatible with SQL Server 2014 Developer MDS?Non-Yielding scheduler errorsNon-yielding Scheduler Error with dump caused by heavy queries on SQL 2016SQL Server Processor affinity with trace flag 8002 ON






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








16















Simple Question



How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)?



Simple Question Explained



After 184 ms of OS quantum being used (which corresponds to 46 full SQL quantums) the OS quantum has 3.5 ms of time before it will have to hand over the schedule to a different process. The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




Deep Dive on OS Quantum



In the next couple of sections I'll write up what I have found so far regarding the OS quantum and how the duration of a quantum can be calculated. The duration of an OS "quantum" is based on "ticks" and the duration of the "tick" itself is based on the "clock interval" which is normally 15.625000 ms. But let me elaborate a bit...



Tick



In the Blog article Know Thy Tick the author Jim explains the basics of clock intervals (aka "ticks") and what they are for.




When I read something like “the clock interval… for most x86 multiprocessors is about 15 milliseconds” I’m compelled to determine the value of my clock, or “tick”, interval. Fortunately, the book I read this quote in, Windows Internals Fourth Edition provides a reference for helping me with my affliction.
...
The author, Mark Russinovich, of the aforementioned book has graciously made the utility ClockRes available on his web site. Running this utility, I was able to determine that the clock interval on my x86 multiprocessor PC is 15.625000 ms. Interesting, but my curious mind wants to know more.




Quantum



The author of the article goes on to explain in his second article that...




Of course the real reason why the tick interval is important is that it affects thread scheduling. The Windows scheduler gives each thread a “quantum” of time to execute before allowing another task, at the same priority level, to run. The quantum that the scheduler assigns to a thread is a multiple of the tick interval. The specific quantum value chosen for a specific thread is bit beyond where I want to go with this article.




Ok, so I know what a quantum is, but not how long a quantum will run.




For now, let’s just examine the default quantum value for a foreground thread in XPe. In this case the Windows scheduler assigns a quantum of 18 or 6 tick intervals. (Yes, to convert quantum to tick intervals, one must divide by 3. ..., but the reason for the multiple is to allow the scheduler the ability to “charge” a thread for doing an operation which causes it to suspend.)




We now know that a clock interval (tick) should be around 15.625000 ms and on a Windows Desktop OS where the default quantum is 18 that this will result in 6 ticks or 93.750000 ms (18 / 3 * 15.625000 ms).



On a Windows Server OS the default quantum is different. The "Processor scheduling" setting is set to "Background Services"



This setting can be found via "System Settings | Advanced (tab) | Performance (section) | Settings ..." which will open "Perofrmance Options | Advanced (tab) | Processor scheduling"



The default quantum settings are then 36 (Background) to 36 (Foreground). The quantum is larger and hence longer. This is double the amount of the 93.750000 ms of the 18 (6 tick) quantum foreground setting on a Windows Desktop OS, which on a server OS set up for Background Services is around 187.500000 ms.



Observation / Explanation



When you change the setting from "Background services" to "Applicaitons" on either a server or desktop, then the HKLMSYSTEM CurrentControlSet Control PriorityControl Win32PrioritySeparation key in the registry is changed from 0x18 to 0x02. What is the default quantum value for 0x02? This can be found in a comment:




The value 0x02 implies that the "Short vs. Long" and "Variable vs. Fixed" fields are the default for the OS.



The default for these fields for XPe & XP Pro is: Short & Variable which is the same as having the following bits additional bits set: 0x24.



OR'ing this value in with 0x02 gives you 0x26, which you will find in the table in the article.




Reference: Comment to "Master Your Quantum" (MSDN Blogs)



The table explaining the quantum settings from the same article:



Win32PrioritySeparation Foreground Background
0x28, 0x29, 0x2A 18 18
0x18, 0x19, 0x1A 36 36
0x24 6 6
0x25, 0x14 12 6
0x26 18 6
0x15 24 6
0x16 36 6


Short Summary of OS Quantum



Based on the above information and article quotes, we know that a quantum is not a fixed size, but rather derived from an OS setting in the System Properties. A quantum varies depending on the Win32PrioritySeparation setting in the registry which normally corresponds to one of the setting in the "System Properties" (either "Background services" or "Applications").



A quantum at OS level is



  • for the "Applications" setting

    • 18 (which is 6 ticks) for foreground applications (93.75 ms)

    • 6 (which is 2 ticks) for background applications (31.25 ms)


  • for the "Background Services" setting

    • 36 (which is 18 ticks) for foreground applications (187.5 ms)

    • 36 (which is 18 ticks) for background applications (187.5 ms)


So now we know that an OS quantum on a Windows Server setup to be optimised for Background Services is ...



36 / 3 * 15.625000 ms = 187.5 ms



SQL OS Quantum



This section lists what I have found on SQL OS quantum...



SOS_SCHEDULER_YIELD Wait Type



From Paul Randall's description on the SOS_SCHEDULER_YIELD wait type:




This wait type is when a thread was able to execute for its full thread quantum (4 milliseconds in all versions of SQL Server, unchangeable), and so voluntarily yielded the scheduler, moving to the bottom of the Runnable Queue in its scheduler.




Reference: SOS_SCHEDULER_YIELD (SQLSkills.com Wait Types)



Schedulers in SQL Server DMVs



In an explanation on SQL Server DMVs for the sys.dm_os_schedulers DMV.




[...] Windows uses a preemptive scheduling mechanism and assigns a quantum of CPU time to every thread, when a thread consumes its quantum it is sent to a queue and other threads are granted execution.



In opposition, SQL Server uses a cooperative scheduling mechanism when threads can voluntary yield its quantum of time (you can see this behavior when you have a SOS_SCHEDULER_YIELD wait type). This allows SQL Server to optimize CPU utilization, because when a thread is signaled for execution but is not ready to run it can yield its quantum of time in favor of other threads.




Reference: Understanding SQL Server Schedulers, Workers and Tasks (MSSQLTips.com)



Detect SQL Server CPU Pressure



This is a very small section of an article regarding CPU pressure in SQL Server.




Occurs when a task voluntarily yields the scheduler for other tasks to execute. During this wait the task is waiting for its quantum to be renewed.




Reference: Detect SQL Server CPU Pressure (MSSQLTips.com)



sys.dm_os_schedulers (Microsoft Docs)



I guess the following quote is the most important snippet of information regarding SQL OS quantum that I could find:




quantum_length_us bigint Identified for informational purposes only. 
Not supported. Future compatibility is not guaranteed.
Exposes the scheduler quantum used by SQLOS.



Reference: sys.dm_os_schedulers (Transact-SQL) (Microsoft | Docs)




My Conundrum



The Server OS Quantum regulates how much time the SQL Server Service is granted to execute "tasks". The SQL Server OS Quantum is defined as 4 ms. If I divide the 187.5 ms by 4 ms then I am left with 3.5 ms.



And we haven't even started the discussion of when the Clock Interval is set to something other than the default of 15.625000 ms....



Simple Question



How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)?



Simple Question Explained



After 184 ms of OS quantum being used (which corresponds to 46 full SQL quantums) the OS quantum has 3.5 ms of time before it will have to hand over the schedule to a different process. The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?










share|improve this question
























  • How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)? It's not and SQL Server doesn't use preemptive scheduling. Work items are expected to hit yield points and if they don't, you get things such as NONYIELDING schedulers. There is no parity.

    – Sean Gallardy
    May 9 at 16:40











  • So how do they not work together? If the SQL Server executable receives its quantum from the Windows OS, how does SQL Server distribute that quantum to the schedulers for the SQL Server OS "quantum"? Or is there an overhead in the Windows OS quantum that doesn't get used by SQL Server? Would it be better to change the Clock Resolution (in the registry) so that the value isn't some obscure 15.625000 ms, but instead 10.000000 ms?

    – hot2use
    May 10 at 6:33












  • I have added additional information regarding the SQL OS quantum which I found in the Microsoft Docs for sys.dm_os_schedulers.

    – hot2use
    May 10 at 9:53











  • I think the answer is fairly banal: When the OS quantum expires the thread is forcefully descheduled. This is transparent to SQL Server. SQLOS has no way of detecting when this happens. There is no Win32 API for that. Scheduling is transparent to user mode threads.

    – usr
    May 10 at 9:59











  • The Windows scheduler does not know or care what user mode threads are doing. Windows only sees threads that are runnable and lets them run till the end of their OS quantum or until they block.

    – usr
    May 10 at 10:01

















16















Simple Question



How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)?



Simple Question Explained



After 184 ms of OS quantum being used (which corresponds to 46 full SQL quantums) the OS quantum has 3.5 ms of time before it will have to hand over the schedule to a different process. The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




Deep Dive on OS Quantum



In the next couple of sections I'll write up what I have found so far regarding the OS quantum and how the duration of a quantum can be calculated. The duration of an OS "quantum" is based on "ticks" and the duration of the "tick" itself is based on the "clock interval" which is normally 15.625000 ms. But let me elaborate a bit...



Tick



In the Blog article Know Thy Tick the author Jim explains the basics of clock intervals (aka "ticks") and what they are for.




When I read something like “the clock interval… for most x86 multiprocessors is about 15 milliseconds” I’m compelled to determine the value of my clock, or “tick”, interval. Fortunately, the book I read this quote in, Windows Internals Fourth Edition provides a reference for helping me with my affliction.
...
The author, Mark Russinovich, of the aforementioned book has graciously made the utility ClockRes available on his web site. Running this utility, I was able to determine that the clock interval on my x86 multiprocessor PC is 15.625000 ms. Interesting, but my curious mind wants to know more.




Quantum



The author of the article goes on to explain in his second article that...




Of course the real reason why the tick interval is important is that it affects thread scheduling. The Windows scheduler gives each thread a “quantum” of time to execute before allowing another task, at the same priority level, to run. The quantum that the scheduler assigns to a thread is a multiple of the tick interval. The specific quantum value chosen for a specific thread is bit beyond where I want to go with this article.




Ok, so I know what a quantum is, but not how long a quantum will run.




For now, let’s just examine the default quantum value for a foreground thread in XPe. In this case the Windows scheduler assigns a quantum of 18 or 6 tick intervals. (Yes, to convert quantum to tick intervals, one must divide by 3. ..., but the reason for the multiple is to allow the scheduler the ability to “charge” a thread for doing an operation which causes it to suspend.)




We now know that a clock interval (tick) should be around 15.625000 ms and on a Windows Desktop OS where the default quantum is 18 that this will result in 6 ticks or 93.750000 ms (18 / 3 * 15.625000 ms).



On a Windows Server OS the default quantum is different. The "Processor scheduling" setting is set to "Background Services"



This setting can be found via "System Settings | Advanced (tab) | Performance (section) | Settings ..." which will open "Perofrmance Options | Advanced (tab) | Processor scheduling"



The default quantum settings are then 36 (Background) to 36 (Foreground). The quantum is larger and hence longer. This is double the amount of the 93.750000 ms of the 18 (6 tick) quantum foreground setting on a Windows Desktop OS, which on a server OS set up for Background Services is around 187.500000 ms.



Observation / Explanation



When you change the setting from "Background services" to "Applicaitons" on either a server or desktop, then the HKLMSYSTEM CurrentControlSet Control PriorityControl Win32PrioritySeparation key in the registry is changed from 0x18 to 0x02. What is the default quantum value for 0x02? This can be found in a comment:




The value 0x02 implies that the "Short vs. Long" and "Variable vs. Fixed" fields are the default for the OS.



The default for these fields for XPe & XP Pro is: Short & Variable which is the same as having the following bits additional bits set: 0x24.



OR'ing this value in with 0x02 gives you 0x26, which you will find in the table in the article.




Reference: Comment to "Master Your Quantum" (MSDN Blogs)



The table explaining the quantum settings from the same article:



Win32PrioritySeparation Foreground Background
0x28, 0x29, 0x2A 18 18
0x18, 0x19, 0x1A 36 36
0x24 6 6
0x25, 0x14 12 6
0x26 18 6
0x15 24 6
0x16 36 6


Short Summary of OS Quantum



Based on the above information and article quotes, we know that a quantum is not a fixed size, but rather derived from an OS setting in the System Properties. A quantum varies depending on the Win32PrioritySeparation setting in the registry which normally corresponds to one of the setting in the "System Properties" (either "Background services" or "Applications").



A quantum at OS level is



  • for the "Applications" setting

    • 18 (which is 6 ticks) for foreground applications (93.75 ms)

    • 6 (which is 2 ticks) for background applications (31.25 ms)


  • for the "Background Services" setting

    • 36 (which is 18 ticks) for foreground applications (187.5 ms)

    • 36 (which is 18 ticks) for background applications (187.5 ms)


So now we know that an OS quantum on a Windows Server setup to be optimised for Background Services is ...



36 / 3 * 15.625000 ms = 187.5 ms



SQL OS Quantum



This section lists what I have found on SQL OS quantum...



SOS_SCHEDULER_YIELD Wait Type



From Paul Randall's description on the SOS_SCHEDULER_YIELD wait type:




This wait type is when a thread was able to execute for its full thread quantum (4 milliseconds in all versions of SQL Server, unchangeable), and so voluntarily yielded the scheduler, moving to the bottom of the Runnable Queue in its scheduler.




Reference: SOS_SCHEDULER_YIELD (SQLSkills.com Wait Types)



Schedulers in SQL Server DMVs



In an explanation on SQL Server DMVs for the sys.dm_os_schedulers DMV.




[...] Windows uses a preemptive scheduling mechanism and assigns a quantum of CPU time to every thread, when a thread consumes its quantum it is sent to a queue and other threads are granted execution.



In opposition, SQL Server uses a cooperative scheduling mechanism when threads can voluntary yield its quantum of time (you can see this behavior when you have a SOS_SCHEDULER_YIELD wait type). This allows SQL Server to optimize CPU utilization, because when a thread is signaled for execution but is not ready to run it can yield its quantum of time in favor of other threads.




Reference: Understanding SQL Server Schedulers, Workers and Tasks (MSSQLTips.com)



Detect SQL Server CPU Pressure



This is a very small section of an article regarding CPU pressure in SQL Server.




Occurs when a task voluntarily yields the scheduler for other tasks to execute. During this wait the task is waiting for its quantum to be renewed.




Reference: Detect SQL Server CPU Pressure (MSSQLTips.com)



sys.dm_os_schedulers (Microsoft Docs)



I guess the following quote is the most important snippet of information regarding SQL OS quantum that I could find:




quantum_length_us bigint Identified for informational purposes only. 
Not supported. Future compatibility is not guaranteed.
Exposes the scheduler quantum used by SQLOS.



Reference: sys.dm_os_schedulers (Transact-SQL) (Microsoft | Docs)




My Conundrum



The Server OS Quantum regulates how much time the SQL Server Service is granted to execute "tasks". The SQL Server OS Quantum is defined as 4 ms. If I divide the 187.5 ms by 4 ms then I am left with 3.5 ms.



And we haven't even started the discussion of when the Clock Interval is set to something other than the default of 15.625000 ms....



Simple Question



How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)?



Simple Question Explained



After 184 ms of OS quantum being used (which corresponds to 46 full SQL quantums) the OS quantum has 3.5 ms of time before it will have to hand over the schedule to a different process. The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?










share|improve this question
























  • How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)? It's not and SQL Server doesn't use preemptive scheduling. Work items are expected to hit yield points and if they don't, you get things such as NONYIELDING schedulers. There is no parity.

    – Sean Gallardy
    May 9 at 16:40











  • So how do they not work together? If the SQL Server executable receives its quantum from the Windows OS, how does SQL Server distribute that quantum to the schedulers for the SQL Server OS "quantum"? Or is there an overhead in the Windows OS quantum that doesn't get used by SQL Server? Would it be better to change the Clock Resolution (in the registry) so that the value isn't some obscure 15.625000 ms, but instead 10.000000 ms?

    – hot2use
    May 10 at 6:33












  • I have added additional information regarding the SQL OS quantum which I found in the Microsoft Docs for sys.dm_os_schedulers.

    – hot2use
    May 10 at 9:53











  • I think the answer is fairly banal: When the OS quantum expires the thread is forcefully descheduled. This is transparent to SQL Server. SQLOS has no way of detecting when this happens. There is no Win32 API for that. Scheduling is transparent to user mode threads.

    – usr
    May 10 at 9:59











  • The Windows scheduler does not know or care what user mode threads are doing. Windows only sees threads that are runnable and lets them run till the end of their OS quantum or until they block.

    – usr
    May 10 at 10:01













16












16








16


4






Simple Question



How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)?



Simple Question Explained



After 184 ms of OS quantum being used (which corresponds to 46 full SQL quantums) the OS quantum has 3.5 ms of time before it will have to hand over the schedule to a different process. The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




Deep Dive on OS Quantum



In the next couple of sections I'll write up what I have found so far regarding the OS quantum and how the duration of a quantum can be calculated. The duration of an OS "quantum" is based on "ticks" and the duration of the "tick" itself is based on the "clock interval" which is normally 15.625000 ms. But let me elaborate a bit...



Tick



In the Blog article Know Thy Tick the author Jim explains the basics of clock intervals (aka "ticks") and what they are for.




When I read something like “the clock interval… for most x86 multiprocessors is about 15 milliseconds” I’m compelled to determine the value of my clock, or “tick”, interval. Fortunately, the book I read this quote in, Windows Internals Fourth Edition provides a reference for helping me with my affliction.
...
The author, Mark Russinovich, of the aforementioned book has graciously made the utility ClockRes available on his web site. Running this utility, I was able to determine that the clock interval on my x86 multiprocessor PC is 15.625000 ms. Interesting, but my curious mind wants to know more.




Quantum



The author of the article goes on to explain in his second article that...




Of course the real reason why the tick interval is important is that it affects thread scheduling. The Windows scheduler gives each thread a “quantum” of time to execute before allowing another task, at the same priority level, to run. The quantum that the scheduler assigns to a thread is a multiple of the tick interval. The specific quantum value chosen for a specific thread is bit beyond where I want to go with this article.




Ok, so I know what a quantum is, but not how long a quantum will run.




For now, let’s just examine the default quantum value for a foreground thread in XPe. In this case the Windows scheduler assigns a quantum of 18 or 6 tick intervals. (Yes, to convert quantum to tick intervals, one must divide by 3. ..., but the reason for the multiple is to allow the scheduler the ability to “charge” a thread for doing an operation which causes it to suspend.)




We now know that a clock interval (tick) should be around 15.625000 ms and on a Windows Desktop OS where the default quantum is 18 that this will result in 6 ticks or 93.750000 ms (18 / 3 * 15.625000 ms).



On a Windows Server OS the default quantum is different. The "Processor scheduling" setting is set to "Background Services"



This setting can be found via "System Settings | Advanced (tab) | Performance (section) | Settings ..." which will open "Perofrmance Options | Advanced (tab) | Processor scheduling"



The default quantum settings are then 36 (Background) to 36 (Foreground). The quantum is larger and hence longer. This is double the amount of the 93.750000 ms of the 18 (6 tick) quantum foreground setting on a Windows Desktop OS, which on a server OS set up for Background Services is around 187.500000 ms.



Observation / Explanation



When you change the setting from "Background services" to "Applicaitons" on either a server or desktop, then the HKLMSYSTEM CurrentControlSet Control PriorityControl Win32PrioritySeparation key in the registry is changed from 0x18 to 0x02. What is the default quantum value for 0x02? This can be found in a comment:




The value 0x02 implies that the "Short vs. Long" and "Variable vs. Fixed" fields are the default for the OS.



The default for these fields for XPe & XP Pro is: Short & Variable which is the same as having the following bits additional bits set: 0x24.



OR'ing this value in with 0x02 gives you 0x26, which you will find in the table in the article.




Reference: Comment to "Master Your Quantum" (MSDN Blogs)



The table explaining the quantum settings from the same article:



Win32PrioritySeparation Foreground Background
0x28, 0x29, 0x2A 18 18
0x18, 0x19, 0x1A 36 36
0x24 6 6
0x25, 0x14 12 6
0x26 18 6
0x15 24 6
0x16 36 6


Short Summary of OS Quantum



Based on the above information and article quotes, we know that a quantum is not a fixed size, but rather derived from an OS setting in the System Properties. A quantum varies depending on the Win32PrioritySeparation setting in the registry which normally corresponds to one of the setting in the "System Properties" (either "Background services" or "Applications").



A quantum at OS level is



  • for the "Applications" setting

    • 18 (which is 6 ticks) for foreground applications (93.75 ms)

    • 6 (which is 2 ticks) for background applications (31.25 ms)


  • for the "Background Services" setting

    • 36 (which is 18 ticks) for foreground applications (187.5 ms)

    • 36 (which is 18 ticks) for background applications (187.5 ms)


So now we know that an OS quantum on a Windows Server setup to be optimised for Background Services is ...



36 / 3 * 15.625000 ms = 187.5 ms



SQL OS Quantum



This section lists what I have found on SQL OS quantum...



SOS_SCHEDULER_YIELD Wait Type



From Paul Randall's description on the SOS_SCHEDULER_YIELD wait type:




This wait type is when a thread was able to execute for its full thread quantum (4 milliseconds in all versions of SQL Server, unchangeable), and so voluntarily yielded the scheduler, moving to the bottom of the Runnable Queue in its scheduler.




Reference: SOS_SCHEDULER_YIELD (SQLSkills.com Wait Types)



Schedulers in SQL Server DMVs



In an explanation on SQL Server DMVs for the sys.dm_os_schedulers DMV.




[...] Windows uses a preemptive scheduling mechanism and assigns a quantum of CPU time to every thread, when a thread consumes its quantum it is sent to a queue and other threads are granted execution.



In opposition, SQL Server uses a cooperative scheduling mechanism when threads can voluntary yield its quantum of time (you can see this behavior when you have a SOS_SCHEDULER_YIELD wait type). This allows SQL Server to optimize CPU utilization, because when a thread is signaled for execution but is not ready to run it can yield its quantum of time in favor of other threads.




Reference: Understanding SQL Server Schedulers, Workers and Tasks (MSSQLTips.com)



Detect SQL Server CPU Pressure



This is a very small section of an article regarding CPU pressure in SQL Server.




Occurs when a task voluntarily yields the scheduler for other tasks to execute. During this wait the task is waiting for its quantum to be renewed.




Reference: Detect SQL Server CPU Pressure (MSSQLTips.com)



sys.dm_os_schedulers (Microsoft Docs)



I guess the following quote is the most important snippet of information regarding SQL OS quantum that I could find:




quantum_length_us bigint Identified for informational purposes only. 
Not supported. Future compatibility is not guaranteed.
Exposes the scheduler quantum used by SQLOS.



Reference: sys.dm_os_schedulers (Transact-SQL) (Microsoft | Docs)




My Conundrum



The Server OS Quantum regulates how much time the SQL Server Service is granted to execute "tasks". The SQL Server OS Quantum is defined as 4 ms. If I divide the 187.5 ms by 4 ms then I am left with 3.5 ms.



And we haven't even started the discussion of when the Clock Interval is set to something other than the default of 15.625000 ms....



Simple Question



How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)?



Simple Question Explained



After 184 ms of OS quantum being used (which corresponds to 46 full SQL quantums) the OS quantum has 3.5 ms of time before it will have to hand over the schedule to a different process. The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?










share|improve this question
















Simple Question



How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)?



Simple Question Explained



After 184 ms of OS quantum being used (which corresponds to 46 full SQL quantums) the OS quantum has 3.5 ms of time before it will have to hand over the schedule to a different process. The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




Deep Dive on OS Quantum



In the next couple of sections I'll write up what I have found so far regarding the OS quantum and how the duration of a quantum can be calculated. The duration of an OS "quantum" is based on "ticks" and the duration of the "tick" itself is based on the "clock interval" which is normally 15.625000 ms. But let me elaborate a bit...



Tick



In the Blog article Know Thy Tick the author Jim explains the basics of clock intervals (aka "ticks") and what they are for.




When I read something like “the clock interval… for most x86 multiprocessors is about 15 milliseconds” I’m compelled to determine the value of my clock, or “tick”, interval. Fortunately, the book I read this quote in, Windows Internals Fourth Edition provides a reference for helping me with my affliction.
...
The author, Mark Russinovich, of the aforementioned book has graciously made the utility ClockRes available on his web site. Running this utility, I was able to determine that the clock interval on my x86 multiprocessor PC is 15.625000 ms. Interesting, but my curious mind wants to know more.




Quantum



The author of the article goes on to explain in his second article that...




Of course the real reason why the tick interval is important is that it affects thread scheduling. The Windows scheduler gives each thread a “quantum” of time to execute before allowing another task, at the same priority level, to run. The quantum that the scheduler assigns to a thread is a multiple of the tick interval. The specific quantum value chosen for a specific thread is bit beyond where I want to go with this article.




Ok, so I know what a quantum is, but not how long a quantum will run.




For now, let’s just examine the default quantum value for a foreground thread in XPe. In this case the Windows scheduler assigns a quantum of 18 or 6 tick intervals. (Yes, to convert quantum to tick intervals, one must divide by 3. ..., but the reason for the multiple is to allow the scheduler the ability to “charge” a thread for doing an operation which causes it to suspend.)




We now know that a clock interval (tick) should be around 15.625000 ms and on a Windows Desktop OS where the default quantum is 18 that this will result in 6 ticks or 93.750000 ms (18 / 3 * 15.625000 ms).



On a Windows Server OS the default quantum is different. The "Processor scheduling" setting is set to "Background Services"



This setting can be found via "System Settings | Advanced (tab) | Performance (section) | Settings ..." which will open "Perofrmance Options | Advanced (tab) | Processor scheduling"



The default quantum settings are then 36 (Background) to 36 (Foreground). The quantum is larger and hence longer. This is double the amount of the 93.750000 ms of the 18 (6 tick) quantum foreground setting on a Windows Desktop OS, which on a server OS set up for Background Services is around 187.500000 ms.



Observation / Explanation



When you change the setting from "Background services" to "Applicaitons" on either a server or desktop, then the HKLMSYSTEM CurrentControlSet Control PriorityControl Win32PrioritySeparation key in the registry is changed from 0x18 to 0x02. What is the default quantum value for 0x02? This can be found in a comment:




The value 0x02 implies that the "Short vs. Long" and "Variable vs. Fixed" fields are the default for the OS.



The default for these fields for XPe & XP Pro is: Short & Variable which is the same as having the following bits additional bits set: 0x24.



OR'ing this value in with 0x02 gives you 0x26, which you will find in the table in the article.




Reference: Comment to "Master Your Quantum" (MSDN Blogs)



The table explaining the quantum settings from the same article:



Win32PrioritySeparation Foreground Background
0x28, 0x29, 0x2A 18 18
0x18, 0x19, 0x1A 36 36
0x24 6 6
0x25, 0x14 12 6
0x26 18 6
0x15 24 6
0x16 36 6


Short Summary of OS Quantum



Based on the above information and article quotes, we know that a quantum is not a fixed size, but rather derived from an OS setting in the System Properties. A quantum varies depending on the Win32PrioritySeparation setting in the registry which normally corresponds to one of the setting in the "System Properties" (either "Background services" or "Applications").



A quantum at OS level is



  • for the "Applications" setting

    • 18 (which is 6 ticks) for foreground applications (93.75 ms)

    • 6 (which is 2 ticks) for background applications (31.25 ms)


  • for the "Background Services" setting

    • 36 (which is 18 ticks) for foreground applications (187.5 ms)

    • 36 (which is 18 ticks) for background applications (187.5 ms)


So now we know that an OS quantum on a Windows Server setup to be optimised for Background Services is ...



36 / 3 * 15.625000 ms = 187.5 ms



SQL OS Quantum



This section lists what I have found on SQL OS quantum...



SOS_SCHEDULER_YIELD Wait Type



From Paul Randall's description on the SOS_SCHEDULER_YIELD wait type:




This wait type is when a thread was able to execute for its full thread quantum (4 milliseconds in all versions of SQL Server, unchangeable), and so voluntarily yielded the scheduler, moving to the bottom of the Runnable Queue in its scheduler.




Reference: SOS_SCHEDULER_YIELD (SQLSkills.com Wait Types)



Schedulers in SQL Server DMVs



In an explanation on SQL Server DMVs for the sys.dm_os_schedulers DMV.




[...] Windows uses a preemptive scheduling mechanism and assigns a quantum of CPU time to every thread, when a thread consumes its quantum it is sent to a queue and other threads are granted execution.



In opposition, SQL Server uses a cooperative scheduling mechanism when threads can voluntary yield its quantum of time (you can see this behavior when you have a SOS_SCHEDULER_YIELD wait type). This allows SQL Server to optimize CPU utilization, because when a thread is signaled for execution but is not ready to run it can yield its quantum of time in favor of other threads.




Reference: Understanding SQL Server Schedulers, Workers and Tasks (MSSQLTips.com)



Detect SQL Server CPU Pressure



This is a very small section of an article regarding CPU pressure in SQL Server.




Occurs when a task voluntarily yields the scheduler for other tasks to execute. During this wait the task is waiting for its quantum to be renewed.




Reference: Detect SQL Server CPU Pressure (MSSQLTips.com)



sys.dm_os_schedulers (Microsoft Docs)



I guess the following quote is the most important snippet of information regarding SQL OS quantum that I could find:




quantum_length_us bigint Identified for informational purposes only. 
Not supported. Future compatibility is not guaranteed.
Exposes the scheduler quantum used by SQLOS.



Reference: sys.dm_os_schedulers (Transact-SQL) (Microsoft | Docs)




My Conundrum



The Server OS Quantum regulates how much time the SQL Server Service is granted to execute "tasks". The SQL Server OS Quantum is defined as 4 ms. If I divide the 187.5 ms by 4 ms then I am left with 3.5 ms.



And we haven't even started the discussion of when the Clock Interval is set to something other than the default of 15.625000 ms....



Simple Question



How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)?



Simple Question Explained



After 184 ms of OS quantum being used (which corresponds to 46 full SQL quantums) the OS quantum has 3.5 ms of time before it will have to hand over the schedule to a different process. The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?







sql-server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 10 at 12:15







hot2use

















asked May 9 at 14:40









hot2usehot2use

8,73852460




8,73852460












  • How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)? It's not and SQL Server doesn't use preemptive scheduling. Work items are expected to hit yield points and if they don't, you get things such as NONYIELDING schedulers. There is no parity.

    – Sean Gallardy
    May 9 at 16:40











  • So how do they not work together? If the SQL Server executable receives its quantum from the Windows OS, how does SQL Server distribute that quantum to the schedulers for the SQL Server OS "quantum"? Or is there an overhead in the Windows OS quantum that doesn't get used by SQL Server? Would it be better to change the Clock Resolution (in the registry) so that the value isn't some obscure 15.625000 ms, but instead 10.000000 ms?

    – hot2use
    May 10 at 6:33












  • I have added additional information regarding the SQL OS quantum which I found in the Microsoft Docs for sys.dm_os_schedulers.

    – hot2use
    May 10 at 9:53











  • I think the answer is fairly banal: When the OS quantum expires the thread is forcefully descheduled. This is transparent to SQL Server. SQLOS has no way of detecting when this happens. There is no Win32 API for that. Scheduling is transparent to user mode threads.

    – usr
    May 10 at 9:59











  • The Windows scheduler does not know or care what user mode threads are doing. Windows only sees threads that are runnable and lets them run till the end of their OS quantum or until they block.

    – usr
    May 10 at 10:01

















  • How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)? It's not and SQL Server doesn't use preemptive scheduling. Work items are expected to hit yield points and if they don't, you get things such as NONYIELDING schedulers. There is no parity.

    – Sean Gallardy
    May 9 at 16:40











  • So how do they not work together? If the SQL Server executable receives its quantum from the Windows OS, how does SQL Server distribute that quantum to the schedulers for the SQL Server OS "quantum"? Or is there an overhead in the Windows OS quantum that doesn't get used by SQL Server? Would it be better to change the Clock Resolution (in the registry) so that the value isn't some obscure 15.625000 ms, but instead 10.000000 ms?

    – hot2use
    May 10 at 6:33












  • I have added additional information regarding the SQL OS quantum which I found in the Microsoft Docs for sys.dm_os_schedulers.

    – hot2use
    May 10 at 9:53











  • I think the answer is fairly banal: When the OS quantum expires the thread is forcefully descheduled. This is transparent to SQL Server. SQLOS has no way of detecting when this happens. There is no Win32 API for that. Scheduling is transparent to user mode threads.

    – usr
    May 10 at 9:59











  • The Windows scheduler does not know or care what user mode threads are doing. Windows only sees threads that are runnable and lets them run till the end of their OS quantum or until they block.

    – usr
    May 10 at 10:01
















How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)? It's not and SQL Server doesn't use preemptive scheduling. Work items are expected to hit yield points and if they don't, you get things such as NONYIELDING schedulers. There is no parity.

– Sean Gallardy
May 9 at 16:40





How is the SQL Server Quantum (4 ms) synchronised with the Server OS Quantum (normally: 187.5 ms)? It's not and SQL Server doesn't use preemptive scheduling. Work items are expected to hit yield points and if they don't, you get things such as NONYIELDING schedulers. There is no parity.

– Sean Gallardy
May 9 at 16:40













So how do they not work together? If the SQL Server executable receives its quantum from the Windows OS, how does SQL Server distribute that quantum to the schedulers for the SQL Server OS "quantum"? Or is there an overhead in the Windows OS quantum that doesn't get used by SQL Server? Would it be better to change the Clock Resolution (in the registry) so that the value isn't some obscure 15.625000 ms, but instead 10.000000 ms?

– hot2use
May 10 at 6:33






So how do they not work together? If the SQL Server executable receives its quantum from the Windows OS, how does SQL Server distribute that quantum to the schedulers for the SQL Server OS "quantum"? Or is there an overhead in the Windows OS quantum that doesn't get used by SQL Server? Would it be better to change the Clock Resolution (in the registry) so that the value isn't some obscure 15.625000 ms, but instead 10.000000 ms?

– hot2use
May 10 at 6:33














I have added additional information regarding the SQL OS quantum which I found in the Microsoft Docs for sys.dm_os_schedulers.

– hot2use
May 10 at 9:53





I have added additional information regarding the SQL OS quantum which I found in the Microsoft Docs for sys.dm_os_schedulers.

– hot2use
May 10 at 9:53













I think the answer is fairly banal: When the OS quantum expires the thread is forcefully descheduled. This is transparent to SQL Server. SQLOS has no way of detecting when this happens. There is no Win32 API for that. Scheduling is transparent to user mode threads.

– usr
May 10 at 9:59





I think the answer is fairly banal: When the OS quantum expires the thread is forcefully descheduled. This is transparent to SQL Server. SQLOS has no way of detecting when this happens. There is no Win32 API for that. Scheduling is transparent to user mode threads.

– usr
May 10 at 9:59













The Windows scheduler does not know or care what user mode threads are doing. Windows only sees threads that are runnable and lets them run till the end of their OS quantum or until they block.

– usr
May 10 at 10:01





The Windows scheduler does not know or care what user mode threads are doing. Windows only sees threads that are runnable and lets them run till the end of their OS quantum or until they block.

– usr
May 10 at 10:01










1 Answer
1






active

oldest

votes


















10















Even though the scheduler isn't preemptive, the SQL Server scheduler
still adheres to a concept of a quantum. Rahter than SQL Server tasks
be forced to give up the CPU by the operating system, they can
request to be put on a wait queue periodically, and if they have
exceeded the internally defined 4 millisecond quantum and aren't in
the middle of an operation that can't be stopped, they voluntarily
relinquish the CPU.




-"Microsoft SQL Server 2012 Internals", Kalen Delaney et. al. pp38



-Chapter 2 "The SQLOS" Jonathan Kehayias



So the notion of a "quantum" inside SQL Server is more of a "guideline" for programming tasks. IE when you write a task, like say, a task that performs a table scan, if you don't hit any page latch, IO latch, or lock waits for a while, you should stop what you're doing and ask to be put back on the runnable queue, in case there are other tasks waiting.



But it's up to the task programmer to implement this, and it might not be exactly 4ms for each kind of task. For instance the table scan task might use a simple heuristic based on the number of pages scanned to implement the yield points.



So




The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




If the SQL Server thread is pre-empted by Windows while a task is running, it will be paused, and when its thread is next scheduled on a CPU it will continue where it left off. Presumably it will continue to consume the balance of its 4ms quantum, as it wouldn't know any difference. But again, the yield behavior is an implementation detail of the task, not a behavior of SQLOS, so different tasks might behave differently here.






share|improve this answer




















  • 3





    See this article. I've seen mention of SQL Quantums a lot over the years - not sure how true any of it is now.

    – George.Palacios
    May 9 at 16:16







  • 5





    So there it's used to mean essentially "the time a task actually spends assigned to a worker", but that's not the same sense as a Windows quantum, which is a period of time after which the OS will remove a thread from a CPU. There's just different concepts.

    – David Browne - Microsoft
    May 9 at 16:42











  • Yeah it seems like quite a subtle distinction but I agree. The question then becomes what happen if the OS forces a thread to end execution because the OS quantum has been reached - particularly if SQL is midway through an operation.

    – George.Palacios
    May 9 at 16:52











  • A context switch happens SQL Server's thread is suspended, just like any other program.

    – David Browne - Microsoft
    May 9 at 16:59











  • That, as I understand the question, is the answer in that case.

    – George.Palacios
    May 9 at 17:00











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "182"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f237749%2fwindows-os-quantum-vs-sql-os-quantum%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









10















Even though the scheduler isn't preemptive, the SQL Server scheduler
still adheres to a concept of a quantum. Rahter than SQL Server tasks
be forced to give up the CPU by the operating system, they can
request to be put on a wait queue periodically, and if they have
exceeded the internally defined 4 millisecond quantum and aren't in
the middle of an operation that can't be stopped, they voluntarily
relinquish the CPU.




-"Microsoft SQL Server 2012 Internals", Kalen Delaney et. al. pp38



-Chapter 2 "The SQLOS" Jonathan Kehayias



So the notion of a "quantum" inside SQL Server is more of a "guideline" for programming tasks. IE when you write a task, like say, a task that performs a table scan, if you don't hit any page latch, IO latch, or lock waits for a while, you should stop what you're doing and ask to be put back on the runnable queue, in case there are other tasks waiting.



But it's up to the task programmer to implement this, and it might not be exactly 4ms for each kind of task. For instance the table scan task might use a simple heuristic based on the number of pages scanned to implement the yield points.



So




The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




If the SQL Server thread is pre-empted by Windows while a task is running, it will be paused, and when its thread is next scheduled on a CPU it will continue where it left off. Presumably it will continue to consume the balance of its 4ms quantum, as it wouldn't know any difference. But again, the yield behavior is an implementation detail of the task, not a behavior of SQLOS, so different tasks might behave differently here.






share|improve this answer




















  • 3





    See this article. I've seen mention of SQL Quantums a lot over the years - not sure how true any of it is now.

    – George.Palacios
    May 9 at 16:16







  • 5





    So there it's used to mean essentially "the time a task actually spends assigned to a worker", but that's not the same sense as a Windows quantum, which is a period of time after which the OS will remove a thread from a CPU. There's just different concepts.

    – David Browne - Microsoft
    May 9 at 16:42











  • Yeah it seems like quite a subtle distinction but I agree. The question then becomes what happen if the OS forces a thread to end execution because the OS quantum has been reached - particularly if SQL is midway through an operation.

    – George.Palacios
    May 9 at 16:52











  • A context switch happens SQL Server's thread is suspended, just like any other program.

    – David Browne - Microsoft
    May 9 at 16:59











  • That, as I understand the question, is the answer in that case.

    – George.Palacios
    May 9 at 17:00















10















Even though the scheduler isn't preemptive, the SQL Server scheduler
still adheres to a concept of a quantum. Rahter than SQL Server tasks
be forced to give up the CPU by the operating system, they can
request to be put on a wait queue periodically, and if they have
exceeded the internally defined 4 millisecond quantum and aren't in
the middle of an operation that can't be stopped, they voluntarily
relinquish the CPU.




-"Microsoft SQL Server 2012 Internals", Kalen Delaney et. al. pp38



-Chapter 2 "The SQLOS" Jonathan Kehayias



So the notion of a "quantum" inside SQL Server is more of a "guideline" for programming tasks. IE when you write a task, like say, a task that performs a table scan, if you don't hit any page latch, IO latch, or lock waits for a while, you should stop what you're doing and ask to be put back on the runnable queue, in case there are other tasks waiting.



But it's up to the task programmer to implement this, and it might not be exactly 4ms for each kind of task. For instance the table scan task might use a simple heuristic based on the number of pages scanned to implement the yield points.



So




The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




If the SQL Server thread is pre-empted by Windows while a task is running, it will be paused, and when its thread is next scheduled on a CPU it will continue where it left off. Presumably it will continue to consume the balance of its 4ms quantum, as it wouldn't know any difference. But again, the yield behavior is an implementation detail of the task, not a behavior of SQLOS, so different tasks might behave differently here.






share|improve this answer




















  • 3





    See this article. I've seen mention of SQL Quantums a lot over the years - not sure how true any of it is now.

    – George.Palacios
    May 9 at 16:16







  • 5





    So there it's used to mean essentially "the time a task actually spends assigned to a worker", but that's not the same sense as a Windows quantum, which is a period of time after which the OS will remove a thread from a CPU. There's just different concepts.

    – David Browne - Microsoft
    May 9 at 16:42











  • Yeah it seems like quite a subtle distinction but I agree. The question then becomes what happen if the OS forces a thread to end execution because the OS quantum has been reached - particularly if SQL is midway through an operation.

    – George.Palacios
    May 9 at 16:52











  • A context switch happens SQL Server's thread is suspended, just like any other program.

    – David Browne - Microsoft
    May 9 at 16:59











  • That, as I understand the question, is the answer in that case.

    – George.Palacios
    May 9 at 17:00













10












10








10








Even though the scheduler isn't preemptive, the SQL Server scheduler
still adheres to a concept of a quantum. Rahter than SQL Server tasks
be forced to give up the CPU by the operating system, they can
request to be put on a wait queue periodically, and if they have
exceeded the internally defined 4 millisecond quantum and aren't in
the middle of an operation that can't be stopped, they voluntarily
relinquish the CPU.




-"Microsoft SQL Server 2012 Internals", Kalen Delaney et. al. pp38



-Chapter 2 "The SQLOS" Jonathan Kehayias



So the notion of a "quantum" inside SQL Server is more of a "guideline" for programming tasks. IE when you write a task, like say, a task that performs a table scan, if you don't hit any page latch, IO latch, or lock waits for a while, you should stop what you're doing and ask to be put back on the runnable queue, in case there are other tasks waiting.



But it's up to the task programmer to implement this, and it might not be exactly 4ms for each kind of task. For instance the table scan task might use a simple heuristic based on the number of pages scanned to implement the yield points.



So




The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




If the SQL Server thread is pre-empted by Windows while a task is running, it will be paused, and when its thread is next scheduled on a CPU it will continue where it left off. Presumably it will continue to consume the balance of its 4ms quantum, as it wouldn't know any difference. But again, the yield behavior is an implementation detail of the task, not a behavior of SQLOS, so different tasks might behave differently here.






share|improve this answer
















Even though the scheduler isn't preemptive, the SQL Server scheduler
still adheres to a concept of a quantum. Rahter than SQL Server tasks
be forced to give up the CPU by the operating system, they can
request to be put on a wait queue periodically, and if they have
exceeded the internally defined 4 millisecond quantum and aren't in
the middle of an operation that can't be stopped, they voluntarily
relinquish the CPU.




-"Microsoft SQL Server 2012 Internals", Kalen Delaney et. al. pp38



-Chapter 2 "The SQLOS" Jonathan Kehayias



So the notion of a "quantum" inside SQL Server is more of a "guideline" for programming tasks. IE when you write a task, like say, a task that performs a table scan, if you don't hit any page latch, IO latch, or lock waits for a while, you should stop what you're doing and ask to be put back on the runnable queue, in case there are other tasks waiting.



But it's up to the task programmer to implement this, and it might not be exactly 4ms for each kind of task. For instance the table scan task might use a simple heuristic based on the number of pages scanned to implement the yield points.



So




The SQL OS starts a quantum (4 ms) and after 3.5 ms, the OS quantum has decided to stop the current SQL OS thread which still has 0.5 ms before it would yield the schedule. What happens now?




If the SQL Server thread is pre-empted by Windows while a task is running, it will be paused, and when its thread is next scheduled on a CPU it will continue where it left off. Presumably it will continue to consume the balance of its 4ms quantum, as it wouldn't know any difference. But again, the yield behavior is an implementation detail of the task, not a behavior of SQLOS, so different tasks might behave differently here.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 10 at 16:50

























answered May 9 at 16:07









David Browne - MicrosoftDavid Browne - Microsoft

13.3k937




13.3k937







  • 3





    See this article. I've seen mention of SQL Quantums a lot over the years - not sure how true any of it is now.

    – George.Palacios
    May 9 at 16:16







  • 5





    So there it's used to mean essentially "the time a task actually spends assigned to a worker", but that's not the same sense as a Windows quantum, which is a period of time after which the OS will remove a thread from a CPU. There's just different concepts.

    – David Browne - Microsoft
    May 9 at 16:42











  • Yeah it seems like quite a subtle distinction but I agree. The question then becomes what happen if the OS forces a thread to end execution because the OS quantum has been reached - particularly if SQL is midway through an operation.

    – George.Palacios
    May 9 at 16:52











  • A context switch happens SQL Server's thread is suspended, just like any other program.

    – David Browne - Microsoft
    May 9 at 16:59











  • That, as I understand the question, is the answer in that case.

    – George.Palacios
    May 9 at 17:00












  • 3





    See this article. I've seen mention of SQL Quantums a lot over the years - not sure how true any of it is now.

    – George.Palacios
    May 9 at 16:16







  • 5





    So there it's used to mean essentially "the time a task actually spends assigned to a worker", but that's not the same sense as a Windows quantum, which is a period of time after which the OS will remove a thread from a CPU. There's just different concepts.

    – David Browne - Microsoft
    May 9 at 16:42











  • Yeah it seems like quite a subtle distinction but I agree. The question then becomes what happen if the OS forces a thread to end execution because the OS quantum has been reached - particularly if SQL is midway through an operation.

    – George.Palacios
    May 9 at 16:52











  • A context switch happens SQL Server's thread is suspended, just like any other program.

    – David Browne - Microsoft
    May 9 at 16:59











  • That, as I understand the question, is the answer in that case.

    – George.Palacios
    May 9 at 17:00







3




3





See this article. I've seen mention of SQL Quantums a lot over the years - not sure how true any of it is now.

– George.Palacios
May 9 at 16:16






See this article. I've seen mention of SQL Quantums a lot over the years - not sure how true any of it is now.

– George.Palacios
May 9 at 16:16





5




5





So there it's used to mean essentially "the time a task actually spends assigned to a worker", but that's not the same sense as a Windows quantum, which is a period of time after which the OS will remove a thread from a CPU. There's just different concepts.

– David Browne - Microsoft
May 9 at 16:42





So there it's used to mean essentially "the time a task actually spends assigned to a worker", but that's not the same sense as a Windows quantum, which is a period of time after which the OS will remove a thread from a CPU. There's just different concepts.

– David Browne - Microsoft
May 9 at 16:42













Yeah it seems like quite a subtle distinction but I agree. The question then becomes what happen if the OS forces a thread to end execution because the OS quantum has been reached - particularly if SQL is midway through an operation.

– George.Palacios
May 9 at 16:52





Yeah it seems like quite a subtle distinction but I agree. The question then becomes what happen if the OS forces a thread to end execution because the OS quantum has been reached - particularly if SQL is midway through an operation.

– George.Palacios
May 9 at 16:52













A context switch happens SQL Server's thread is suspended, just like any other program.

– David Browne - Microsoft
May 9 at 16:59





A context switch happens SQL Server's thread is suspended, just like any other program.

– David Browne - Microsoft
May 9 at 16:59













That, as I understand the question, is the answer in that case.

– George.Palacios
May 9 at 17:00





That, as I understand the question, is the answer in that case.

– George.Palacios
May 9 at 17:00

















draft saved

draft discarded
















































Thanks for contributing an answer to Database Administrators Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f237749%2fwindows-os-quantum-vs-sql-os-quantum%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림