Overview
The MetricConfig class is an immutable configuration object that controls the behavior of the Ray Java metric reporting scheduler.
Description
MetricConfig defines three configuration parameters for the metric registry: the reporting time interval, the thread pool size for the scheduler, and the shutdown wait time. It provides sensible defaults (5-second interval, 1 thread, 3-second shutdown wait) through a static DEFAULT_CONFIG instance. A nested MetricConfigBuilder class implements the builder pattern for creating custom configurations.
Usage
Use MetricConfig when you need to customize the metric reporting behavior, such as adjusting the flush interval or thread pool size. For most cases, the DEFAULT_CONFIG is sufficient. Pass a MetricConfig instance to Metrics.init() to initialize the metric registry with custom settings.
Code Reference
Source Location
- Repository: Ray
- File:
java/runtime/src/main/java/io/ray/runtime/metric/MetricConfig.java
Signature
public class MetricConfig {
public static final MetricConfig DEFAULT_CONFIG;
public MetricConfig(long timeIntervalMs, int threadPoolSize, long shutdownWaitTimeMs)
public long timeIntervalMs()
public int threadPoolSize()
public long shutdownWaitTimeMs()
public String toString()
public static MetricConfigBuilder builder()
public static class MetricConfigBuilder {
public MetricConfig create()
public MetricConfigBuilder timeIntervalMs(long timeIntervalMs)
public MetricConfigBuilder threadPoolSize(int threadPoolSize)
public MetricConfigBuilder shutdownWaitTimeMs(long shutdownWaitTimeMs)
}
}
Import
import io.ray.runtime.metric.MetricConfig;
I/O Contract
| Constructor Parameters
|
| Name |
Type |
Required |
Description
|
timeIntervalMs |
long |
Yes |
Time interval in milliseconds between metric flushes to the native stats system
|
threadPoolSize |
int |
Yes |
Number of threads in the scheduled executor pool for metric reporting
|
shutdownWaitTimeMs |
long |
Yes |
Maximum time in milliseconds to wait for the scheduler to shut down gracefully
|
| Accessor Methods
|
| Method |
Return Type |
Default Value |
Description
|
timeIntervalMs() |
long |
5000 |
Returns the reporting interval in milliseconds
|
threadPoolSize() |
int |
1 |
Returns the thread pool size
|
shutdownWaitTimeMs() |
long |
3000 |
Returns the shutdown wait time in milliseconds
|
| Default Constants
|
| Constant |
Value |
Description
|
DEFAULT_TIME_INTERVAL_MS |
5000 |
Default flush interval (5 seconds)
|
DEFAULT_THREAD_POLL_SIZE |
1 |
Default number of scheduler threads
|
DEFAULT_SHUTDOWN_WAIT_TIME_MS |
3000 |
Default shutdown grace period (3 seconds)
|
| Builder Methods
|
| Method |
Parameter |
Return Type |
Description
|
builder() |
none |
MetricConfigBuilder |
Static factory method to create a new builder
|
timeIntervalMs(long) |
timeIntervalMs |
MetricConfigBuilder |
Sets the reporting interval
|
threadPoolSize(int) |
threadPoolSize |
MetricConfigBuilder |
Sets the thread pool size
|
shutdownWaitTimeMs(long) |
shutdownWaitTimeMs |
MetricConfigBuilder |
Sets the shutdown wait time
|
create() |
none |
MetricConfig |
Builds and returns the immutable configuration object
|
Usage Examples
// Use the default configuration
MetricConfig defaultConfig = MetricConfig.DEFAULT_CONFIG;
Metrics.init(defaultConfig);
// Build a custom configuration using the builder pattern
MetricConfig customConfig = MetricConfig.builder()
.timeIntervalMs(10000) // Flush every 10 seconds
.threadPoolSize(2) // Use 2 scheduler threads
.shutdownWaitTimeMs(5000) // Wait 5 seconds on shutdown
.create();
MetricRegistry registry = Metrics.init(customConfig);
// Inspect configuration values
long interval = customConfig.timeIntervalMs(); // 10000
int poolSize = customConfig.threadPoolSize(); // 2
long waitTime = customConfig.shutdownWaitTimeMs(); // 5000
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.