public class MemoryMonitor
extends java.lang.Object
implements java.lang.Runnable
Note: Only one instance of this should be initialized per server and it should be done when the server starts running.
This runnable works as follows:
(# monitored
periods in GC thrashing) / (# monitored periods).
| Modifier and Type | Class and Description |
|---|---|
static interface |
MemoryMonitor.GCStatsProvider
Abstract interface for providing GC stats (for testing).
|
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_SLEEP_TIME_MILLIS
Amount of time (in ms) this thread must sleep between two consecutive iterations.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
describeMemory()
Return a string describing the current memory state of the server.
|
java.io.File |
dumpHeap()
Dump the current heap profile to a file in the given directory and return its name.
|
static MemoryMonitor |
fromOptions(org.apache.beam.sdk.options.PipelineOptions options) |
boolean |
isThrashing() |
void |
run()
Runs this thread.
|
void |
stop()
Request the memory monitor stops.
|
@Nullable java.io.File |
tryToDumpHeap()
Dumps the heap to a file and return the name of the file, or null if the heap should
not or could not be dumped.
|
void |
waitForResources(java.lang.String context)
Return only when the server is not in the GC thrashing state.
|
void |
waitForThrashingState(boolean desiredThrashingState)
For testing only: Wait for thrashing status to be updated to given value.
|
public static final long DEFAULT_SLEEP_TIME_MILLIS
public static MemoryMonitor fromOptions(org.apache.beam.sdk.options.PipelineOptions options)
public void waitForThrashingState(boolean desiredThrashingState)
public void stop()
public boolean isThrashing()
public @Nullable java.io.File tryToDumpHeap()
public void run()
run in interface java.lang.Runnablepublic void waitForResources(java.lang.String context)
public java.io.File dumpHeap()
throws javax.management.MalformedObjectNameException,
javax.management.InstanceNotFoundException,
javax.management.ReflectionException,
javax.management.MBeanException,
java.io.IOException
NOTE: We deliberately don't salt the heap dump filename so as to minimize disk impact of repeated dumps. These files can be of comparable size to the local disk.
javax.management.MalformedObjectNameExceptionjavax.management.InstanceNotFoundExceptionjavax.management.ReflectionExceptionjavax.management.MBeanExceptionjava.io.IOExceptionpublic java.lang.String describeMemory()