Windows 7 suddenly limits outgoing UDP packets RRS feed

  • Question

  • Hello all.

    I have an application that sends UDP packets from my laptop to a piece of hardware that sends response UDP packets.  The application sends 3 UDP packets out every 1 ms and the hardware replies immediately with 3 packets.  I am not on a network or going through any routers.  This is a direct connection, and I have disabled the Windows 7 firewall.  I do not have any virus-scan software installed.  When I first boot the machine and run my application, my application runs fine and I can see in Wireshark that the approximate period of my loop is 1 ms, which is expected since there is a 1 ms Wait statement inside the loop in the C# code.  The code runs as expected until around 15 minutes after booting, the outbound UDP packet rate drops by about a factor of 16.  I can clearly see in Wireshark the point where my three outbound packets occur at every 16 ms rather than every 1 ms.  The replies from my hardware at the other end of the ethernet cable are still immediate, but it is like something has suddenly started throttling my outbound UDP packet rate.  This behavior is repeatable.  If I reboot and run my application, I go back to a 1 ms period, but after 15-20 minutes, it suddenly drops again.

    My code is very simple.  I am sure it is not anything inside my code causing this.  I have searched around the forums and internet about UDP throttling and have tried adding a QoS policy for my executable that sets the DSCP field in my UDP packets to highest priority without any throttling limit.  I had to add a register entry called "Do not use NLA" and set the string to 1 (I saw someone else who said they had to do this to get the DSCP setting working) and am able to see in Wireshark that my outbound UDP packets have their DSCP field changed to 63, but it does not keep the rate from suddenly decreasing 15 minutes after a fresh reboot.

    I have tried to look at the services running before and after the change in behavior using "tasklist /svc" but do not see any additional services that have started after the bad behavior starts.  I am using Windows 7 SP1.  I have enabled Priority under my NIC settings.

    I saw another post suggesting edits to the registry to disable throttling:

    I tried all of those and the behavior persists.

    Interestingly, if I try rebooting in safe mode with networking, my code runs with the slow 16ms period from the get-go.  There is no initial 1ms period for 15 minutes, and then the sudden drop in performance.

    Another interesting fact is that I have installed 32-bit Windows XP on another hard drive and used it with the same laptop and identical setup and this bipolar behavior does not occur.

    I'm at a loss at this point.  Any ideas?

    Thanks a lot!


    • Edited by dcaruth Saturday, February 18, 2012 12:50 AM
    Saturday, February 18, 2012 12:46 AM

All replies

  • SearchIndexer service?
    Wednesday, February 29, 2012 8:09 PM
  • It turns out that my issue had nothing to do with outbound UDP throttling.  It was the Windows Sleep function.  I had a loop that sent out the packets, was supposed to Sleep for 1ms, and then repeat.  For whatever reason, there were times when Sleep was returning after 1ms and then other times after 15ms.  It was a very bi-modal behavior.  The problem is that when using Sleep, the thread yields the processor it was running on to the OS, and then, when it is done sleeping and wants the processor back, Windows 7 does not always give it back right away and resume execution of the thread.

    So I wrote my own sleep function that queried the processor for its frequency (QueryPerformanceFrequency) and its initial tick value (QueryPerformanceCounter), and then entered a loop that queried the current tick value (again, QueryPerformanceCounter) until the number of ticks elapsed / frequency = my desired sleep time.  This function never yields the processor and reliably sleeps for 1ms +/- 10 us, which is more than good enough for what I need to do.  Under Wireshark, I now see the packets come out reliably every 1ms.


    David Caruth

    Thursday, March 1, 2012 12:46 AM