question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use lettuce in the right way

See original GitHub issue

Bug Report

When the server is under a lot of pressure, call lettucePool.acquire().get(1, TimeUnit.SECONDS) and the program has the following exception.

Exception

java.util.NoSuchElementException: Pool exhausted
...
Other exception stack information

Java code

// config  RedisClusterClient
ClientResources clientResources = DefaultClientResources.builder()
                                     .ioThreadPoolSize(3 * Runtime.getRuntime().availableProcessors())
                                     .computationThreadPoolSize(4)
                                     .reconnectDelay(Delay.constant(Duration.ofSeconds(1)))
                                     .build();

RedisClusterClient clusterClient = RedisClusterClient.create(clientResources, redisURIS);
ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions
                                                         .builder()
                                                         .enableAdaptiveRefreshTrigger(ClusterTopologyRefreshOptions.RefreshTrigger.MOVED_REDIRECT,ClusterTopologyRefreshOptions.RefreshTrigger.PERSISTENT_RECONNECTS)
                                                         .adaptiveRefreshTriggersTimeout(Duration.ofMinutes(3))
                                                         .build();
clusterClient.setOptions(ClusterClientOptions.builder()
                                                         .topologyRefreshOptions(topologyRefreshOptions)
                                                         .autoReconnect(true)
                                                         .pingBeforeActivateConnection(true)
                                                         .build());

// config lettucePool
// maxIdle = 8
// minIdle = 1
// maxActive = 8
// testOnCreate = true
final BoundedPoolConfig boundedPoolConfig = BoundedPoolConfig
                .builder()
                .minIdle(minIdle)
                .maxIdle(maxIdle)
                .maxTotal(maxActive)
                .testOnCreate(testOnCreate)
                .testOnAcquire(true).build();
final BoundedAsyncPool<StatefulRedisClusterConnection<String, String>> lettucePool =
                AsyncConnectionPoolSupport.createBoundedObjectPool(() -> clusterClient.connectAsync(StringCodec.UTF8), boundedPoolConfig);
===============================================================


// way of use
@Autowired
BoundedAsyncPool<StatefulRedisClusterConnection<String, String>> lettucePool;
// way of use
final StatefulRedisClusterConnection<String, String> connection = lettucePool.acquire().get(1, TimeUnit.SECONDS);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mp911decommented, Oct 16, 2018

Lettuce connection are designed to be long-lived and they are thread-safe. If you use Redis Cluster with simple GET and SET commands, then you don’t need pooling at all. The only thing to do is injecting StatefulRedisClusterConnection into your code and simply using it.

0reactions
10119255commented, Oct 17, 2018

Lettuce connection are designed to be long-lived and they are thread-safe. If you use Redis Cluster with simple GET and SET commands, then you don’t need pooling at all. The only thing to do is injecting StatefulRedisClusterConnection into your code and simply using it.

Thank you very much for your reply. I will try your suggestion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Up Lettuce & Other Greens Before They Go Bad ...
This is one of my favorite ways to use up lettuce before it goes bad. Cut into wedges or thick slices, dressed with...
Read more >
The Very Best Way to Use Up Lots of Lettuce - Roots & Boots
Harvest lettuce. · Wash thoroughly. · You can dry the lettuce, but it's not necessary. · Stuff it into a high powered blender....
Read more >
38 Lettuce Recipes That Go Beyond Salad | Bon Appétit
Lettuce Show You How Versatile Tender Greens Can Be With These 38 Recipes · Classic Caesar Salad · Little Gem Salad with Lemon...
Read more >
How to Use Your Garden Lettuces - 4 Ideas to use ... - YouTube
Is it that time of year when you are wondering how to use your garden lettuces for something other than salads?
Read more >
How to Harvest Lettuce so it Keeps on Growing ... - YouTube
Growing your own fresh, tasty salads for several months is easy when you know how to harvest lettuce so it keeps on growing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found