Thread.uSleep

  • Thread starter Thread starter Matthijs
  • Start date Start date
M

Matthijs

Hi,
I have a problem coding a UDP Server/client. The server needs to send big
amounts of data over UDP. The problem however is that you can't send as fast
as you like. (All packets will be dropped due to the fact that a router
can't handle the huge number of packets (most likely the first one the
packets hit)).

To fix this problem you need to increase/decrease the speed according to
packetloss.

The problem I'm facing at the moment is; When I need to wait less then 1 ms
in between sending 2 packets. At the moment I'm using Thread.Sleep to time
the packets. Which is working quite nicely won't go faster then ~1.4
mBytes/s depending on packet size while testing.

Is there a simple way to fix this without using a busy waiting or do I need
to use p/invoke (To get to usleep or something).
(you can't resolve this by changing packet size due to the fact that most
routers have a max MTU length!)

Thanks, Matthijs
 
Matthijs said:
Hi,
I have a problem coding a UDP Server/client. The server needs to send big
amounts of data over UDP. The problem however is that you can't send as
fast as you like. (All packets will be dropped due to the fact that a
router can't handle the huge number of packets (most likely the first one
the packets hit)).

To fix this problem you need to increase/decrease the speed according to
packetloss.

The problem I'm facing at the moment is; When I need to wait less then 1
ms in between sending 2 packets. At the moment I'm using Thread.Sleep to
time the packets. Which is working quite nicely won't go faster then ~1.4
mBytes/s depending on packet size while testing.

Is there a simple way to fix this without using a busy waiting or do I
need to use p/invoke (To get to usleep or something).
(you can't resolve this by changing packet size due to the fact that most
routers have a max MTU length!)

Thanks, Matthijs

Beware that Thread.Sleep(n), sets the calling thread to sleep for at least n
milliseconds, if n < one clock period, the thread will put asleep for at
most one clock period.
For most modern X86 based systems, the clock period is set to 10msec., but
periods of 15.6msec or higher are also possible (like on AMD and SMP boxes).
That means that when you call Sleep(1) on a system with a 10msec. clock
period, this will put the thread to sleep for at least 0 millisecond up to
10 msec, the same, if you call Sleep(9), your thread might sleep from 0 up
to 10 msec. That means that calling Sleep(n) with n lower than the clock
period tends to be very inaccurate and in general makes no sense at all.


Willy.
 
Back
Top