Board index » delphi » How to throttle Bandwidth Usage in Indy

How to throttle Bandwidth Usage in Indy

Hi, I'm writing a little download-tool at the moment which I want to give
the ability to throttle downloads in order not to consume all availlable
Bandwidth (with the tidhttp component). Is there any neat way? And how can I
simply get the Bandwidth Usage of a Thread running an tidhttp download?
Using the onwork event isn't enough because it's far to less called on slow
connections...

Thx in advance.

Yoshi Zrbit

 

Re:How to throttle Bandwidth Usage in Indy


Quote
"Yoshi Zrbit" <Yos...@Sysopz.de> wrote in message news:3b811f7a_1@dnews...
> Hi, I'm writing a little download-tool at the moment which I want to give
> the ability to throttle downloads in order not to consume all availlable
> Bandwidth (with the tidhttp component). Is there any neat way? And how can
I
> simply get the Bandwidth Usage of a Thread running an tidhttp download?
> Using the onwork event isn't enough because it's far to less called on
slow
> connections...

You'd need to write a custom intercept to measure the speed of the
connection and throttle
it as necessary.  I'm working on this, but my solution will require that
both the server and
the client have such intercepts, allowing them to select a piece of data as
a speed test, and
return the result for later use in throttling the connection.  The reason
for this is Send()s
get passed on to the Winsock TCP/IP stack, and the function immediately
returns, giving
you no chance to time it.  Recv()s are different - you can time them just
fine.  So it's
possible that just a client intercept could check its speed that way.

Given that the apps I'm writing this for are in-house and use custom TCP
servers, I'm not
too concerned with making just a client intercept work this way.  If I have
time I might try
it.  And if so I'll release the code.

                    Toby

Re:How to throttle Bandwidth Usage in Indy


Quote
> The reason for this is Send()s get passed on to the Winsock TCP/IP stack,
> and the function immediately returns, giving you no chance to time it.

True, but you CAN control when (how often) you call send!  Let's say that
you want to set a maximum download speed from your server at 16Kb/sec.
(128KBps)  If you call send() with a 16K block of data, you have now sent
your maximum data quantity for the next second.  If you check the time (I
would use getWindowsTicks), you can calculate the next earliest time that
you can send another block (one whole second from now).  As a result, the
TCP/IP stack will only receive data from your app at 16K/s;  and it can't
send it out any faster than it gets it!  (Note: you could also send smaller
chunks at closer intervals, ie: 4K every .25 sec, but I don't know what
effect that would have on the bandwidth.  The long term average would be the
same, but traffic flow itself (and the availability of the bandwidth to
other users) would change, but I'm not sure how.

Ralph S.

Quote
"Toby Leonard" <to...@netedgesolutions.com> wrote in message

news:3b82ab02_1@dnews...
Quote
> "Yoshi Zrbit" <Yos...@Sysopz.de> wrote in message news:3b811f7a_1@dnews...
> > Hi, I'm writing a little download-tool at the moment which I want to
give
> > the ability to throttle downloads in order not to consume all availlable
> > Bandwidth (with the tidhttp component). Is there any neat way? And how
can
> I
> > simply get the Bandwidth Usage of a Thread running an tidhttp download?
> > Using the onwork event isn't enough because it's far to less called on
> slow
> > connections...

> You'd need to write a custom intercept to measure the speed of the
> connection and throttle
> it as necessary.  I'm working on this, but my solution will require that
> both the server and
> the client have such intercepts, allowing them to select a piece of data
as
> a speed test, and
> return the result for later use in throttling the connection.  The reason
> for this is Send()s
> get passed on to the Winsock TCP/IP stack, and the function immediately
> returns, giving
> you no chance to time it.  Recv()s are different - you can time them just
> fine.  So it's
> possible that just a client intercept could check its speed that way.

> Given that the apps I'm writing this for are in-house and use custom TCP
> servers, I'm not
> too concerned with making just a client intercept work this way.  If I
have
> time I might try
> it.  And if so I'll release the code.

>                     Toby

Re:How to throttle Bandwidth Usage in Indy


If anyone is willing to share such a thing, I would love to see an example
of a client-only intercept that would allow me to control the speed at which
data is received.

Thanks,
David Jameson

Other Threads