zentol commented on a change in pull request #13163: URL: https://github.com/apache/flink/pull/13163#discussion_r471631455
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/management/JMXService.java ########## @@ -85,6 +86,9 @@ private static JMXServer startJMXServerWithPortRanges(Iterator<Integer> ports) { while (ports.hasNext() && successfullyStartedServer == null) { JMXServer server = new JMXServer(); int port = ports.next(); + if (port == 0) { // try poke with a random port when port is set to zero Review comment: That's a fair concern, and it does make me wonder whether we shouldn't just add a retry to the port poking approach; on average we'll likely end up with fewer attempts. Nevertheless, I still thought about how we could alleviate the concern: We could use a custom iterator that is not simply iterating over the port range, but also jumping into other port blocks. So instead of checking `1, 2, 3, ..., 65000` we do ` 1000, 2000, 3000, ..., 65000, 1, 1001, 2001, ...`; i would think it is more likely that we run into a completely used port block (e.g., 8000-9000) than the first N ports in each block being used. We can make the blocks arbitrarily small (e.g., 100), and the iterator implementation should be fairly simple. ``` non-iterator solution: port = START // this could even be random value between 1 and BLOCK_SIZE while (port != SOME_END_CRITERIA_PORT): if (!canCreateJMXServer(port)): port = port + BLOCK_SIZE if port > MAX: port = (port + 1) % MAX ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org