Skip to content

Conversation

joegallo
Copy link
Contributor

Each commit is a different optimization, and they all matter (just a little). Here's the flamegraph before (with areas highlighted):

Screenshot 2025-01-24 at 12 26 36 PM

And after:

Screenshot 2025-01-24 at 12 26 44 PM

This saves us the expensive time to retrieve and set the nanoseconds part of the Instant.
@joegallo joegallo added >enhancement :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP Team:Data Management Meta label for data/management team auto-backport Automatically create backport pull requests when merged v9.0.0 v8.18.0 labels Jan 24, 2025
@joegallo joegallo requested a review from masseyke January 24, 2025 17:44
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@elasticsearchmachine
Copy link
Collaborator

Hi @joegallo, I've created a changelog YAML for you.


public boolean isCloseToExpiration() {
return Instant.ofEpochMilli(lastCheck).isBefore(Instant.now().minus(25, ChronoUnit.DAYS));
final Instant now = Instant.ofEpochMilli(System.currentTimeMillis()); // millisecond precision is sufficient (and faster)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could pass in a ThreadPool, and use ThreadPool::absoluteTimeInMillis, which would be significantly faster since it's cached. Same goes in the other place below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I'll see if I can make that happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't make it pass tests! I'm going to open a new ticket to track it.

// to show up in a flame graph.
final long valid;
if (settings.hasValue("ingest.geoip.database_validity")) {
valid = settings.getAsTime("ingest.geoip.database_validity", THIRTY_DAYS).millis();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this slow only when there is no value (b/c we generate an exception or something)? Or is it always slow? If the latter, should we calculate this outside of this method, and have a settings listener listening for updates to the setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added another comment here in the code -- the setting itself is kindof a hack to get around the situation where we want to be able to test this code but we can't make it possible to actually change the value of the setting in 'the real world'.

I'm not at all opposed to continuing to grind on this, but I'd love to do that in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the latter, should we calculate this outside of this method, and have a settings listener listening for updates to the setting?

I took a closer look at the idea of the settings listener, and I think the reason we're not doing any of that right now is specifically because the setting in question isn't a 'real setting' -- AFAICT all the settings update listener type methods require a proper Setting object to hang off of, which we don't have in this case. 😬

Somebody could probably get pretty far by extracting our current code and manually watching for settings changes like this:

+ clusterService.addListener(event -> { + if (event.metadataChanged() && event.state().metadata().settings() != event.previousState().metadata().settings()) { + logger.info("metadata changed and settings changed"); + [... process the settings update here, check if the database validity has changed, etc ...] + } + }); 
@joegallo
Copy link
Contributor Author

joegallo commented Jan 24, 2025

I need to snag a profile, but a6a4135 is a very nice change here. (edit: but I reverted it -- I'd rather we write a better cluster state listener than hack that change in the way I did it in that commit)

@joegallo
Copy link
Contributor Author

I kicked some changes out of this PR, and I'm punting some of what I would still like to see done onto #121208. We can come back to this in the future and do even better.

Copy link
Member

@masseyke masseyke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joegallo joegallo merged commit c4bb9b3 into elastic:main Jan 29, 2025
15 of 16 checks passed
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP >enhancement Team:Data Management Meta label for data/management team v8.18.0 v9.0.0

3 participants