jedis icon indicating copy to clipboard operation
jedis copied to clipboard

Make buffer size of RedisOutputStream/RedisInputStream configurable

Open itugs opened this issue 9 years ago • 4 comments

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 avatar May 29 '15 05:05 itugs

@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?

marcosnils avatar May 29 '15 06:05 marcosnils

@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 avatar May 29 '15 06:05 marcosnils

@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.

itugs avatar May 29 '15 07:05 itugs

This issue is marked stale. It will be closed in 30 days if it is not updated.

github-actions[bot] avatar Feb 15 '24 00:02 github-actions[bot]