Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Alternative to WAITFOR DELAY

199 views
Skip to first unread message

Anton Shepelev

unread,
Nov 29, 2017, 3:38:22 PM11/29/17
to
Hello, all

Is there a more granular way to ease a tight polling
loop in T-SQL than WAITFOR DEALAY? A delay of 3.33
milliseconds being a tad too long for my purposes, I
seek a way to implement delays of about half a mil-
lisecond or shorter. I do not need the precision of
real-time systems and will accept any solution to
prevent a fast WHILE 1=1 loop from hogging the CPU.

--
() ascii ribbon campaign -- against html e-mail
/\ http://preview.tinyurl.com/qcy6mjc [archived]

Erland Sommarskog

unread,
Nov 29, 2017, 4:49:32 PM11/29/17
to
Anton Shepelev (anto...@gmail.com) writes:
> Is there a more granular way to ease a tight polling
> loop in T-SQL than WAITFOR DEALAY? A delay of 3.33
> milliseconds being a tad too long for my purposes, I
> seek a way to implement delays of about half a mil-
> lisecond or shorter. I do not need the precision of
> real-time systems and will accept any solution to
> prevent a fast WHILE 1=1 loop from hogging the CPU.
>

I guess that you could write a CLR procedure for the task.

Anton Shepelev

unread,
Nov 30, 2017, 5:59:03 AM11/30/17
to
Erland Sommarskog to Anton Shepelev:

>>Is there a more granular way to ease a tight
>>polling loop in T-SQL than WAITFOR DEALAY? A de-
>>lay of 3.33 milliseconds being a tad too long for
>>my purposes, I seek a way to implement delays of
>>about half a millisecond or shorter. I do not
>>need the precision of real-time systems and will
>>accept any solution to prevent a fast WHILE 1=1
>>loop from hogging the CPU.
>
>I guess that you could write a CLR procedure for
>the task.

Thanks. No idea why it didn't occur to me. I have
written .NET assemblies for MSSQL before. If per-
formace testing shows a need for a shorter delay I
will definitely follow your advice.

Meanwhile, my loop switches to zero delay once it
finds work to do, and back to a 3.3 ms delay once
all work is done and in incoming queue is empty.

--
() ascii ribbon campaign - against html e-mail
/\ http://preview.tinyurl.com/qcy6mjc [archived]
0 new messages