406617 Spin in Request.recylce

removed loop from read, so only a single attempt a blocking for content.
This commit is contained in:
Greg Wilkins 2013-05-02 12:57:48 +10:00
parent 92a39fcb08
commit 22b0098be7
2 changed files with 39 additions and 17 deletions

View File

@ -561,6 +561,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
if (getEndPoint().isInputShutdown()) if (getEndPoint().isInputShutdown())
{ {
_parser.shutdownInput(); _parser.shutdownInput();
shutdown();
return; return;
} }

View File

@ -96,21 +96,26 @@ public abstract class HttpInput<T> extends ServletInputStream
T item = null; T item = null;
synchronized (lock()) synchronized (lock())
{ {
while (item == null) // Get the current head of the input Q
{
item = _inputQ.peekUnsafe(); item = _inputQ.peekUnsafe();
// Skip empty items at the head of the queue
while (item != null && remaining(item) == 0) while (item != null && remaining(item) == 0)
{ {
_inputQ.pollUnsafe(); _inputQ.pollUnsafe();
onContentConsumed(item); onContentConsumed(item);
LOG.debug("{} consumed {}", this, item); LOG.debug("{} consumed {}", this, item);
item = _inputQ.peekUnsafe(); item = _inputQ.peekUnsafe();
// If that was the last item then notify
if (item==null)
onAllContentConsumed();
} }
// If we have no item
if (item == null) if (item == null)
{ {
onAllContentConsumed(); // Was it unexpectedly EOF'd?
if (isEarlyEOF()) if (isEarlyEOF())
throw new EofException(); throw new EofException();
@ -121,7 +126,23 @@ public abstract class HttpInput<T> extends ServletInputStream
return -1; return -1;
} }
// OK then block for some more content
blockForContent(); blockForContent();
// If still not content, we must be closed
item = _inputQ.peekUnsafe();
if (item==null)
{
if (isEarlyEOF())
throw new EofException();
// blockForContent will only return with no
// content if it is closed.
if (!isShutdown())
LOG.warn("unexpected !EOF state");
onEOF();
return -1;
} }
} }
} }