By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

Restricting bandwidth for download stream

P: n/a
Hi all,

I have an asp.net application from which registered users can download
files. What I want to implement is a bandwidth restriction for certain
users. What I DON'T want to do is restrict the bandwidth on the IIS
side. It really should be handled in the code. Here is a code snippet
showing how downloads are currently handled (standard implementation I
guess):

// fs: FileStream
while (offset < size && Response.IsClientConnected)
{
if (size-offset < bufSize)
{
bufSize = size-offset;
buf = new byte[bufSize];
}
fs.Read(buf, 0, (int)bufSize);
Response.OutputStream.Write(buf, 0, (int)bufSize);
if (Response.IsClientConnected)
Response.Flush();
else
break;
offset += bufSize;
}

everything works fine, but I can't find a way to decrease the speed of
the download (except perhaps adding Sleep() or decreasing bufsize which
would both be a *dirty* solution). Anyone has an idea?

Thanks in advance

Hannes

Sep 2 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
first be sure buffering is turned off. loop writing chunks with sleeps as
you guessed.

a bit about about flow. when the download request hits iis, it uses a thread
and pipe to talk to asp.net worker process. asp.net dedicates an io thread
to handle the pipe, and starts a worker thread to process the request.

if you add delays, all these threads will be tied up, and the number of
concurrent downloads will drop. while you can bump up the threads pools, it
is still not a very high number (200 concurrent downloads per server is
about the max).

you may find that limiting bandwidth is not very useful. you might look at
limiting the number of downloads in a given time rather than slowing down a
download.

-- bruce (sqlwork.com)
"hoenes1" <le****@twism4life.de> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi all,

I have an asp.net application from which registered users can download
files. What I want to implement is a bandwidth restriction for certain
users. What I DON'T want to do is restrict the bandwidth on the IIS
side. It really should be handled in the code. Here is a code snippet
showing how downloads are currently handled (standard implementation I
guess):

// fs: FileStream
while (offset < size && Response.IsClientConnected)
{
if (size-offset < bufSize)
{
bufSize = size-offset;
buf = new byte[bufSize];
}
fs.Read(buf, 0, (int)bufSize);
Response.OutputStream.Write(buf, 0, (int)bufSize);
if (Response.IsClientConnected)
Response.Flush();
else
break;
offset += bufSize;
}

everything works fine, but I can't find a way to decrease the speed of
the download (except perhaps adding Sleep() or decreasing bufsize which
would both be a *dirty* solution). Anyone has an idea?

Thanks in advance

Hannes

Sep 2 '05 #2

P: n/a
First, thank you for the time you spent with your answer.
Actually, the purpose of the bandwith restriction is not to disburden
the server (which has enough firepower to serve all concurrent
requests), but to restrict the bandwidth usage of certain users (e. g.
who don't pay for the service or any other restriction criteria). Is
Sleep() really the only possibility to restrict streaming bandwidth? I
can hardly imagine that. And if so, does adding Sleep() after
stream.Write() actually slow down all concurrent downloads (given that
every download has its own thread)?
Thanks again in advance for your input.

Sep 5 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.