#9900: only take begin nanotime once per stream

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2023-11-21 15:03:42 +01:00
parent 03f2e76da5
commit 0ebea03577
2 changed files with 21 additions and 6 deletions

View File

@ -54,7 +54,8 @@ public class Parser
private int maxSettingsKeys = SettingsFrame.DEFAULT_MAX_KEYS;
private boolean continuation;
private State state = State.HEADER;
protected long beginNanoTime = Long.MIN_VALUE;
private long beginNanoTime = Long.MIN_VALUE;
private boolean nanoTimeRead = true;
public Parser(ByteBufferPool bufferPool, int maxHeaderSize)
{
@ -65,7 +66,11 @@ public class Parser
{
this.bufferPool = bufferPool;
this.headerParser = new HeaderParser(rateControl == null ? RateControl.NO_RATE_CONTROL : rateControl);
this.hpackDecoder = new HpackDecoder(maxHeaderSize, () -> beginNanoTime);
this.hpackDecoder = new HpackDecoder(maxHeaderSize, () ->
{
nanoTimeRead = true;
return beginNanoTime;
});
this.bodyParsers = new BodyParser[FrameType.values().length];
}
@ -104,6 +109,18 @@ public class Parser
headerParser.reset();
state = State.HEADER;
beginNanoTime = Long.MIN_VALUE;
nanoTimeRead = true;
}
protected void takeNanoTime()
{
if (nanoTimeRead)
{
beginNanoTime = NanoTime.now(); // TODO #9900 check beginNanoTime's accuracy
if (beginNanoTime == Long.MIN_VALUE)
beginNanoTime++;
nanoTimeRead = false;
}
}
/**
@ -121,13 +138,13 @@ public class Parser
{
try
{
takeNanoTime();
while (true)
{
switch (state)
{
case HEADER:
{
beginNanoTime = NanoTime.now(); // TODO #9900 check beginNanoTime's accuracy
if (!parseHeader(buffer))
return;
break;

View File

@ -21,7 +21,6 @@ import org.eclipse.jetty.http2.RateControl;
import org.eclipse.jetty.http2.frames.FrameType;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.NanoTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -87,14 +86,13 @@ public class ServerParser extends Parser
{
if (LOG.isDebugEnabled())
LOG.debug("Parsing {}", buffer);
takeNanoTime();
while (true)
{
switch (state)
{
case PREFACE:
{
beginNanoTime = NanoTime.now(); // TODO #9900 check beginNanoTime's accuracy
if (!prefaceParser.parse(buffer))
return;
if (notifyPreface)