@ManagedObject(value="Monitor for low resource conditions and activate a low resource mode if detected") public class LowResourceMonitor extends AbstractLifeCycle
An instance of this class will monitor all the connectors of a server (or a set of connectors
configured with setMonitoredConnectors(Collection)
) for a low resources state.
Low resources can be detected by:
ThreadPool.isLowOnThreads()
if Connector.getExecutor()
is
an instance of ThreadPool
and setMonitorThreads(boolean)
is true.setMaxMemory(long)
is non zero then low resources is detected if the JVMs
Runtime
instance has Runtime.totalMemory()
minus Runtime.freeMemory()
greater than getMaxMemory()
setMaxConnections(int)
is non zero then low resources is dected if the total number
of connections exceeds getMaxConnections()
Once low resources state is detected, the cause is logged and all existing connections returned
by Connector.getConnectedEndPoints()
have EndPoint.setIdleTimeout(long)
set
to getLowResourcesIdleTimeout()
. New connections are not affected, however if the low
resources state persists for more than getMaxLowResourcesTime()
, then the
getLowResourcesIdleTimeout()
to all connections again. Once the low resources state is
cleared, the idle timeout is reset to the connector default given by Connector.getIdleTimeout()
.
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Constructor and Description |
---|
LowResourceMonitor(Server server) |
Modifier and Type | Method and Description |
---|---|
protected void |
clearLowResources() |
protected void |
doStart() |
protected void |
doStop() |
int |
getLowResourcesIdleTimeout() |
String |
getLowResourcesReasons() |
long |
getLowResourcesStarted() |
int |
getMaxConnections() |
int |
getMaxLowResourcesTime() |
long |
getMaxMemory() |
Collection<Connector> |
getMonitoredConnectors() |
protected Connector[] |
getMonitoredOrServerConnectors() |
boolean |
getMonitorThreads() |
int |
getPeriod() |
boolean |
isLowOnResources() |
protected void |
monitor() |
protected void |
setLowResources() |
void |
setLowResourcesIdleTimeout(int lowResourcesIdleTimeoutMS) |
void |
setMaxConnections(int maxConnections) |
void |
setMaxLowResourcesTime(int maxLowResourcesTimeMS) |
void |
setMaxMemory(long maxMemoryBytes) |
void |
setMonitoredConnectors(Collection<Connector> monitoredConnectors) |
void |
setMonitorThreads(boolean monitorThreads) |
void |
setPeriod(int periodMS) |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
@ManagedAttribute(value="Are the monitored connectors low on resources?") public boolean isLowOnResources()
@ManagedAttribute(value="The reason(s) the monitored connectors are low on resources") public String getLowResourcesReasons()
@ManagedAttribute(value="Get the timestamp in ms since epoch that low resources state started") public long getLowResourcesStarted()
@ManagedAttribute(value="The monitored connectors. If null then all server connectors are monitored") public Collection<Connector> getMonitoredConnectors()
public void setMonitoredConnectors(Collection<Connector> monitoredConnectors)
monitoredConnectors
- The collections of Connectors that should be monitored for low resources.@ManagedAttribute(value="The monitor period in ms") public int getPeriod()
public void setPeriod(int periodMS)
periodMS
- The period in ms to monitor for low resources@ManagedAttribute(value="True if low available threads status is monitored") public boolean getMonitorThreads()
public void setMonitorThreads(boolean monitorThreads)
monitorThreads
- If true, check connectors executors to see if they are
ThreadPool
instances that are low on threads.@ManagedAttribute(value="The maximum connections allowed for the monitored connectors before low resource handling is activated") public int getMaxConnections()
public void setMaxConnections(int maxConnections)
maxConnections
- The maximum connections before low resources state is triggered@ManagedAttribute(value="The maximum memory (in bytes) that can be used before low resources is triggered. Memory used is calculated as (totalMemory-freeMemory).") public long getMaxMemory()
public void setMaxMemory(long maxMemoryBytes)
maxMemoryBytes
- The maximum memory in bytes in use before low resources is triggered.@ManagedAttribute(value="The idletimeout in ms to apply to all existing connections when low resources is detected") public int getLowResourcesIdleTimeout()
public void setLowResourcesIdleTimeout(int lowResourcesIdleTimeoutMS)
lowResourcesIdleTimeoutMS
- The timeout in ms to apply to EndPoints when in the low resources state.@ManagedAttribute(value="The maximum time in ms that low resources condition can persist before lowResourcesIdleTimeout is applied to new connections as well as existing connections") public int getMaxLowResourcesTime()
public void setMaxLowResourcesTime(int maxLowResourcesTimeMS)
maxLowResourcesTimeMS
- The time in milliseconds that a low resource state can persist before the low resource idle timeout is reapplied to all connectionsprotected void doStart() throws Exception
doStart
in class AbstractLifeCycle
Exception
protected void doStop() throws Exception
doStop
in class AbstractLifeCycle
Exception
protected Connector[] getMonitoredOrServerConnectors()
protected void monitor()
protected void setLowResources()
protected void clearLowResources()
Copyright © 1995-2015 Webtide. All Rights Reserved.