RFR: 8266369: (se) Add wepoll based Selector

Alan Bateman alanb at openjdk.java.net
Fri Apr 30 17:25:29 UTC 2021


This PR proposes a new Selector implementation for the Windows platform based on the Bert Belder's "wepoll" library. The wepoll library provides a scalable polling interface to the Ancillary Function Driver for Winsock. The interface that it exposes is close to the Linux epoll interface. The main benefit is that the cost of selection operations are a function of the number of sockets that are ready for I/O rather than the number of channels registered with the Selector. The existing Selector on Windows uses the legacy "select" which scales horribly, partly because it's O(N) on the number of registered channels and partly because it is limited to 1024 sockets and so requires a thread per 1024 sockets.

The patch brings the wepoll sources into the repo, adds a small shim, and the Selector implementation itself. The new implementation needs to handle OOB data in the same way as the old implementation so the method to discard OOB moves to Net.

I've added a microbenchmark to demonstrate the scaling when there is 1, 10, ... 10k connections and one socket ready for I/O. Windows Server 2019 was used for the data here. I've seen improvements with almost everything that I've tried. The only exception is a select after a wakeup where the old implementation skips the selection operation (arguably a long standing bug in the old implementation).

Existing select based Selector where the selection operation is almost 1ms when there are 10,000 channels registered.

Benchmark                (nchannels)  Mode  Cnt       Score       Error  Units
SelectOne.testSelectOne            1  avgt   20    1587.429 ±     4.053  ns/op
SelectOne.testSelectOne           10  avgt   20    2515.324 ±     8.141  ns/op
SelectOne.testSelectOne          100  avgt   20   10903.445 ±    65.508  ns/op
SelectOne.testSelectOne         1000  avgt   20  101651.369 ±   673.781  ns/op
SelectOne.testSelectOne        10000  avgt   20  932032.385 ± 59004.246  ns/op


New wepoll based Selector:

Benchmark                (nchannels)  Mode  Cnt     Score    Error  Units
SelectOne.testSelectOne            1  avgt   20  1428.914 ±  6.648  ns/op
SelectOne.testSelectOne           10  avgt   20  1429.806 ±  5.537  ns/op
SelectOne.testSelectOne          100  avgt   20  1433.371 ±  3.253  ns/op
SelectOne.testSelectOne         1000  avgt   20  1435.007 ± 12.420  ns/op
SelectOne.testSelectOne        10000  avgt   20  1445.201 ±  7.902  ns/op


Replacing the Selector implementation after 19 years of service is a big step. The proposal is to leave the existing implementation until there is confidence with the new implementation. It also serves as a backup in case Windows were to significantly change the AFD interface. The old Selector can be used by running with -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.WindowsSelectorProvider. A selection of existing tests have been updated to run a second time with the old Selector so that it is continues to be tested.

CSR and Release Note planned.

-------------

Commit messages:
 - Initial commit

Changes: https://git.openjdk.java.net/jdk/pull/3816/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3816&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8266369
  Stats: 3271 lines in 23 files changed: 3169 ins; 61 del; 41 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3816.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3816/head:pull/3816

PR: https://git.openjdk.java.net/jdk/pull/3816


More information about the nio-dev mailing list