Skip to content
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

Reduce initial's Arc ManagedContext activation cost #34310

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

franz1981
Copy link
Contributor

@franz1981 franz1981 commented Jun 26, 2023

This is a companion of #34132

On main:

  • ManagedContext's initial activation requires to retrieve the request context state value (ie RequestContextState instance freshly created) from the Vertx local context which is already known upfront ( 'cause is the first time we set it, so we know already): this pr is saving this lookup
  • CurrentVertxRequest's already provide a batch set method (thanks @stuartwdouglas for it!!!) we can use to avoid proxies to perform twice a delegate lookup (which involve io/quarkus/arc/impl/RequestContext.getIfActive to happen twice)

@quarkus-bot quarkus-bot bot added area/arc Issue related to ARC (dependency injection) area/rest labels Jun 26, 2023
@franz1981
Copy link
Contributor Author

Waiting #34132 to be merged (if merged) before moving with this

@franz1981 franz1981 changed the title Reduce initial's Arc ManagedContext initial activation cost Reduce initial's Arc ManagedContext activation cost Jun 26, 2023
@franz1981 franz1981 marked this pull request as ready for review June 28, 2023 09:16
@franz1981
Copy link
Contributor Author

@mkouba still waiting #34310 to be merged, but we can do the opposite, when everyone is happy with this; I'll rebase the other one, in case

@gsmet gsmet marked this pull request as draft June 28, 2023 09:35
@gsmet
Copy link
Member

gsmet commented Jun 28, 2023

Marking as draft for now as this is still being discussed and CI is overloaded.

*/
default void activate() {
Copy link
Contributor

Choose a reason for hiding this comment

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

For the record, this change is binary incompatible. However, the ManagedContext interface is not intended to be implemented outside the ArC core. Therefore, there's a low risk of breaking existing code. If we run into a problem though we should consider adding synthetic bridge methods via https://github.com/dmlloyd/bridger.

@franz1981 franz1981 force-pushed the ctx branch 2 times, most recently from a1a1744 to 965f906 Compare June 30, 2023 13:55
@geoand geoand requested review from Ladicek and mkouba June 30, 2023 13:57
@geoand geoand marked this pull request as ready for review June 30, 2023 13:59
@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jun 30, 2023
@quarkus-bot

This comment has been minimized.

@franz1981
Copy link
Contributor Author

@mkouba ManagedExecutorTest TCK failures are from the latest commits which includes your changes?

@mkouba
Copy link
Contributor

mkouba commented Jul 3, 2023

@mkouba ManagedExecutorTest TCK failures are from the latest commits which includes your changes?

Well, it's the assert currentContext.get() == null that triggers an assertion error:

Caused by: java.lang.AssertionError
	at io.quarkus.arc.impl.RequestContext.activate(RequestContext.java:138)
	at io.quarkus.arc.runtime.context.ArcContextProvider$ContextSnapshot.begin(ArcContextProvider.java:145)
	at io.smallrye.context.impl.SlowActiveContextState.<init>(SlowActiveContextState.java:29)
	at io.smallrye.context.impl.SlowCapturedContextState.begin(SlowCapturedContextState.java:34)
	at io.smallrye.context.impl.SlowCapturedContextState.begin(SlowCapturedContextState.java:13)
	at io.smallrye.context.impl.wrappers.SlowContextualSupplier.get(SlowContextualSupplier.java:20)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromItemSupplier.subscribe(UniCreateFromItemSupplier.java:28)

It seems that the captured ContextState is not valid anymore but the current context is set. I have no idea if this is legal from MP CP POV. But it probably is because the code in io.quarkus.arc.runtime.context.ArcContextProvider.ContextSnapshot.begin() simply tests the validity of the context and passes null if it's not, thus effectively overrides the current context.

@manovotn @FroMage WDYT?

@franz1981
Copy link
Contributor Author

@mkouba I've run locally the tests and I can confirm it indeed

<<< END Method.completedFutureDependentStagesRunWithContext FAILED
java.util.concurrent.ExecutionException: java.lang.AssertionError
        at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
        at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)
        at io.smallrye.context.CompletableFutureWrapper.get(CompletableFutureWrapper.java:159)
        at org.eclipse.microprofile.context.tck.ManagedExecutorTest.completedFutureDependentStagesRunWithContext(ManagedExecutorTest.java:266)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at io.quarkus.arquillian.QuarkusProtocol$QuarkusMethodExecutor$1.invoke(QuarkusProtocol.java:87)
        at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:57)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)
        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:90)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:133)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:105)
        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:62)
        at io.quarkus.arquillian.QuarkusProtocol$QuarkusMethodExecutor.invoke(QuarkusProtocol.java:67)
        at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:103)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)
        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:90)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:133)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:105)
        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:62)
        at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:52)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)
        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:90)
        at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:128)
        at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:118)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:95)
        at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:116)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:95)
        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:83)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:95)
        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:69)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:95)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:133)
        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:139)
        at org.jboss.arquillian.testng.Arquillian.run(Arquillian.java:138)
        at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:253)
        at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:594)
        at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
        at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
        at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
        at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at org.testng.TestRunner.privateRun(TestRunner.java:794)
        at org.testng.TestRunner.run(TestRunner.java:596)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
        at org.testng.SuiteRunner.run(SuiteRunner.java:276)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
        at org.testng.TestNG.runSuites(TestNG.java:1063)
        at org.testng.TestNG.run(TestNG.java:1031)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:155)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:102)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:91)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:137)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
Caused by: java.lang.AssertionError
        at io.quarkus.arc.impl.RequestContext.activate(RequestContext.java:132)
        at io.quarkus.arc.ManagedContext.activate(ManagedContext.java:17)
        at io.quarkus.arc.runtime.context.ArcContextProvider$ClearContextSnapshot.begin(ArcContextProvider.java:81)
        at io.smallrye.context.impl.SlowActiveContextState.<init>(SlowActiveContextState.java:29)
        at io.smallrye.context.impl.SlowCapturedContextState.begin(SlowCapturedContextState.java:34)
        at io.smallrye.context.impl.SlowCapturedContextState.begin(SlowCapturedContextState.java:13)
        at io.smallrye.context.impl.wrappers.SlowContextualBiFunction.apply(SlowContextualBiFunction.java:20)
        at java.base/java.util.concurrent.CompletableFuture.biApply(CompletableFuture.java:1311)
        at java.base/java.util.concurrent.CompletableFuture$BiApply.tryFire(CompletableFuture.java:1280)
        at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
        at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2179)
        at org.eclipse.microprofile.context.tck.ManagedExecutorTest.completedFutureDependentStagesRunWithContext(ManagedExecutorTest.java:264)
        ... 81 more

@FroMage
Copy link
Member

FroMage commented Jul 4, 2023

I really don't know how this class works, it's mostly @manovotn who understands it :)

@franz1981
Copy link
Contributor Author

@mkouba if we don't need to keep the assertion I can remove it, in case, and instead, open an issue where we need to understand better the life-cycle of it

@mkouba
Copy link
Contributor

mkouba commented Jul 7, 2023

@mkouba if we don't need to keep the assertion I can remove it, in case, and instead, open an issue where we need to understand better the life-cycle of it

Yep, that sounds reasonable. Let's comment out that assertion for now and file a new tracking issue.

@franz1981
Copy link
Contributor Author

@mkouba assertion removed!
wdyt, are we ready to go?

@franz1981
Copy link
Contributor Author

@mkouba assertion removed, do I need to squash the changes?

@quarkus-bot

This comment has been minimized.

@mkouba
Copy link
Contributor

mkouba commented Jul 12, 2023

@mkouba assertion removed, do I need to squash the changes?

Yes please ;-)

@quarkus-bot quarkus-bot bot added area/dependencies Pull requests that update a dependency file area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/mongodb area/platform Issues related to definition and interaction with Quarkus Platform area/testing labels Jul 12, 2023
@franz1981
Copy link
Contributor Author

@mkouba squashing done! (Sorry I've lost you as co-author :/ )

@mkouba
Copy link
Contributor

mkouba commented Jul 13, 2023

@mkouba squashing done! (Sorry I've lost you as co-author :/ )

No problem. I think that the only thing you need to do is to add something like Co-authored-by: NAME <[email protected]> in the comment.

@geoand
Copy link
Contributor

geoand commented Jul 13, 2023

I think that the only thing you need to do is to add something like Co-authored-by: NAME [email protected] in the comment.

That is correct - it's simply a matter of editing the commit message and adding this

@franz1981
Copy link
Contributor Author

@mkouba @geoand done!

@quarkus-bot
Copy link

quarkus-bot bot commented Jul 14, 2023

Failing Jobs - Building ccabce0

Status Name Step Failures Logs Raw logs
✔️ JVM Tests - JDK 11
JVM Tests - JDK 17 Build ⚠️ Check → Logs Raw logs
✔️ JVM Tests - JDK 19

@geoand geoand merged commit 0b0eff7 into quarkusio:main Jul 19, 2023
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jul 19, 2023
@quarkus-bot quarkus-bot bot added this to the 3.3 - main milestone Jul 19, 2023
mkouba added a commit to mkouba/quarkus that referenced this pull request Aug 29, 2023
mkouba added a commit to mkouba/quarkus that referenced this pull request Aug 29, 2023
gsmet pushed a commit to gsmet/quarkus that referenced this pull request Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/dependencies Pull requests that update a dependency file area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/mongodb area/platform Issues related to definition and interaction with Quarkus Platform area/rest area/testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants