Hi,
I am doing a binaryWrite to allow users to download files. The problem
occurs if the file is too big. Some of the files i have are close to
100 megs. I read on msdn that if the data is greater than 4MB it is
advisable to break it up into multiple chunks http://msdn.microsoft.com/library/de...4b95130b4a.asp
How would that be done?
Thanks for your time and help :)
ps below is the sub i use for streaming
Private Sub streamDocs(path, filename, originalFileName, contentType)
Response.AddHeader
"content-disposition","attachment;filename="&originalFileNa me
Response.ContentType = contentType
Dim BinaryStream, Fil, fs
Set BinaryStream = CreateObject("ADODB.Stream")
set fs = Server.CreateObject("Scripting.FileSystemObject")
Set Fil = fs.GetFile(path & "\" &filename) 'Open file
BinaryStream.Type = 1
BinaryStream.Open
BinaryStream.LoadFromFile Fil.path
Response.BinaryWrite BinaryStream.Read
BinaryStream.Cancel
BinaryStream.Close
set BinaryStream = nothing
End sub 12 7594
On Wed, 13 Sep 2006 09:03:42 -0500, Katie <Dn*********@gmail.comwrote:
Hi,
I am doing a binaryWrite to allow users to download files. The problem
occurs if the file is too big. Some of the files i have are close to
100 megs. I read on msdn that if the data is greater than 4MB it is
advisable to break it up into multiple chunks
The optional first argument to the Read() method will allows you to
specify the maximum number of bytes read. So where you have this:
Response.BinaryWrite BinaryStream.Read
You could change it to this to write data in thousand-byte chunks:
Dim i
For i = 0 To BinaryStream.Size
Response.BinaryWrite BinaryStream.Read(1000)
Next
You can find documentation for all of the Stream object's properties and
methods on Microsoft's website.
Stream Object Properties, Methods, and Events http://windowssdk.msdn.microsoft.com.../ms677486.aspx
--
Justin Piper
Bizco Technologies http://www.bizco.com/
On Wed, 13 Sep 2006 09:22:36 -0500, Justin Piper <jp****@bizco.comwrote:
For i = 0 To BinaryStream.Size
Whoops, that should of course read, "For i = 0 To BinaryStream.Size Step
1000".
--
Justin Piper
Bizco Technologies http://www.bizco.com/
Justin Piper wrote on 13 sep 2006 in
microsoft.public.inetserver.asp.general:
On Wed, 13 Sep 2006 09:22:36 -0500, Justin Piper <jp****@bizco.com>
wrote:
> For i = 0 To BinaryStream.Size
Whoops, that should of course read, "For i = 0 To BinaryStream.Size
Step 1000".
or:
For i = 0 To BinaryStream.Size/1000
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
On Wed, 13 Sep 2006 09:43:34 -0500, Evertjan.
<ex**************@interxnl.netwrote:
Justin Piper wrote on 13 sep 2006 in
microsoft.public.inetserver.asp.general:
>On Wed, 13 Sep 2006 09:22:36 -0500, Justin Piper <jp****@bizco.com> wrote:
>> For i = 0 To BinaryStream.Size
Whoops, that should of course read, "For i = 0 To BinaryStream.Size Step 1000".
or:
For i = 0 To BinaryStream.Size/1000
Well, as long as we're splitting hairs, using "Step" is about 30% faster.
:)
E:\jpiper\Documents\Scripts\VBScript\prof
cscript step.vbs
Step 2.122266s
Div 3.476563s
step.vbs:
Option Explicit
Function Prof(f)
Dim start, finish, i, total
total = 0
For i = 0 To 9
start = Timer()
f
finish = Timer()
total = total + finish - start
Next
Prof = total/10
End Function
Sub ProfStep()
Dim i: For i = 0 To 1000000000 Step 100 : Next
End Sub
WScript.Echo "Step" & vbTab & Prof(GetRef("ProfStep")) & "s"
Sub ProfDiv()
Dim j: j = 1000000000 / 100
Dim i: For i = 0 To j : Next
End Sub
WScript.Echo "Div" & vbTab & Prof(GetRef("ProfDiv")) & "s"
--
Justin Piper
Bizco Technologies http://www.bizco.com/
Justin Piper wrote on 13 sep 2006 in
microsoft.public.inetserver.asp.general:
>For i = 0 To BinaryStream.Size/1000
Well, as long as we're splitting hairs, using "Step" is about 30%
faster.
:)
Oh, if you wish, try:
temp = int(BinaryStream.Size/1000)+1
For i = 0 To temp
However I do not believe you are right, Justin, with the 30%,
as BinaryStream.Read(1000) and the response.write
will take much more cpu time,
than the repetitive for-next division by 1000 overhead.
I guess it will be muh ess than 1%.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
On Wed, 13 Sep 2006 11:40:05 -0500, Evertjan.
<ex**************@interxnl.netwrote:
Justin Piper wrote on 13 sep 2006 in
microsoft.public.inetserver.asp.general:
>>For i = 0 To BinaryStream.Size/1000 Well, as long as we're splitting hairs, using "Step" is about 30% faster. :)
Oh, if you wish, try:
temp = int(BinaryStream.Size/1000)+1
For i = 0 To temp
Int() doesn't change the type of the variable, but yes, once you eliminate
the floating point arithmetic they are equivalent.
However I do not believe you are right, Justin, with the 30%,
as BinaryStream.Read(1000) and the response.write
will take much more cpu time,
than the repetitive for-next division by 1000 overhead.
I guess it will be muh ess than 1%.
Oh, naturally this will all be lost in the noise. But as far as ".Size
Step 1000" itself, it is indeed significantly faster than ".Size/1000".
And I /did/ warn you I was splitting hairs. :)
--
Justin Piper
Bizco Technologies http://www.bizco.com/
Hi,
Thanks for your help.
It works :)
Just wondering is there a particular value for the data size that is
optimal or can i use any e.g. 1000kb
Thanks
:)
Justin Piper wrote:
On Wed, 13 Sep 2006 11:40:05 -0500, Evertjan.
<ex**************@interxnl.netwrote:
Justin Piper wrote on 13 sep 2006 in
microsoft.public.inetserver.asp.general:
>For i = 0 To BinaryStream.Size/1000
Well, as long as we're splitting hairs, using "Step" is about 30%
faster.
:)
Oh, if you wish, try:
temp = int(BinaryStream.Size/1000)+1
For i = 0 To temp
Int() doesn't change the type of the variable, but yes, once you eliminate
the floating point arithmetic they are equivalent.
However I do not believe you are right, Justin, with the 30%,
as BinaryStream.Read(1000) and the response.write
will take much more cpu time,
than the repetitive for-next division by 1000 overhead.
I guess it will be muh ess than 1%.
Oh, naturally this will all be lost in the noise. But as far as ".Size
Step 1000" itself, it is indeed significantly faster than ".Size/1000".
And I /did/ warn you I was splitting hairs. :)
--
Justin Piper
Bizco Technologies http://www.bizco.com/
On Wed, 13 Sep 2006 13:35:45 -0500, Katie <Dn*********@gmail.comwrote:
Just wondering is there a particular value for the data size that is
optimal or can i use any e.g. 1000kb
Well, a 1000KB block size would mean that everyone downloading a file
would be using as much memory, so only do that if you won't have to
support more than a few connections at a time. If you want to find the
sweet spot you might try Microsoft's Web Application Stress Tool[1], but
if it were me, I'd just arbitrarily pick a nice round number and call it
good.
[1] Download details: Web Application Stress Tool http://www.microsoft.com/downloads/d...displaylang=en
--
Justin Piper
Bizco Technologies http://www.bizco.com/
"Katie" <Dn*********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Hi,
Thanks for your help.
It works :)
Just wondering is there a particular value for the data size that is
optimal or can i use any e.g. 1000kb
Katie,
My apologies I did have your earlier post on this subject marked for a
response but I never did get round it.
Unfortunately the code posted so far contains a small bug that will result
in a truncation of the file to the nearest mutliple of the chunk size.
Const mclChunkSize = &H200000
Dim i
Response.Buffer = False
For i = 0 To BinaryStream.Size Step mclChunkSize
Response.BinaryWrite BinaryStream.Read(mclChunkSize)
Next
If (BinaryStream.Size Mod mclChunkSize) 0 Then
Response.BinaryWrite BinaryStream.Read(BinaryStream.Size Mod
mclChunkSize)
End If
Choice of chunk size will affect the download performance. You shoud choose
a good size like the 1Mb you proposed. Using a very small chunk size such
as 1000 is inefficient (even a single TCP/IP packet can carry a larger
payload) and each Response.BinaryWrite will block until all acknowledgements
for data sent has been received from the client. By using a larger chunk
size you let the TCP/IP stack do it's work far more effeciently.
Justin has pointed out there is a trade off between chunksize and server
memory use. However, it's worth bearing in mind that by default only 10
requests will be processed per CPU anyway (although this may be increased it
shouldn't really exceed 25) hence a chunksize of 2MB only represents 20MB -
50MB per CPU and that assumes all worker threads are busy responding to
download requests.
Anthony.
Thanks
:)
Justin Piper wrote:
On Wed, 13 Sep 2006 11:40:05 -0500, Evertjan.
<ex**************@interxnl.netwrote:
Justin Piper wrote on 13 sep 2006 in
microsoft.public.inetserver.asp.general:
>
>>For i = 0 To BinaryStream.Size/1000
>>>
>>
>Well, as long as we're splitting hairs, using "Step" is about 30%
>faster.
>:)
>>
>
Oh, if you wish, try:
>
temp = int(BinaryStream.Size/1000)+1
For i = 0 To temp
Int() doesn't change the type of the variable, but yes, once you
eliminate
the floating point arithmetic they are equivalent.
However I do not believe you are right, Justin, with the 30%,
as BinaryStream.Read(1000) and the response.write
will take much more cpu time,
than the repetitive for-next division by 1000 overhead.
>
I guess it will be muh ess than 1%.
Oh, naturally this will all be lost in the noise. But as far as ".Size
Step 1000" itself, it is indeed significantly faster than ".Size/1000".
And I /did/ warn you I was splitting hairs. :)
--
Justin Piper
Bizco Technologies http://www.bizco.com/
On Thu, 14 Sep 2006 03:32:02 -0500, Anthony Jones <An*@yadayadayada.com>
wrote:
>
"Katie" <Dn*********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>Just wondering is there a particular value for the data size that is optimal or can i use any e.g. 1000kb
Unfortunately the code posted so far contains a small bug that will
result in a truncation of the file to the nearest mutliple of the
chunk size.
Ah, well, there is actually a bug, but that isn't it. This works fine,
so long as test.txt is not an even multiple of the block size:
<% Option Explicit
Dim stream, i
Response.ContentType = "text/plain"
Set stream = CreateObject("ADODB.Stream")
With stream
.Type = 1
.Open
.LoadFromFile Server.MapPath("test.txt")
End With
For i = 0 To stream.Size Step 1000
Response.BinaryWrite stream.Read(1000)
Next
%>
When its size is an even multiple, we actually go through the loop once
more than necessary, and the last call to Read() returns Null. You had
the right idea, though. All that's needed is to change "For i = 0" to
"For i = 1" and then write any remaining bytes.
<% Option Explicit
Dim stream, i
Const BlockSize = 1000
Response.ContentType = "text/plain"
Set stream = CreateObject("ADODB.Stream")
With stream
.Type = 1
.Open
.LoadFromFile Server.MapPath("test.txt")
End With
For i = 1 To stream.Size Step BlockSize
Response.BinaryWrite stream.Read(BlockSize)
Next
If stream.Size Mod BlockSize 0 Then Response.Write stream.Read
%>
Justin has pointed out there is a trade off between chunksize and
server memory use. However, it's worth bearing in mind that by
default only 10 requests will be processed per CPU anyway (although
this may be increased it shouldn't really exceed 25) hence a
chunksize of 2MB only represents 20MB - 50MB per CPU and that assumes
all worker threads are busy responding to download requests.
That's a good point. I was thinking of how only a few hundred downloads
would be all that's needed to cause paging, but hadn't considered the
any of the _other_ logistical problems you'd encounter in such a
scenerio.
--
Justin Piper
Bizco Technologies http://www.bizco.com/
On Thu, 14 Sep 2006 09:43:53 -0500, Justin Piper <jp****@bizco.comwrote:
If stream.Size Mod BlockSize 0 Then Response.Write stream.Read
Agh. This has not been my week. That should be:
If Not stream.EOS Then Response.BinaryWrite stream.Read
It only appeared to work since Response.Write will dutifly write nothing
if you tell it to. :P
--
Justin Piper
Bizco Technologies http://www.bizco.com/
Thanks for your help :)
Justin Piper wrote:
On Thu, 14 Sep 2006 09:43:53 -0500, Justin Piper <jp****@bizco.comwrote:
If stream.Size Mod BlockSize 0 Then Response.Write stream.Read
Agh. This has not been my week. That should be:
If Not stream.EOS Then Response.BinaryWrite stream.Read
It only appeared to work since Response.Write will dutifly write nothing
if you tell it to. :P
--
Justin Piper
Bizco Technologies http://www.bizco.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ad |
last post by:
I want to send a DataSet to WebService, but the DataSet if too huge(there
about 50000 records, and 50 fields every record).
My solution is
1.save the DataSet as XML file,
2.zip the XML file.
3....
|
by: Alec MacLean |
last post by:
Hi,
I've created a small application for our company extranet (staff bulletins)
that outputs a list of links to PDF's that are stored in a SQL table. The
user clicks a link and the PDF is...
|
by: Claudio Grondi |
last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want
to change only eight bytes in this file at a given offset of appr. 200
Gbyte (all other data in that file should remain...
|
by: Katie |
last post by:
Hi,
I made a posting a while ago regarding doing a binarywrite of a large
file in chunks and got a lot of helpful responses. I was able to make
it work then. Unfortunately when the project is...
|
by: keerthyragavendran |
last post by:
hi
i'm downloading a single file using multiple threads...
how can i specify a particular range of bytes alone from a single
large file... for example say if i need only bytes ranging from...
|
by: David |
last post by:
I have googled to no avail on getting specifically what I'm looking for. I
have found plenty of full blown apps that implement some type of file
transfer but what I'm specifcally looking for is an...
|
by: WATYF |
last post by:
Hi there... I have a huge text file that needs to be processed. At the
moment, I'm loading it into memory in small chunks (x amount of lines)
and processing it that way. I'd like the process to be...
|
by: Dom Rout |
last post by:
Hello.
Well, this is my first post on any USENET group anywhere, so I hope I
get it right. Basically, I just want to get some opinions on a plan of
mine for a new project.
I want to produce a...
|
by: henry |
last post by:
Folks:
As a follow-up to my recent posts, I want to ask some more general questions
about multiple instances of a CSS link in a page as seen by browsers due to
server-side file inclusion. Let...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |