Discussion:
[redis-db] jedis - Could not get a resource from the pool
박종현
2016-11-15 02:05:03 UTC
Permalink
Hi, I'm using Jedis from a multi threaded environment and I'm getting this
error code

Exception in thread "main"
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a
resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException:
java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 10 more



Here is my Jedis test code.


import java.util.ArrayList;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class HelloRedis implements Runnable{
int seq;
Jedis jedis;

static JedisPool pool;
static JedisPoolConfig config;
String str = "@";
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);

long startTime = System.currentTimeMillis();

ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}

@Override
public void run() {

for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);

}

jedis.close();
}
}



I set the number of maxclients is 10,000,000 in redis.conf file.

I wonder why this code occur error although I set that Jedis pool size is
bigger than the number of threads.

I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
CharSyam
2016-11-15 08:04:36 UTC
Permalink
Did you run redis server?
Post by 박종현
Hi, I'm using Jedis from a multi threaded environment and I'm getting this
error code
Exception in thread "main"
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a
resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool size is
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
박종현
2016-11-15 08:24:24 UTC
Permalink
Yes. I run redis server in windows
Post by CharSyam
Did you run redis server?
Post by 박종현
Hi, I'm using Jedis from a multi threaded environment and I'm getting
this
Post by 박종현
error code
Exception in thread "main"
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a
resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
Post by 박종현
at redis.clients.util.Pool.getResource(Pool.java:49)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool size
is
Post by 박종현
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google
Groups
Post by 박종현
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send
an
<javascript:>.
Post by 박종현
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
CharSyam
2016-11-15 09:05:38 UTC
Permalink
Please check like below.
1] just try to connect your redis server, is it OK?

2] set below and test again.
1. set maxclient just as 1024 for test
2. set config.setMaxTotal(100);
3. set config.setMaxIdle(100);
Post by 박종현
Yes. I run redis server in windows
Post by CharSyam
Did you run redis server?
Post by 박종현
Hi, I'm using Jedis from a multi threaded environment and I'm getting this
error code
Exception in thread "main"
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a
resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool size is
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google
Groups
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
박종현
2016-11-15 09:28:31 UTC
Permalink
Thank you! It runs well when I set 2].

By the way, why did this code occur when maxclient, setMaxTotal and
setMaxIdle are high values?
Post by CharSyam
Please check like below.
1] just try to connect your redis server, is it OK?
2] set below and test again.
1. set maxclient just as 1024 for test
2. set config.setMaxTotal(100);
3. set config.setMaxIdle(100);
Post by 박종현
Yes. I run redis server in windows
Post by CharSyam
Did you run redis server?
Post by 박종현
Hi, I'm using Jedis from a multi threaded environment and I'm getting this
error code
Exception in thread "main"
redis.clients.jedis.exceptions.JedisConnectionException: Could not
get a
Post by 박종현
Post by CharSyam
Post by 박종현
resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
Post by 박종현
Post by CharSyam
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
Post by 박종현
Post by CharSyam
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
Post by 박종현
Post by CharSyam
Post by 박종현
at redis.clients.util.Pool.getResource(Pool.java:49)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool
size
Post by 박종현
Post by CharSyam
Post by 박종현
is
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google
Groups
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it,
send
Post by 박종현
Post by CharSyam
Post by 박종현
an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
Post by 박종현
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send
an
<javascript:>.
Post by 박종현
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
박종현
2016-11-15 09:28:59 UTC
Permalink
Post by 박종현
Thank you! It runs well when I set 2].
By the way, why did this code occur the error when maxclient, setMaxTotal
and setMaxIdle are high values?
Post by CharSyam
Please check like below.
1] just try to connect your redis server, is it OK?
2] set below and test again.
1. set maxclient just as 1024 for test
2. set config.setMaxTotal(100);
3. set config.setMaxIdle(100);
Post by 박종현
Yes. I run redis server in windows
Post by CharSyam
Did you run redis server?
Post by 박종현
Hi, I'm using Jedis from a multi threaded environment and I'm
getting
Post by 박종현
Post by CharSyam
Post by 박종현
this
error code
Exception in thread "main"
redis.clients.jedis.exceptions.JedisConnectionException: Could not
get a
Post by 박종현
Post by CharSyam
Post by 박종현
resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at
redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
Post by 박종현
Post by CharSyam
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
Post by 박종현
Post by CharSyam
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
Post by 박종현
Post by CharSyam
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
Post by 박종현
Post by CharSyam
Post by 박종현
at redis.clients.util.Pool.getResource(Pool.java:49)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool
size
Post by 박종현
Post by CharSyam
Post by 박종현
is
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google
Groups
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it,
send
Post by 박종현
Post by CharSyam
Post by 박종현
an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
Post by 박종현
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by 박종현
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
박종현
2016-11-15 09:29:52 UTC
Permalink
Thank you! It runs well when I set 2].

By the way, why did this code occur the error when maxclient, setMaxTotal
and setMaxIdle are high values?
Post by CharSyam
Please check like below.
1] just try to connect your redis server, is it OK?
2] set below and test again.
1. set maxclient just as 1024 for test
2. set config.setMaxTotal(100);
3. set config.setMaxIdle(100);
Post by 박종현
Yes. I run redis server in windows
Post by CharSyam
Did you run redis server?
Post by 박종현
Hi, I'm using Jedis from a multi threaded environment and I'm getting this
error code
Exception in thread "main"
redis.clients.jedis.exceptions.JedisConnectionException: Could not
get a
Post by 박종현
Post by CharSyam
Post by 박종현
resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
Post by 박종현
Post by CharSyam
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
Post by 박종현
Post by CharSyam
Post by 박종현
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
Post by 박종현
Post by CharSyam
Post by 박종현
at redis.clients.util.Pool.getResource(Pool.java:49)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool
size
Post by 박종현
Post by CharSyam
Post by 박종현
is
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google
Groups
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it,
send
Post by 박종현
Post by CharSyam
Post by 박종현
an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
Post by 박종현
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send
an
<javascript:>.
Post by 박종현
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
CharSyam
2016-11-15 09:48:41 UTC
Permalink
It depens on operating systems. :)
Because of Open File Descriptor or just over spending of socket(you
can just use maximum 65535 clients)
Post by 박종현
Thank you! It runs well when I set 2].
By the way, why did this code occur the error when maxclient, setMaxTotal
and setMaxIdle are high values?
Post by CharSyam
Please check like below.
1] just try to connect your redis server, is it OK?
2] set below and test again.
1. set maxclient just as 1024 for test
2. set config.setMaxTotal(100);
3. set config.setMaxIdle(100);
Post by 박종현
Yes. I run redis server in windows
Post by CharSyam
Did you run redis server?
Post by 박종현
Hi, I'm using Jedis from a multi threaded environment and I'm getting this
error code
Exception in thread "main"
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a
resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool size
is
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google
Groups
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
"Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Loading...