473,289 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Restricting bandwidth for download stream

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
2 1580
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dany | last post by:
Wrote a script (tried to;) which should force to download a pdf-file, but it doesn't work on every browser. What should be changed ? SCRIPT: --------- <% Dim Stream Dim Contents
0
by: Martin Raychev | last post by:
Hi everybody, I have a need for a web app that will allow a flash client to download files at a specified speed. I am using Flash for an application of mine which downloads JPG slides to...
5
by: Thomas Andersson | last post by:
Hi, I am trying to find a working solution for download of large files (400-800 MB)... But this seems almost impossible to find a working example. I have tried Response.Transmitfile, this...
8
by: Dominic Martin | last post by:
Hi, I need to setup an ODBC link over our Internet connection between MS Access (local) and a MySQL server (Remote - the local PC has the MySQL ODBC driver installed). What kind of bandwidth...
9
by: Chibi | last post by:
I'm writing an application that's bandwidth intense. My available bandwidth is 1.5Mbps (cable modem) and I know I can reach around 1.4Mbps, if not more. The application I am writing right now...
1
by: hoenes1 | last post by:
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...
3
by: Raj | last post by:
is it possible using C# dotnet to control the bandwidth usage means the transfer rate of download and upload? Thanks!
4
by: rony_16 | last post by:
Hi, I have a program that connects to a site With WebRequest and WebResponse . The response of this site is a file (csv file). The problem is that the file do not comes as a stream , hi is a part...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.