I am working on performance improvement for an application that allows user to download quite big files (like 1 GB and bigger). I made a very simple example that just takes a file from the storage and returns it via StreamContent:
var fileStream = System.IO.File.Open(@"C:\files\1GB.bin", FileMode.Open,
FileAccess.Read);
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Headers.AcceptRanges.Add("bytes");
var content = new StreamContent(fileStream, BufferSize);
response.Content = content;
Playing with BufferSize, as suggested in ASP.NET Web API 2 - StreamContent is extremely slow helped to improve performance. However, then comparing this download method with simple Node static server (I'm using https://www.npmjs.com/package/serve) there is a very big difference in download speed.
I would like to understand what could be the reason for it taking into consideration the following:
- Testing is done in one network, the machine that downloads the file is in the same network as the one that has servers running
- Serve is accessed via IP address through http, like http://172.12.22.4, website is accessed via URL https://wwww.testenv.com/api/getfile
- The file is the same and stored in the network folder on another machine, the network is the same
- The difference in performance is several times (the file is downloaded at ~80-90 MB/s per second through Web API, 240-270 MB/s through serve)
- When downloading the file through https://wwww.testenv.com/api/getfile on the same machine where the servers are running (i.e. locally), the speed is higher (~150 MB/s but still lower than using Node server through the network)
- There are several IIS websites running on the IIS server with different URLs implemented using Binding redirects
So it is really interesting what causes the difference in performance. Can it be using binding redirects, or https, or public URL instead of IP address? It is also interesting that even local download through IIS is still slower than network download through Node serve.
The test downloads were done either to memory or disk, the results were roughly the same.