jedis
jedis copied to clipboard
Make buffer size of RedisOutputStream/RedisInputStream configurable
The buffer size of RedisOutput/InputStream is fixed as 8192, 8KB. It is no problem if there is not much connection.
In our case, we maintain many connections concurrently and handle under 1KB. So 8KB is too big for us, and became burden of OldGen.
RedisOutputStream
/RedisInputStream
already has configurable constructor but in Connection#connect
there is no chance to use it.
- Connection#connect
public void connect() {
if (!isConnected()) {
try {
socket = new Socket();
// ->@wjw_add
socket.setReuseAddress(true);
socket.setKeepAlive(true); // Will monitor the TCP connection is
// valid
socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to
// ensure timely delivery of data
socket.setSoLinger(true, 0); // Control calls close () method,
// the underlying socket is closed
// immediately
// <-@wjw_add
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
socket.setSoTimeout(soTimeout);
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
broken = true;
throw new JedisConnectionException(ex);
}
}
}
@itugs makes sense. I'm thinking of the proper way of setting buffer size without adding a new constructor to all Jedis
instances (Pool / Cluster / Sharded / etc) but I can't come up with a solution.
Any sugestions?
@itugs another question: Would it make sense to modify this value on runtime?. Maybe we can do something like. jedis.getClient().setIOBuffer()
.
I'd guess that modifying that value in runtime might probably cause errors, right?
@marcosnils Runtim modification will work if it is properly handled. ie, isolate modification with communication. But IMO construction time configuration is preferred for simplicity and clarity.
I'm also checked but it is not easy if we do not add new constructors at classes.
IMO ideally it's is good to introduce configuration object like ConnectionConfig
.
This issue is marked stale. It will be closed in 30 days if it is not updated.