-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cleanups of DateCache #10176
cleanups of DateCache #10176
Conversation
Signed-off-by: Lachlan Roberts <[email protected]>
Signed-off-by: Lachlan Roberts <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've missed the difference between format
and formatNow
. With this change, the cache is now vulnerable to being set to a tick from any time and thus could miss more frequently.
Perhaps we can just have a single format method, but it must only update the _tick with the current time.
|
||
Tick tick = _tick; | ||
// recheck the tick, to save multiple formats | ||
if (tick == null || tick._seconds != seconds) | ||
{ | ||
String s = ZonedDateTime.ofInstant(Instant.ofEpochMilli(now), _zoneId).format(_tzFormat); | ||
String s = formatWithoutCache(inDate); | ||
_tick = new Tick(seconds, s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now being used to format arbitrary times, so the tick cache could be hoping all over time.
Maybe we change this to never cache a passed in time, but to only ever cache the format of now. If the passed in time is in a different tick, we then check the tick time against now and only reformat that if now has changed? |
@gregw the major user of For the minor usages, I think we can just format on-the-fly all the time. In The other use case, currently unused in the Jetty codebase, is for applications that want to set the I'm not sure |
If someone wants to format their request timestamp with millisecond accuracy (see #10153), how will a |
It cannot. |
The |
Maybe... also with millisecond support again would be good. I think just having the last 2 seconds should be sufficient, as if requests are taking more than 2s to complete, then formatting dates is not going to be the hot path (OK perhaps if they are really async?) The main issue will be for quick requests that are finishing in about the same time, then as the second clicks from 1 to the next, we might get the requests from different threads in the wrong order, thus a lot more formatting might take place as the second changes over. The simplest fix would be to only let the tick monotonically increase and never go back in time, whilst always formatting the current time. That would reduce the cache itself fibrillating as the second changes, but it might mean that a few threads will finish requests for the previous second and need to do formatting. So having the current second and the previous second would probably save 10s of formats per second, not a huge saving for a bit of extra complexity. Eitherway, I agree that we leave the server using it's |
@sbordet |
Looking back at Jetty 6, we didn't support |
Ah, Jetty 6.0.2 had support for So the support for |
phew!!! the memory is not totally shot!.... yet! |
Signed-off-by: Lachlan Roberts <[email protected]>
Signed-off-by: Lachlan Roberts <[email protected]>
…ferent size Signed-off-by: Lachlan Roberts <[email protected]>
…to have cache miss Signed-off-by: Lachlan Roberts <[email protected]>
Signed-off-by: Lachlan Roberts <[email protected]>
…k with sub second time Signed-off-by: Lachlan Roberts <[email protected]>
Signed-off-by: Lachlan Roberts <[email protected]>
@gregw an index in the format string does not correspond to the same index in the formatted date, many of the date codes expand to different sizes when formatting a date, even dynamically depending on the time of day / week / month etc. So we can only figure out the correct index when we create the Using separate formatters for the suffix and prefix is marginally faster, but both are around 10 times slower than using the cached ms time. |
…at code Signed-off-by: Lachlan Roberts <[email protected]>
Signed-off-by: Lachlan Roberts <[email protected]>
Signed-off-by: Lachlan Roberts <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close but....
Signed-off-by: Lachlan Roberts <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fairly complicated now, but speed(ier).
JMH results on my hardware, compensating for the Instant
allocation so that testDateCache()
does Instant.now().toEpochMillis()
:
DateCacheBenchmark.testDateCache thrpt 3 42247477.161 ± 51521167.555 ops/s
DateCacheBenchmark.testDateTimeFormatter thrpt 3 8058916.049 ± 466843.119 ops/s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just niggles... but let's get this merged
return _seconds; | ||
} | ||
|
||
public String getString(long inDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public String getString(long inDate) | |
public String format(long inDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
private volatile Tick _tick; | ||
private volatile TickHolder _tickHolder; | ||
|
||
private static class TickHolder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a record?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, this is jetty-10 so we can't use records
Signed-off-by: Lachlan Roberts <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was 2 lines you changed not 1 :)
@lachlan-roberts can you squash merge this soon? |
@lachlan-roberts do you need superpowers to merge this to 11 & 12 or are you going to do PRs? |
Yes, it has been merged to 12 already. |
DateCache.format
now actually uses the cache.formatWithoutCache
method.ZZZ
is unnecessary.Maybe this should be for 12 only, there could be some change in behaviour if someone is relying on
DateCache.format
to not use the cache (even though the javadoc says it does).