Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2145

UndertowOutputStream and ServletOutputStreamImpl awaitWritable unnecessarily

    XMLWordPrintable

Details

    Description

      After a channel.write(buffer), the implementation checks only buffer.hasRemaining, not the result of channel.write. We should write until a write returns zero. In synthetic benchmarks this seems to result in a significant performance improvement.

      UndertowOutputStream:
      https://github.com/undertow-io/undertow/blob/a3aebce60e57f83b02aa847c50d6e372b9a9b9b5/core/src/main/java/io/undertow/io/UndertowOutputStream.java#L294-L301

              while (buffer.hasRemaining()) {
                  if(writeFinal) {
                      channel.writeFinal(buffer);
                  } else {
                      channel.write(buffer);
                  }
                  if(buffer.hasRemaining()) {
                      channel.awaitWritable();
                  }
              }

      ServletOutputStreamImpl:
      https://github.com/undertow-io/undertow/blob/fde1ca6ffc8c6248a62179e98c59eb09202545c5/servlet/src/main/java/io/undertow/servlet/spec/ServletOutputStreamImpl.java#L581-L589

              while (buffer.hasRemaining()) {
                  if (writeFinal) {
                      channel.writeFinal(buffer);
                  } else {
                      channel.write(buffer);
                  }
                  if (buffer.hasRemaining()) {
                      channel.awaitWritable();
                  }
              }

       

      Attachments

        Issue Links

          Activity

            People

              flaviarnn Flavia Rainone
              carterkozak Carter Kozak
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: