I'm using Jedis to perform a lot of insertions/reads in Redis. The Redis server is using the default configuration. The problem appears when I start using a few threads 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;
}}
Seems like it's a timeout issue.
See this thread: Configure Jedis timeout
And also this discussion: https://github.com/xetorthio/jedis/issues/185
So I would try instantiating JedisPool
with a timeout parameter
(i.e. https://github.com/xetorthio/jedis/blob/master/src/main/java/redis/clients/jedis/JedisPool.java#L201, but there are many other constructors)
and setting CONFIG SET timeout 600
in redis (with a 10 minute timeout for instance).
The JedisPool
timeout is in milliseconds it seems.