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

Carrier threads pinned on object.wait() for Generativeaiinterferenceclient #629

Open
NarendraBanothu opened this issue Aug 23, 2024 · 1 comment
Labels
SDK Issue pertains to the SDK itself and not specific to any service

Comments

@NarendraBanothu
Copy link

observed thread pinning happening for GenerativeAiInferenceClient for Helidon 4x version for AI calls for OCI sdk.

#2270 "[0x453f951d 0x5e59747f] WebServer socket" virtual
java.base/java.lang.Object.wait0(Native Method)
java.base/java.lang.Object.wait(Object.java:366)
java.base/java.lang.Object.wait(Object.java:339)
com.oracle.bmc.http.internal.SyncFutureWaiter$Waiter.waitAndWork(SyncFutureWaiter.java:61)
com.oracle.bmc.http.internal.SyncFutureWaiter.listenForResult(SyncFutureWaiter.java:32)
com.oracle.bmc.http.internal.ClientCall.callSync(ClientCall.java:1101)
com.oracle.bmc.generativeaiinference.GenerativeAiInferenceClient.chat(GenerativeAiInferenceClient.java:114)

#1582 "[0x453f951d 0x74dfd5cd] WebServer socket" virtual
java.base/java.lang.Object.wait0(Native Method)
java.base/java.lang.Object.wait(Object.java:366)
java.base/java.lang.Object.wait(Object.java:339)
com.oracle.bmc.http.internal.SyncFutureWaiter$Waiter.waitAndWork(SyncFutureWaiter.java:61)
com.oracle.bmc.http.internal.SyncFutureWaiter.listenForResult(SyncFutureWaiter.java:32)
com.oracle.bmc.http.internal.ClientCall.callSync(ClientCall.java:1101)
com.oracle.bmc.generativeaiinference.GenerativeAiInferenceClient.embedText(GenerativeAiInferenceClient.java:143)

@NarendraBanothu
Copy link
Author

The pinning here is due to use of Object.wait()/Object.notifyAll() in below OCI-SDK code

java.base/java.lang.Object.wait(Object.java:339) com.oracle.bmc.http.internal.SyncFutureWaiter$Waiter.waitAndWork(SyncFutureWaiter.java:61)

https://github.com/oracle/oci-java-sdk/blob/master/bmc-common/src/main/java/com/oracle/bmc/http/internal/SyncFutureWaiter.java

public R waitAndWork() throws InterruptedException, Throwable {
synchronized (SyncFutureWaiter.this) {
while (!complete) {
Runnable task = tasks.poll();
if (task == null) {
SyncFutureWaiter.this.wait();
} else {
task.run();
}
}
....
.....
}
}

The use of Sync block and Object.wait ( SyncFutureWaiter.this.wait() ) here causes the carrier thread to be pinned in this code when running with Virtual threads with Java-21.

These code need to be replaced with a combination of ReentrantLock and Condition.await()/Condition.signalAll() , which are loom friendly and doesn't cause the carrier thread to be pinned.

@mricken mricken added the SDK Issue pertains to the SDK itself and not specific to any service label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK Issue pertains to the SDK itself and not specific to any service
Projects
None yet
Development

No branches or pull requests

2 participants