Only queue write when not queued
This commit is contained in:
parent
7cc51959d9
commit
480996433e
|
|
@ -16,7 +16,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
public const int MaxPooledWriteReqs = 1024;
|
public const int MaxPooledWriteReqs = 1024;
|
||||||
|
|
||||||
private const int _maxPendingWrites = 3;
|
|
||||||
private const int _maxBytesPreCompleted = 65536;
|
private const int _maxBytesPreCompleted = 65536;
|
||||||
private const int _initialTaskQueues = 64;
|
private const int _initialTaskQueues = 64;
|
||||||
private const int _maxPooledWriteContexts = 32;
|
private const int _maxPooledWriteContexts = 32;
|
||||||
|
|
@ -44,7 +43,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
|
|
||||||
// The number of write operations that have been scheduled so far
|
// The number of write operations that have been scheduled so far
|
||||||
// but have not completed.
|
// but have not completed.
|
||||||
private int _writesPending = 0;
|
private bool _writePending = false;
|
||||||
private int _numBytesPreCompleted = 0;
|
private int _numBytesPreCompleted = 0;
|
||||||
private Exception _lastWriteError;
|
private Exception _lastWriteError;
|
||||||
private WriteContext _nextWriteContext;
|
private WriteContext _nextWriteContext;
|
||||||
|
|
@ -139,10 +138,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
_tasksPending.Enqueue(tcs);
|
_tasksPending.Enqueue(tcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_writesPending < _maxPendingWrites && immediate)
|
if (!_writePending && immediate)
|
||||||
{
|
{
|
||||||
|
_writePending = true;
|
||||||
scheduleWrite = true;
|
scheduleWrite = true;
|
||||||
_writesPending++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,6 +257,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
|
|
||||||
lock (_contextLock)
|
lock (_contextLock)
|
||||||
{
|
{
|
||||||
|
_writePending = false;
|
||||||
|
|
||||||
if (_nextWriteContext != null)
|
if (_nextWriteContext != null)
|
||||||
{
|
{
|
||||||
writingContext = _nextWriteContext;
|
writingContext = _nextWriteContext;
|
||||||
|
|
@ -265,26 +266,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_writesPending--;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
writingContext.DoWriteIfNeeded();
|
||||||
{
|
|
||||||
writingContext.DoWriteIfNeeded();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
lock (_contextLock)
|
|
||||||
{
|
|
||||||
// Lock instead of using Interlocked.Decrement so _writesSending
|
|
||||||
// doesn't change in the middle of executing other synchronized code.
|
|
||||||
_writesPending--;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called on the libuv event loop
|
// This is called on the libuv event loop
|
||||||
|
|
@ -311,10 +297,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
if (_nextWriteContext != null)
|
if (_nextWriteContext != null)
|
||||||
{
|
{
|
||||||
scheduleWrite = true;
|
scheduleWrite = true;
|
||||||
}
|
_writePending = true;
|
||||||
else
|
|
||||||
{
|
|
||||||
_writesPending--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// _numBytesPreCompleted can temporarily go negative in the event there are
|
// _numBytesPreCompleted can temporarily go negative in the event there are
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue