You're right, I think we should be able to minimize the number of
window adjustements to decrease traffic.

On Thu, Dec 15, 2011 at 16:35, Simon Paradis <spara...@pgsolutions.com> wrote:
> Hi,
>
> I'm using SSHD 0.6.0 on Oracle JVM 1.6.0_23-b05 on Windows 7 x64. I have a 
> custom server channel subclassing AbstractServerChannel. I'm wondering if my 
> handling of SSH window adjustment message is correct. I'm sending a window 
> adjustment everytime the window size decreases by half. Apparenly, some 
> OpenSSH implementation works this way. This code is talking to another C++ 
> process built with libssh2 1.3.0.
>
> protected void doWriteData(byte[] p_Data, int p_Offset, int p_Length)
>  throws IOException
> {
>  // The localWindow.consumeAndCheck() send too much window adjustments.
>  localWindow.consume(p_Length);
>  int size = localWindow.getSize();
>  int maxSize = localWindow.getMaxSize();
>  if (size < maxSize/2) {
>    localWindow.expand(maxSize - size);
>    sendWindowAdjust(maxSize - size);
>  }
>
>  // Do stuff ...
> }
>
> Before that, I was calling localWindow.consumeAndCheck(p_Length) but I found 
> out it sends quite a lot of these adjustment down the wire. In Window.java, 
> we have this
>
> public void consumeAndCheck(int len) throws IOException {
>  synchronized (lock) {
>    size -= len;
>    if (log.isTraceEnabled()) {
>      log.trace("Consume " + name + " by " + len + " down to " + size);
>    }
>    check(maxSize);
>  }
> }
>
> public void check(int maxFree) throws IOException {
>  synchronized (lock) {
>    if ((size < maxFree) && (maxFree - size > packetSize * 3 || size < maxFree 
> / 2)) {
>      if (log.isDebugEnabled()) {
>        log.debug("Increase " + name + " by " + (maxFree - size) + " up to " + 
> maxFree);
>      }
>      channel.sendWindowAdjust(maxFree - size);
>      size = maxFree;
>    }
>  }
> }
>
> This is sending a window adjustment every 3 * packetSize, so every 96kb in my 
> case since the packet size is 32kb. Is there a practical reason for doing 
> this instead of sending it every half of the maximum size ?
>
> Thanks,
>
> Simon Paradis



-- 
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Reply via email to