Friday, July 27, 2012

Undocumented Oracle JVM HttpServer Properties

I have blogged before on the utility of the HttpServer provided with the Oracle HotSpot JVM. One of the general challenges associated with its use is the lack of documentation. Fortunately, its open source implementation allows certain features to be discovered. In this post, I look at some apparently undocumented properties that are used by the HttpServer's source code.

A colleague (thanks Jim!) pointed out the existence of these properties as discovered in the source code. There are multiple places from which the relevant source code can be acquired and reviewed. One easily accessible location is Docjar. For example, the code listings for sun.net.httpserver.ServerConfig and sun.net.httpserver.ServerImpl are hosted there. Other similar sites include Open Source Java Code (ServerConfig) and grepcode (ServerConfig).

The static initialization block of the sun.net.httpserver.ServerConfig class includes the setting of several static variables based on specific Java properties or based on a default if no property is provided. The next code listing comes from that class and indicates the default values for these static variables.

static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec.

/* These values must be a reasonable multiple of clockTick */
static final long DEFAULT_IDLE_INTERVAL = 30 ; // 5 min
static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ;

static final long DEFAULT_MAX_REQ_TIME = -1; // default: forever
static final long DEFAULT_MAX_RSP_TIME = -1; // default: forever
static final long DEFAULT_TIMER_MILLIS = 1000;

static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024;

As the code and comments above indicate, the default idle interval is 300 seconds (5 minutes). The default request and response times are "forever" indicated by -1.

Although defaults are available as indicated in the above code listing, these can be overridden via the specification of Java properties. These properties are not well documented, but can be gleaned from the code. The following is a list of them as extracted from the ServerConfig class with notes about each property based on other portions of the code.

Properties for Configuring HotSpot HttpServer
  • sun.net.httpserver.idleInterval
  • sun.net.httpserver.clockTick
  • sun.net.httpserver.maxIdleConnections
  • sun.net.httpserver.drainAmount
  • sun.net.httpserver.maxReqTime
    • Replaces sun.net.httpserver.readTimeout
  • sun.net.httpserver.maxRspTime
    • Replaces sun.net.httpserver.writeTimeout
  • sun.net.httpserver.timerMillis
  • sun.net.httpserver.debug

Note that the property sun.net.httpserver.selCacheTimeout is no longer used, but does not have its replacement spelled out in the code comments or logged messages.

The Oracle JVM HttpServer allows for configuration based on Java properties. These properties are not well advertised, but the open source nature of the HttpServer implementation makes it possible to browse the code to determine which properties are available.

1 comment:

David Hofmann said...

what are the clocktick and timermillis properties for ?