Component for limiting bandwith

Component for limiting bandwith

Post by dcaballero » Thu, 13 Jul 2006 02:08:15



Hi! Anybody know of a dll or some other kind of component I could use
in a .NET app via interop to limit bandwith of any application running
in the PC?

Please! I really need this.

Thnx
David C.
 
 
 

Component for limiting bandwith

Post by Arkady Fre » Thu, 13 Jul 2006 06:29:50

Check/googlize maybe some company have lsp dll for that. just like
netlimiter ( http://www.yqcomputer.com/ ) but engine in dll and not exe
Arkady

 
 
 

Component for limiting bandwith

Post by UGF2ZWwgQS » Thu, 13 Jul 2006 06:41:02


Limiting per application will work in Vista
( see http://www.yqcomputer.com/ )
Until this happens, look for some utility , as Arkady suggested

--PA
 
 
 

Component for limiting bandwith

Post by Hector San » Thu, 13 Jul 2006 06:59:22


You want to control ANY application or you mean your own applications?

I can't tell you how you can control other processes, but within your own
its just a matter of throttling your throughput with the socket I/O commands
or the equivalent .NET functionality of a socket I/O.

There are a few varying methodologies depending on per session per user per
service, etc. But essentially, the commonality is to calculate the "sleep"
time between socket reads and writes that will give you the bandwidth you
want.

Here is a snippet code pulled from my TSocketIO class that we used for
throttling socket bandwidths. You can take this C/C++ functionally and add
it to your own .NET code:

DWORD TSocketIO::CalculateThrottle(
const double speedk, // kbits/secs
const DWORD dwBufferSize)
{
if (speedk == 0.0) {
return 0;
}
DWORD time = 0;
DWORD bits = 8;
double rate = speedk/bits;
if (speedk > 0.0) time = (DWORD)(dwBufferSize/rate);
return time; // milli-seconds
}

int TSocketIO::SendThrottle(const char *buf,
DWORD bufsize,
int maxspeed,
DWORD flags)
{
LARGE_INTEGER start_ticks;
LARGE_INTEGER ends_ticks;
if (maxspeed > 0) QueryPerformanceCounter(&start_ticks);
int n = ::send(hSocket, (char *)buf, bufsize,flags);
if ((n > 0) && (maxspeed > 0)) {
QueryPerformanceCounter(&ends_ticks);
ends_ticks.QuadPart -= start_ticks.QuadPart;
double atime = ends_ticks.QuadPart * 1000.0 / frequency.QuadPart;
int time = (int) CalculateThrottle(maxspeed,n) - (DWORD)atime;
if (time > 0) Sleep(time);
}

return n;
}

int TSocketIO::recvthrottle(char *buf,
int bufsize,
int maxspeed,
DWORD flags /* = 0 */)
{
int n;
LARGE_INTEGER start_ticks;
LARGE_INTEGER ends_ticks;
if (maxspeed > 0) QueryPerformanceCounter(&start_ticks);
n = ::recv(hSocket, (char *)buf, bufsize, flags);
if ((n > 0) && (maxspeed > 0)) {
QueryPerformanceCounter(&ends_ticks);
ends_ticks.QuadPart -= start_ticks.QuadPart;
double atime = ends_ticks.QuadPart * 1000.0 / frequency.QuadPart;
int time = (int) CalculateThrottle(maxspeed,n) - (DWORD)atime;
if (time > 0) {
timeBeginPeriod(1);
Sleep(time);
timeEndPeriod(1);
}
}
return n;
}

In short, the above are just wrappers that will "slow down" or "throttle"
the sends and recvs by calculating a sleep based on the desired maximum
speed.

Hope this helps or what you were looking for.
 
 
 

Component for limiting bandwith

Post by Vladimir S » Sat, 22 Jul 2006 16:22:07

Starting from Vista you will be able to do that using QOSSetOutgoingRate
function.

http://www.yqcomputer.com/

--
Vladimir (Windows SDK MVP)