Harmony
  1. Harmony
  2. HARMONY-6328

[classlib][nio] optimize SocketChannel.write(ByteBuffer[], int, int) by writev

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 5.0M11
    • Fix Version/s: 5.0M12
    • Component/s: Classlib
    • Labels:
      None

      Description

      SocketChannel.write(ByteBuffer[], int, int) can be optimized by using writev, which can write an array of buffer to socket without any stage buffer. If all passed in ByteBuffer is direct buffer, they can be passed to system call directly without any copies.

      1. test.diff
        3 kB
        Regis Xu
      2. HARMONY-6328.v3.diff
        13 kB
        Regis Xu
      3. HARMONY-6328.v2.diff
        10 kB
        Regis Xu
      4. HARMONY-6328.final.diff
        16 kB
        Regis Xu
      5. HARMONY-6328.diff
        8 kB
        Regis Xu

        Issue Links

          Activity

          Regis Xu made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Regis Xu made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 5.0M12 [ 12314191 ]
          Resolution Fixed [ 1 ]
          Hide
          Regis Xu added a comment -

          patch applied at r816508.

          Show
          Regis Xu added a comment - patch applied at r816508.
          Regis Xu made changes -
          Assignee Regis Xu [ regis_xu ]
          Hide
          Regis Xu added a comment -

          Final patch for this issue, combines all above patches and improvements discussed on dev list.

          Show
          Regis Xu added a comment - Final patch for this issue, combines all above patches and improvements discussed on dev list.
          Regis Xu made changes -
          Attachment HARMONY-6328.final.diff [ 12419983 ]
          Regis Xu made changes -
          Attachment test.diff [ 12418790 ]
          Hide
          Regis Xu added a comment -

          test case and document based on HARMONY-6328.v3.diff

          Show
          Regis Xu added a comment - test case and document based on HARMONY-6328 .v3.diff
          Regis Xu made changes -
          Attachment HARMONY-6328.v3.diff [ 12418786 ]
          Hide
          Regis Xu added a comment -

          HARMONY-6328.v3.diff try to utilize "pin feature" (if vm support)

          Show
          Regis Xu added a comment - HARMONY-6328 .v3.diff try to utilize "pin feature" (if vm support)
          Tim Ellison made changes -
          Link This issue is part of HARMONY-5488 [ HARMONY-5488 ]
          Hide
          Tim Ellison added a comment -

          Good to see this enhancement!

          A minor comment first Please check return values for :

          + vect = (struct iovec*) hymem_allocate_memory(sizeof(struct iovec) * length);
          +
          + message = (*env)->GetPrimitiveArrayCritical(env, addrs, &isCopyMessage);
          + cts = (*env)->GetPrimitiveArrayCritical(env, counts, &isCopyCts);

          A further enhancement is to have two versions of primitives, one that deals with direct buffers and one that deals with java heap buffers, so that there is (potentially) no data copying required for the java-heap buffers version that you have got today:

          + if (!buffer.isDirect()) {
          + src[i] = ByteBuffer.allocateDirect(buffer.remaining());
          + int oldPosition = buffer.position();
          + src[i].put(buffer);

          some VMs will pin the java heap memory accessed in JNI (GetByteArrayElements), so if you can get hold of the ByteBuffer#array() you can pass a set of pointers to the backing arrays and maybe send the data directly.

          Looking forward to seeing the readv impl too

          Show
          Tim Ellison added a comment - Good to see this enhancement! A minor comment first Please check return values for : + vect = (struct iovec*) hymem_allocate_memory(sizeof(struct iovec) * length); + + message = (*env)->GetPrimitiveArrayCritical(env, addrs, &isCopyMessage); + cts = (*env)->GetPrimitiveArrayCritical(env, counts, &isCopyCts); A further enhancement is to have two versions of primitives, one that deals with direct buffers and one that deals with java heap buffers, so that there is (potentially) no data copying required for the java-heap buffers version that you have got today: + if (!buffer.isDirect()) { + src [i] = ByteBuffer.allocateDirect(buffer.remaining()); + int oldPosition = buffer.position(); + src [i] .put(buffer); some VMs will pin the java heap memory accessed in JNI (GetByteArrayElements), so if you can get hold of the ByteBuffer#array() you can pass a set of pointers to the backing arrays and maybe send the data directly. Looking forward to seeing the readv impl too
          Regis Xu made changes -
          Attachment HARMONY-6328.v2.diff [ 12418351 ]
          Hide
          Regis Xu added a comment -

          HARMONY-6328.v2.diff add Windows implementation, it includes previous one.

          Show
          Regis Xu added a comment - HARMONY-6328 .v2.diff add Windows implementation, it includes previous one.
          Regis Xu made changes -
          Field Original Value New Value
          Attachment HARMONY-6328.diff [ 12418328 ]
          Hide
          Regis Xu added a comment -

          This patch add a new method writevDirect to INetworkSystem, and only implement native code on Linux, Windows side code will implement soon.

          Show
          Regis Xu added a comment - This patch add a new method writevDirect to INetworkSystem, and only implement native code on Linux, Windows side code will implement soon.
          Regis Xu created issue -

            People

            • Assignee:
              Regis Xu
              Reporter:
              Regis Xu
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development