Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
|
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 14th, 2007, 06:42 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Downloading a large file in multiple segments

I am developing a Download Manager for our custom installation package. I have to download a file (90MB in size) in multiple segments from a web location. I am using multi-threaded application where each thread is responsible to download a segment of that file. I am using HttpWebRequest/HttpWebResponse objects & working in .Net Framework 1.1.

Now, the problem is, that my application is not allowing me to establish more than two active connections with the web locationn to download the file. When i use four segments to download the file, first two threads have established connections with the file and they were working fine, but the rest of the two threads were waiting for the connection. In the mean time request time out occurred in one of the last two threads and it thrown WebException.

Here is the snap of code working behind each thread

Try

objHttpWebRequest = WebRequest.Create(strSourceURL)
objHttpWebRequest.AddRange(iStartByte)
objHttpWebRequest.Credentials = CredentialCache.DefaultCredentials

objHttpWebResponse = CType(objHttpWebRequest.GetResponse(), HttpWebResponse)
objResponseStream = objHttpWebResponse.GetResponseStream

objOutputStream = New FileStream(strTargetFile, FileMode.Create, FileAccess.Write)

Dim iByteSize As Integer = 0
Dim aDownBuffer(BUF_SIZE) As Byte

iByteSize = objResponseStream.Read(aDownBuffer, 0, aDownBuffer.Length)

While (iByteSize > 0)
objOutputStream.Write(aDownBuffer, 0, iByteSize)
iByteSize = objResponseStream.Read(aDownBuffer, 0, aDownBuffer.Length)
End While

Catch ex As System.Net.WebException
'Handling exception

Finally
If Not objResponseStream Is Nothing Then
objResponseStream.Close()
End If

If Not objOutputStream Is Nothing Then
objOutputStream.Close()
End If

End Try

Can anyone give me a suggestion that how to solve this issue?

Thanks and Regards

SSaud
 
Old May 14th, 2007, 08:09 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What good does multiple threads do for you? Your download is limited by the available bandwidth so multiple threads are just sharing the same pipe. While I am no TCP/IP expert I would think that having multiple connections would actually be less efficient if you are talking to the same system because of the overhead (as small as it may be) of the two connections.

-Peter
 
Old May 14th, 2007, 08:26 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I agree with Peter on this. You are not gaining anything by using multiple threads, other then being able to create multiple connections to your remote system to pull down files.

I am not sure that you have taken into consideration the impact that your code will have on your users though. Given the availability of High Speed Connections, a 90mb file seems like a trivial matter to download (whether it be 1 90mb file or 10 9meg files) but someone that is connection to you code on, say, a dial up connection is going to absolutely dispise your application.

The reason being is they have a lot smaller downstream pipe on their modem so when you create, say 10 requests, to download your files, they are going to have an overall slower transfer rate on each of the 10 requests then if you created just 1 request to 1 90mb file.

Most of what I said is just a further explination of what Peter originally said: Your download is limited by the available bandwidth. (Both on your side and on the server side)

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 15th, 2007, 12:27 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your time and replies. Yes I have understood your remarks and am agreed with both of you. I got the answer of my initial question i.e. I can set the number of active connections using ServicePointManager.DefaultConnectionLimit property. But, I have tested my application and its performance gain is not good. :(

But, I want to know that how different download managers or download acclerator applications are using segmented download? What technique are they using for it to accelarate our download speed? If there isn't any performance gain why are they implemented so?

Please make your remarks.

Thanks and Regards

SSaud
 
Old May 15th, 2007, 06:56 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

A file download is a file download is a file download. For example, the download manager in firefox is simply a GUI that shows you how many active downloads you currently have working, it is not making your system preform any better during the download, it is just a convienent place to see all of your active downloads. (And files that you have already downloaded for that matter)

How fast the download comes down the pipe is related to your downstream capability and the servers upstream capability, nothing you can do is going to increase the preformance of that.

hth.



================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using PHP to open a large file... arholly PHP How-To 0 March 6th, 2007 06:29 PM
Flash file downloading Adam H-W Flash (all versions) 1 December 15th, 2006 11:36 PM
Downloading a File RobC ASP.NET 2.0 Basics 4 February 4th, 2006 09:37 PM
Split large file to chunks eelisMX Pro VB.NET 2002/2003 4 February 8th, 2005 04:48 AM
Downloading Excel File [email protected] VB How-To 0 October 28th, 2004 11:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.