Skip to content

Commit

Permalink
#9900: only take begin nanotime once per stream
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban committed Nov 23, 2023
1 parent 03f2e76 commit 0ebea03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -65,7 +66,11 @@ public Parser(ByteBufferPool bufferPool, int maxHeaderSize, RateControl rateCont
{
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];
}

Expand Down Expand Up @@ -104,6 +109,18 @@ private void reset()
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;
}
}

/**
Expand All @@ -121,13 +138,13 @@ public void parse(ByteBuffer buffer)
{
try
{
takeNanoTime();
while (true)
{
switch (state)
{
case HEADER:
{
beginNanoTime = NanoTime.now(); // TODO #9900 check beginNanoTime's accuracy
if (!parseHeader(buffer))
return;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;

Expand Down Expand Up @@ -87,14 +86,13 @@ public void parse(ByteBuffer buffer)
{
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)
Expand Down

0 comments on commit 0ebea03

Please sign in to comment.