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

Pool exhausted, Java 21 and Virtual Threads #2867

Open
jkvargas opened this issue May 29, 2024 · 4 comments
Open

Pool exhausted, Java 21 and Virtual Threads #2867

jkvargas opened this issue May 29, 2024 · 4 comments
Labels
for: stackoverflow A question that is better suited to stackoverflow.com status: waiting-for-feedback We need additional information before we can continue

Comments

@jkvargas
Copy link

jkvargas commented May 29, 2024

Hi, I am getting Pool exhausted when I pass a ClientResources which does use an executor with virtual threads.

java.util.concurrent.CompletionException: java.util.NoSuchElementException: Pool exhausted
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source) ~[?:?]
	at java.base/java.util.concurrent.CompletableFuture.uniApplyNow(Unknown Source) ~[?:?]
	at java.base/java.util.concurrent.CompletableFuture.uniApplyStage(Unknown Source) ~[?:?]
	at java.base/java.util.concurrent.CompletableFuture.thenApply(Unknown Source) ~[?:?]
	at io.lettuce.core.support.AsyncConnectionPoolSupport$1.acquire(AsyncConnectionPoolSupport.java:189) ~[lettuce-core-6.3.2.RELEASE.jar:6.3.2.RELEASE/8941aea]

This is my java code,

var executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().factory());
EventLoopGroup customEventLoopGroup = new NioEventLoopGroup(0, executor);
var clientResources =
        ClientResources.builder().eventExecutorGroup(customEventLoopGroup).build();
RedisClient.create(clientResources, ...);

how can I fix this?
I am using lettuce-core-6.3.2.RELEASE.jar running on a linux container.
Thanks!

@arulned
Copy link

arulned commented May 31, 2024

I am also interested in this. I could not find a clear documentation on how to use virtual threads in lettuce. Appreciate a good reference.

@prathyand
Copy link

Hi, I am getting Pool exhausted when I pass a ClientResources which does use an executor with virtual threads.

java.util.concurrent.CompletionException: java.util.NoSuchElementException: Pool exhausted
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source) ~[?:?]
	at java.base/java.util.concurrent.CompletableFuture.uniApplyNow(Unknown Source) ~[?:?]
	at java.base/java.util.concurrent.CompletableFuture.uniApplyStage(Unknown Source) ~[?:?]
	at java.base/java.util.concurrent.CompletableFuture.thenApply(Unknown Source) ~[?:?]
	at io.lettuce.core.support.AsyncConnectionPoolSupport$1.acquire(AsyncConnectionPoolSupport.java:189) ~[lettuce-core-6.3.2.RELEASE.jar:6.3.2.RELEASE/8941aea]

This is my java code,

var executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().factory());
EventLoopGroup customEventLoopGroup = new NioEventLoopGroup(0, executor);
var clientResources =
        ClientResources.builder().eventExecutorGroup(customEventLoopGroup).build();
RedisClient.create(clientResources, ...);

how can I fix this?
I am using lettuce-core-6.3.2.RELEASE.jar running on a linux container.
Thanks!

Hey I'm not quite sure if I know the solution, but you might want to look into
newVirtualThreadPerTaskExecutor()

@tishun tishun added the for: stackoverflow A question that is better suited to stackoverflow.com label Jun 27, 2024
@tishun
Copy link
Collaborator

tishun commented Jun 28, 2024

Hey @jkvargas ,

        Executor executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().factory());
        EventLoopGroup customEventLoopGroup = new NioEventLoopGroup(0, executor);
        var clientResources =
                ClientResources.builder().eventExecutorGroup(customEventLoopGroup).build();

        try (RedisClient clusterClient = RedisClient.create(clientResources, redisURI)) {
            StatefulRedisConnection<String, String> connection = clusterClient.connect();
            connection.sync().set("key", "value");
        }

I tried your code and it worked for me, could this be some environment issue with your JVM / JDK?

Hey I'm not quite sure if I know the solution, but you might want to look into newVirtualThreadPerTaskExecutor()

Both newVirtualThreadPerTaskExecutor() and newThreadPerTaskExecutor() should do the job, see this blog post.

@tishun tishun added the status: waiting-for-feedback We need additional information before we can continue label Jun 28, 2024
@yszzu1
Copy link

yszzu1 commented Aug 20, 2024

redisTemplate.getRequiredConnectionFactory().getConnection();

org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.SharedConnection#getConnection, getNativeConnection() is stucked, there is synchronized , after upgrade to springboot 3.3.2 which is using lock, it's still stucked.

ref: spring-projects/spring-data-redis#2690

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that is better suited to stackoverflow.com status: waiting-for-feedback We need additional information before we can continue
Projects
None yet
Development

No branches or pull requests

5 participants