Skip to content

Conversation

joegallo
Copy link
Contributor

@joegallo joegallo commented Aug 15, 2025

I ran into this while benchmarking some search code that uses a licensed feature. There was enough lock contention on updating the last used time for that feature that it showed up in a lock flamegraph, so I added this logic to update the last used time less often. I'm not attached to ten seconds, I think we would probably see an improvement if we even just limit it to once a second. 🤷 (edit: I changed the logic.)

For most features, I don't think this would make a difference, but I know for example that the redact processor is running a check on every document, so I could see how the existing logic could cause a problem.

It's not useful to have multiple threads banging away on the map just to put the same value in repeatedly, so now the logic is that the last used time is only updated if it has increased (or if it isn't present at all, as it would be on a fresh start).

@joegallo joegallo requested a review from a team August 15, 2025 18:52
@joegallo joegallo added >enhancement :Security/License License functionality for commercial features Team:Security Meta label for security team v9.2.0 labels Aug 15, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@elasticsearchmachine
Copy link
Collaborator

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

@joegallo
Copy link
Contributor Author

joegallo commented Aug 15, 2025

This test failure is real:

./gradlew ":x-pack:plugin:security:qa:multi-cluster:bcUpgradeTest" -Dtests.class="org.elasticsearch.xpack.remotecluster.RemoteClusterSecurityEsqlIT" -Dtests.bwc.main.version=9.2.0-SNAPSHOT -Dtests.bwc.refspec.main=62c84a486bd9710cc2f8a18441a30af77a121f5b

If we end up doing something like what this PR is proposing, then we'd need to address this test assertion:

if (ccsLastUsedTimestampAtStartOfTest != null) {
assertThat(lastUsed.toString(), not(equalTo(ccsLastUsedTimestampAtStartOfTest.toString())));
}

@mark-vieira
Copy link
Contributor

I think we would probably see an improvement if we even just limit it to once a second. 🤷

Perhaps it's worth doing the same benchmarks with different intervals to see where we get diminishing returns. I agree that 10 seconds is probably too coarse.

If we end up doing something like what this PR is proposing, then we'd need to address this test assertion:

That assertion doesn't seem to provide much value from what I can tell. I suspect we can relax it or remove it entirely.

@joegallo
Copy link
Contributor Author

Heh, it's possible the value might even just be if the logic is "don't bash the same value in repeatedly!" (i.e. if the minimum millis diff is just 1). Anyway, I'll run my benchmark a few times and see what I find.

@joegallo
Copy link
Contributor Author

Heh, it's possible the value might even just be if the logic is "don't bash the same value in repeatedly!" (i.e. if the minimum millis diff is just 1). Anyway, I'll run my benchmark a few times and see what I find.

Heh, yeah, at least for the feature I'm benchmarking, if we change it to only updating the usage timestamp if the timestamp has increased, then the lock contention falls out completely. See bfdeb0c.

Copy link
Contributor

@szybia szybia left a comment

Choose a reason for hiding this comment

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

can't find any fault with this approach

@joegallo joegallo changed the title Limit the frequency of licensed feature last-used time updates Limit the frequency of feature last-used time updates Aug 18, 2025
@joegallo joegallo changed the title Limit the frequency of feature last-used time updates Limit frequency of feature last-used time updates Aug 18, 2025
@joegallo joegallo requested review from mark-vieira and szybia August 18, 2025 15:05
@joegallo joegallo requested review from ankit--sethi and removed request for mark-vieira August 18, 2025 16:29
@elasticsearchmachine
Copy link
Collaborator

Hi @joegallo, I've updated the changelog YAML for you.

@joegallo joegallo added v9.1.3 v8.19.3 auto-backport Automatically create backport pull requests when merged and removed v9.1.1 labels Aug 19, 2025
@joegallo joegallo merged commit f248fd1 into elastic:main Aug 19, 2025
40 checks passed
@joegallo joegallo deleted the update-feature-usage-less-frequently branch August 19, 2025 20:55
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
9.0
9.1
8.19

@joegallo
Copy link
Contributor Author

It turns out that this was related to #111473.

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 >bug :Security/License License functionality for commercial features Team:Security Meta label for security team v8.19.3 v9.0.6 v9.1.3 v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants