I have a files controller that is responsible for handling uploaded files in chunks (1 MB chunks). I took my time testing this in development and everything is as expected. The following is the pseudo code of an action:
我有一个文件控制器负责处理块中的上传文件(1 MB块)。我花了我的时间在开发中测试它,一切都如预期。以下是操作的伪代码:
logger.Log("Getting InputStream");
var stream = Request.InputStream; // Here is the wait.
logger.Log("Got InputStream");
var bytes = GetByteArray(stream); // This is always less than 1 MB.
await FilesService.AppendToFileAsync(key, fileName, owner, bytes); // Write to the file.
// The GetByteArray method
private byte[] GetByteArray(Stream stream)
{
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
return bytes;
}
The specifics aren't terribly important. I'm getting the bytes then I'm appending them to the file on disk.
具体细节并不十分重要。我正在获取字节,然后我将它们附加到磁盘上的文件中。
In production however, things get weird. This is the request timeline of one chunk being uploaded (in production):
然而,在生产中,事情变得奇怪。这是一个上传的块(在生产中)的请求时间线:
By means of logging I absolutely know that all the waiting time is being spent in the Request.InputStream
prop.
通过记录我绝对知道所有的等待时间都花在了Request.InputStream道具上。
The waiting time is somewhere between 1 min - 3 mins.
等待时间介于1分钟到3分钟之间。
My Question
- Does this mean the server is just taking that much time downloading the request? (though I really doubt that)
- 这是否意味着服务器只花了那么多时间下载请求? (虽然我真的怀疑)
- Or is it that I'm doing something wrong here?
- 还是我在这里做错了什么?
And a small question: is the Request sent
timeline telling me when the content bytes are done being received on the other side?
还有一个小问题:请求发送时间线告诉我何时在另一方接收到内容字节?
I know that perhaps I should write a file upload handler or something, but does that really make that much of a difference?
我知道也许我应该写一个文件上传处理程序或者其他东西,但是这真的会产生很大的不同吗?
So, what's going on?
发生什么了?
EDIT:
Of course, I looked into a lot of seemingly related issues but nothing hit the mark.
当然,我调查了许多看似相关的问题,但没有任何结果。
- I firstly suspected that the appdomain was being recycled on every chunk request (because I'm writing to a file) but I confirmed that this not the case from the logs. Also it wouldn't make any sense since the wait is on
Request.InputStream
. - 我首先怀疑appdomain是在每个chunk请求上被回收的(因为我正在写一个文件)但我确认这不是日志中的情况。它也没有任何意义,因为等待是在Request.InputStream上。
EDIT 2:
I just tested with GetBufferlessInputStream
with manual reading inside the same action and the result is the same. Now I'm sure the wait is while reading the request stream. At this point, I'm getting the feeling that the server is just that slow with getting the request. I contacted my host and they said they don't put a limit on the speed and it shouldn't be slow.
我刚用GetBufferlessInputStream测试了同一个动作内部的手动读取,结果是一样的。现在我确定等待是在读取请求流时。此时,我感觉到服务器获取请求的速度很慢。我联系了我的主人,他们说他们没有限制速度,也不应该慢。
To confirm this, this is one of my logs while a chunk was being uploaded:
要确认这一点,这是我上传一个块时的日志之一:
2015-09-15 23:23:12.6419|Entered upload chunk // This is the action.
2015-09-15 23:23:12.6419|Got bufferless stream // var s = Request.GetBufferlessStream()
2015-09-15 23:23:12.6419|Stream length: 1048576 (1 MB) // s.Length
2015-09-15 23:23:12.6419|Reading stream... // Here is the wait, this time it was not much (~26 secs) but it's still a lot.
2015-09-15 23:23:38.8211|Read stream of size 1048576 bytes (1 MB)
and this is how I'm reading it:
这就是我读它的方式:
var b = new byte[s.Length];
var read = 0;
var c = 0;
while ((c = s.Read(b, read, b.Length - read)) != 0)
{
read += c;
}
1 个解决方案
#1
1
You should change the plan , there are tons of sites on that server Get enrolled in an advanced plan to increase your download speed
您应该更改计划,该服务器上有大量站点获取注册高级计划以提高下载速度
#1
1
You should change the plan , there are tons of sites on that server Get enrolled in an advanced plan to increase your download speed
您应该更改计划,该服务器上有大量站点获取注册高级计划以提高下载速度