Broken pipe while using Jedis Pool

2,073 views
Skip to first unread message

Allexandre Sampaio

unread,
Mar 10, 2017, 9:31:25 AM3/10/17
to Jedis
I'm using Jedis to perform a lot of insertions/reads in Redis.
The Redis server is using the default configuration.
The problem only appears when I start using a few threads (like 100) and the exception is:

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Pipe quebrado (Write failed)

I've searched a lot about this problem but couldn't find the reason of it or it's solve. The code I'm using to perform these tests is below:

public class RedisFacade {

private static RedisFacade instancia = null;
// Initialize the Connection
final JedisPoolConfig poolConfig = buildPoolConfig();
JedisPool pool = new JedisPool(poolConfig, "localhost");
Jedis jedis;
int i = 0;

private RedisFacade() {
}

public static RedisFacade getInstancia() {
   
if (instancia == null) {
        instancia
= new RedisFacade();
   
}
   
return instancia;
}

// retorna um cliente jedis da pool
public Jedis getDB() {
   
if (jedis == null) {
        jedis
= pool.getResource();
   
}
   
return jedis;
}

//inserting
public void insert(Document d) {
   
String key = i + d.getString("date") + d.getString("time");
   
String value = d.toString();
   
this.getDB().set(key, value);
    i
++;
}

//reading
public void read(String date, String time) {
   
Object doc = this.getDB().get(i + date + time);
    i
++;
   
System.out.println(doc);
}

public void destroyPool() {
   
this.pool.destroy();
}

private JedisPoolConfig buildPoolConfig() {
   
final JedisPoolConfig poolConfig = new JedisPoolConfig();
    poolConfig
.setMaxTotal(1100);
    poolConfig
.setMaxIdle(16);
    poolConfig
.setMinIdle(16);
    poolConfig
.setTestOnBorrow(true);
    poolConfig
.setTestOnReturn(true);
    poolConfig
.setTestWhileIdle(true);poolConfig.setMinEvictableIdleTimeMillis(Duration.ofSeconds(60).toMillis());
    poolConfig
.setTimeBetweenEvictionRunsMillis(Duration.ofSeconds(30).toMillis());
    poolConfig
.setNumTestsPerEvictionRun(3);
    poolConfig
.setBlockWhenExhausted(true);
   
return poolConfig;
}}

If someone could give me some help, I'd be grateful, part of my final project at college is depending on it.
Thanks in advance.

Marcos Lilljedahl

unread,
Mar 11, 2017, 11:22:34 AM3/11/17
to Jedis
Hey Allexandre, 

Seems like you're not returning the Jedis instance to the pool after using it, neither checking for exceptions. 

Try changing your insert method as follows:

//inserting
public void insert(Document d) {
    String key = i + d.getString("date") + d.getString("time");
    String value = d.toString();
    try(Jedis jedis = this.getDB()) {
      jedis.set(key, value);
      i++;
    } catch (Exception e) {
       //Something failed, log, handle, whatever
    }
}

Hope this helps, 

Marcos.

--
You received this message because you are subscribed to the Google Groups "Jedis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jedis_redis+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcos Lilljedahl

unread,
Mar 11, 2017, 11:23:30 AM3/11/17
to Jedis
BTW, you should do the same for the read function as well.

Allan Wax

unread,
Apr 3, 2017, 1:45:15 PM4/3/17
to Jedis
I would also recommend making getInstancia and getDB synchronized if you are in a multi-threaded environment.  There could be issues otherwise.

Allan
To unsubscribe from this group and stop receiving emails from it, send an email to jedis_redis...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages