views:

39

answers:

3

Hi, I was wondering if there is any difference in performance (or any other important factor) between a file sent to the browser from our server by this method :

For i = 1 To fileSize \ chunk
  If Not Response.IsClientConnected Then Exit For
  Response.BinaryWrite stream.Read(chunk)
  Response.Flush
Next

VS

the old plain file access method that the IIS comes with.

We are working on a file manager handler for security reasons and would like to know what is the performance hit.

Thanks

+2  A: 

Both methods need to push binary data to the browser.

would like to know what is the performance hit.

Like always in such cases: measure. Try to optimize settings on IIS and measure again until you get the most optimal solution.

XIII
Which settings in IIS would one optimize to get the best performance in this case?
AnthonyWJones
+1  A: 

Unless you are dealing with a fairly large file, there shouldn't be a noticeable difference. Since you are creating the chunks manually and the flushing the buffer, you are going to have more packet traffic to the client (the payload of the packet or the last packet will be only partially full). However, as I said, this probably won't be noticeable unless you have a large file and even then it's not likely to show up.

Tarwn
Last time I tested this `Flush` would block until all ACKs for the flushed packets had been received. The latency involved in this results in a much greater download time that you might have otherwise thought. Its possible that IIS7 may have changed this behaviour. Using a large buffer size (like 64K) can minimise both the impact of this latency and the number of extra packets sent.
AnthonyWJones
I was trying very hard not to answer with "It Depends" :)There were some changes made in between IIS 5 + 6, but there are some extra factors: Are you counting performance as performance of running the server-side script, total time from request to delivery, resource load on the server? While blocking will occur, the amount is dependent on the amount of data you are flushing (as you point out below), the whole thing will depend on the size of the files (at which point you have to balance memory usage on server against blocking/network latency/under-sizing packets), etc.
Tarwn
Thanks, We will run some test to see whats the network overload for dividing the chunks like this.
Eliran
A: 

In my experience chunking stuff down using script is significantly slower than IIS's highly optimised static file handling. How much slower depends on too many factors I've seen up to 10 times when other poor choices have been made (like using 4096 bytes as the buffer size).

Some things may have improved on IIS7 but if you can fetch the file as static content I would definitely go with that.

AnthonyWJones