RFR: 8227006 - [linux] Runtime.availableProcessors execution time increased by factor of 100

David Holmes david.holmes at oracle.com
Wed Oct 30 23:14:28 UTC 2019


Hi Bob,

On 31/10/2019 4:35 am, Bob Vandette wrote:
> Summary:  The container support added to Linux caused the call to os::active_processor_count to
> become much more expensive than prior to the container addition.  This RFR adds a cache to avoid
> the extra overhead on repetitive calls to Runtime.getRuntime().availableProcessors().  The cache
> timeout is set at 20ms.  This allows the docker update command to alter the number of available processors
> which will be reflected in the return from the API.
> 
> BUG: https://bugs.openjdk.java.net/browse/JDK-8227006
> WEBREV:  http://cr.openjdk.java.net/~bobv/8227006/webrev.01

The caching mechanism is somewhat racy, but that is probably tolerable 
given the expected timeframes for making changes.

I have some naming suggestions but feel free to ignore

  130     bool cache_has_expired() {
  131       return os::elapsed_counter() > _next_check_counter;
  132     }
  133
  134     void set_cache_expiry_time(jlong timeout) {
  135       _next_check_counter = os::elapsed_counter() + timeout;
  136     }

Aside: it would be slightly more efficient to just store the current 
time from javaTimeNanos() directly rather than using 
os::elapsed_counter(). Again feel free to ignore.

Reviewed.

Thanks,
David

> Adding a single cache of active_processor_count with a 20ms timeout results in the following improvements.
> 
> ORIGINAL SCORES
> 
> 39346 calls/sec
> 40007 calls/sec
> 39708 calls/sec
> 39732 calls/sec
> 39736 calls/sec
> 39629 calls/sec
> 
> DISABLE CONTAINER SUPPORT (-XX:-UseContainerSupport)
> 
> 1106795 calls/sec
> 1135589 calls/sec
> 1123782 calls/sec
> 1123605 calls/sec
> 1123343 calls/sec
> 1123135 calls/sec
> 
> 20MS TIMEOUT CACHE
> 
> 9867172 calls/sec
> 10077977 calls/sec
> 9989674 calls/sec
> 9983963 calls/sec
> 9984400 calls/sec
> 9985898 calls/sec
> 9985123 calls/sec
> 9985608 calls/sec
> 
> So the cache actually improves performance beyond the pre-container support by 8x but
> this of course only helps programs that call this function in a loop.
> 
> 
> Bob.
> 
> 
> 


More information about the hotspot-runtime-dev mailing list