|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.tmf.ThroughputMonitorFilterBase
org.hd.d.pg2k.webSvr.util.ThroughputMonitorFilterPG2K
public final class ThroughputMonitorFilterPG2K
Filter to monitor throughput (output rate) to help regulate flow. Can be used in association with the compression filter to enable compression when our output pipe is likely to get congested.
(This filter has had a few miscellaneous bits of functionality thrown in for now:
This also makes a rough estimate of the number of users (without forcing a session) by counting the number of IP addresses used to visit the site through this servlet container instance (probably a slight overestimate). This ignores clients that are probably spiders (ie that never send a referring URL), and that appear to be one-off hotlinks from external sites.
A truely distributed front end will need a more sophisticated communication mechanism to share data efficiently between front-end instances.
TODO: This filter is not yet suitable for multi-JVM front-ends (clustering) or otherwise where the WAR container creates multiple instances of this filter for what is logically one front-end.
| Field Summary | |
|---|---|
private long |
_lastForcedZero
Last time reported bandwidth was (forced to) zero, eg because of overload. |
private static java.lang.String |
ANTI_DUP_ATTR_NAME
Name of attribute that we use to avoid duplicate application of this filter on one filter chain. |
private static float |
BPS_TO_GBP30D
Conversion factor from byte/second to GB/30day. |
private static java.lang.String |
CATAREA_PREFIX
Common (possibly ambiguous) prefix for catalogue page and search page. |
private static java.lang.String |
CATPAGE_PREFIX
Unique prefix for catalogue pages. |
private java.util.concurrent.atomic.AtomicInteger |
catPageHitCounter
Counter of all catalogue-page GET hits. |
private static boolean |
CHECK_DNSRBL_EARLY
If true, check clients in DNS BL before each access if status is not known. |
private static int |
DNSBL_RESULT_CACHE_MS
Approximate time we cache a positive or negative DNS BL lookup value for; strictly positive. |
private static boolean |
DO_PREEMPTIVE_GC
If true, then we may try to force a preemptive GC when the system is idle. |
private static boolean |
DO_QUICK_GEO_LOOKUP
If false, be prepared to consume extra resources working out geographical location of client. |
private long |
dontDumpThreadsBefore
Don't dump busy threads again before this time; initially zero so first dump is immediately as required. |
private static java.lang.String |
EX_PREFIX
Unique prefix for exhibits. |
private java.util.concurrent.atomic.AtomicInteger |
hitCounter
Counter of all (successful) hits. |
private MemoryTools.SimpleLRUMapAutoSizeForHitRate<java.net.InetAddress,Tuple.Pair<java.lang.Long,java.lang.String>> |
inBL
LRU set of clients currently known to be in a DNS BL. |
private static java.lang.String |
KEY_debugFlag
Key in generic props of slow-profile flag and/or as system property. |
private static boolean |
LOG_ONLY_INJVM
If true then omit threads in native code, ie not actively burning CPU in the JVM. |
private static boolean |
LOG_ONLY_TOPMOST
If true then only show top-most method in log rather than entire trace... |
private WebUtils.ServletLoggerWithFallback |
logger
Our logger which falls back to System.out if servlet log not available; never null. |
private int |
maxBpsFor30D
|
private int |
maxGBytesPer30D
Any GB-per-30-days traffic limit; strictly positive if set. |
private long |
nextSendAllParams
Time when we will next report the slow-changing parameters, initially 0 to force immediate send. |
private static boolean |
permSlowProfile
Allow a hard-wired profiling from the get-go if required as if centrally enabled. |
static java.lang.String |
PNAME_SAVED_REQ_URI
Request attribute (property name) in which we save the incoming requestURI. |
private static SimpleVariableDefinition |
PROFILING_EVENT
System event to which profiling/busy events are recorded. |
private static int |
RAMP_UP_TIME_MS
Ramp up time (ms) from zero bandwidth, eg at start-up or on recovery from overload; non-negative. |
private static boolean |
REDIRECT_DEPRECATED_HOSTNAME
If true, redirect users arriving with a deprecated host name. |
private static boolean |
REPORT_UNEXPECTED_HOSTNAME
If true, report any unexpected host name used to access the site. |
private static boolean |
STARTUP_EXECUTION_SAMPLING_ENABLED
Allow start-up fast execution sampling for performance tuning. |
private static int |
STARTUP_EXECUTION_SAMPLING_MAX_DUMP
Maximum number of (top) sampled sites to dump; strictly positive. |
private static int |
STARTUP_EXECUTION_SAMPLING_MS
Start-up sampling time (ms); strictly positive. |
private StatsLogger.StatsConfig |
statsIDTHRFGEN
The stats set to which we log general throughput events. |
private java.util.concurrent.atomic.AtomicInteger |
stickyClientHitCounter
Counter of "sticky" hits on site pages (rather than graphics). |
static java.lang.String |
THRFNAME_kHIT
General stats event name: 1000 hits (GETs, POSTs, redirects, etc). |
static java.lang.String |
THRFNAME_kHIT_CAT_PAGE
General stats event name: 1000 catalogue page hits (GETs). |
static java.lang.String |
THRFNAME_kHIT_STICKY_CLIENT_PAGE
General stats event name: 1000 "sticky client" page hits (GETs). |
static java.lang.String |
THRFNAME_REDIR_ALIAS
General stats event name: redirect issued to client because of deprecated alias. |
static java.lang.String |
THRFNAME_REDIR_TO_LOCAL
General stats event name: redirect issued to client to get them to local mirror. |
static java.lang.String |
THRFNAME_REDIR_UNKNOWN
General stats event name: redirect issued to client because of unknown name. |
static java.lang.String |
THRFNAMEPR_CLIENT_PROXIMITY
General stats event name prefix: client estimated proximity from IP address. |
static java.lang.String |
THRFNAMEPR_CLIENT_REGION
General stats event name prefix: client region by IP address. |
static java.lang.String |
THRFNAMEPR_CODATIME
General stats event name prefix: coda processing time log(ms). |
static java.lang.String |
THRFNAMEPR_DNSRBL_DETECTION
General stats event name prefix: client SPAMmer/compromised detected by given DNSRBL. |
static java.lang.String |
THRFNAMEPR_STICKY_CLIENT_REGION
General stats event name prefix: "sticky" client region by IP address. |
static java.lang.String |
THRFNAMEPR_VHOST
General stats event name prefix: virtual host name used to fetch page. |
| Fields inherited from class org.hd.d.tmf.ThroughputMonitorFilterBase |
|---|
ATTR_NAME_SUFFIX_BUSY_FRACTION_SMOOTHED, ATTR_NAME_SUFFIX_BYTES_PER_SEC_OUTBOUND, ATTR_NAME_SUFFIX_CONNECTION_LOAD, ATTR_NAME_SUFFIX_CONNECTION_LOAD_LONG_TERM, ATTR_NAME_SUFFIX_DAILY_UNIQUE_VISITORS, ATTR_NAME_SUFFIX_SERVER_LIFETIME_BYTES_PER_SEC_OUTBOUND, DEFAULT_ATTR_PREFIX, DEFAULT_CLIENT_IP_PURGE_TIME_S, DEFAULT_LOWER_THRESHOLD, DEFAULT_MAX_BYTES_PER_SEC, DEFAULT_TIMER_INTERVAL_MS, DEFAULT_UPPER_THRESHOLD, MONITOR_GET_TRAFFIC_ONLY, NEW_HTTP_OVERHEAD_BYTES_EST, REQ_ATTR_NAME_NEW_CLIENT_FLAG, UNIQUE_VISTOR_MEASUREMENT_INTERVAL_MS, UNIQUE_VISTOR_MEASUREMENT_MAX_BUCKET_SIZE, WARMUP_TIME_TICKS |
| Constructor Summary | |
|---|---|
ThroughputMonitorFilterPG2K()
|
|
| Method Summary | |
|---|---|
private void |
_doCoda(javax.servlet.FilterConfig config,
javax.servlet.http.HttpServletRequest requestH,
boolean isGET,
java.lang.String reqURI,
Tuple.Pair<java.lang.Long,java.lang.String> statusInRBL,
java.net.InetAddress clientIP,
boolean checkBL)
Handle coda processing, ie after servicing body of request. |
private void |
_logThreads(int connCount,
boolean dontPrint)
Log running threads to the event record and servlet stats, and optionally to the servlet log. |
private static void |
_perfSampleThreadsQuick(java.util.concurrent.ConcurrentHashMap<java.lang.StackTraceElement,java.util.concurrent.atomic.AtomicInteger> counts)
Quickly sample running threads for performance logging, eg at start-up. |
void |
destroy()
Unhook from servlet logger. |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
Called to handle each (HTTP) request. |
protected boolean |
dontMonitorMe(javax.servlet.http.HttpServletRequest httpServletRequest)
Exclude some traffic from connection-responsiveness monitoring. |
protected int |
expectedBpsPerStickyClient()
Returns expected approximate bytes-per-second per sticky client; strictly positive. |
private java.util.Set<java.lang.String> |
getDNSBLs()
Get the set of DNS RBLs to screen traffic, empty if none; never null. |
void |
init(javax.servlet.FilterConfig filterConfig)
Hook into servlet logger. |
protected boolean |
isStickyClient(boolean isGET,
javax.servlet.http.HttpServletRequest requestH,
java.net.InetAddress clientIP)
Returns true if we deem this a hit to be from a "sticky" client. |
protected void |
logBusyThreads(int connCount)
Make a note of the thread state in a (busy) system. |
protected void |
onIdle()
Called when the system is idle according to the throughput monitor. |
private static boolean |
slowProfileEnabled(GenProps gp)
If true then slow profiling is enabled. |
protected void |
stickyClientPageHit(java.net.InetAddress clientIP)
Note a page (eg HTML) hit from a sticky client. |
protected void |
tick(int availableBpsPerClientBasic,
int allVisitorCount,
int stickyVisitorCount,
float ltbpss,
int dailyUniqueVisitors,
float busyFractionSmoothed,
boolean tooManyVisitors,
boolean connectionTooBusy,
boolean systemTooBusy)
Called on every tick, and passed the most important metrics. |
| Methods inherited from class org.hd.d.tmf.ThroughputMonitorFilterBase |
|---|
computeApproximateUserCapacity, getConfig, getValue, getValueMapRO, newClient |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String PNAME_SAVED_REQ_URI
private static final boolean DO_PREEMPTIVE_GC
private static final float BPS_TO_GBP30D
private static final int RAMP_UP_TIME_MS
private final int maxGBytesPer30D
private final int maxBpsFor30D
private static final java.lang.String EX_PREFIX
private static final java.lang.String CATPAGE_PREFIX
private static final java.lang.String CATAREA_PREFIX
private static final SimpleVariableDefinition PROFILING_EVENT
private final WebUtils.ServletLoggerWithFallback logger
private final StatsLogger.StatsConfig statsIDTHRFGEN
public static final java.lang.String THRFNAMEPR_CLIENT_REGION
public static final java.lang.String THRFNAMEPR_STICKY_CLIENT_REGION
public static final java.lang.String THRFNAMEPR_CLIENT_PROXIMITY
public static final java.lang.String THRFNAMEPR_DNSRBL_DETECTION
public static final java.lang.String THRFNAMEPR_CODATIME
public static final java.lang.String THRFNAMEPR_VHOST
public static final java.lang.String THRFNAME_REDIR_UNKNOWN
public static final java.lang.String THRFNAME_REDIR_TO_LOCAL
public static final java.lang.String THRFNAME_REDIR_ALIAS
public static final java.lang.String THRFNAME_kHIT
public static final java.lang.String THRFNAME_kHIT_CAT_PAGE
public static final java.lang.String THRFNAME_kHIT_STICKY_CLIENT_PAGE
private static final boolean DO_QUICK_GEO_LOOKUP
private static final boolean REPORT_UNEXPECTED_HOSTNAME
private static final boolean REDIRECT_DEPRECATED_HOSTNAME
private volatile long nextSendAllParams
private volatile long _lastForcedZero
Marked volatile for safe lock-free access, though in fact this is probably unnecessary.
private static final java.lang.String KEY_debugFlag
private static final boolean permSlowProfile
private long dontDumpThreadsBefore
private static final boolean LOG_ONLY_TOPMOST
private static final boolean LOG_ONLY_INJVM
private static final boolean STARTUP_EXECUTION_SAMPLING_ENABLED
private static final int STARTUP_EXECUTION_SAMPLING_MS
private static final int STARTUP_EXECUTION_SAMPLING_MAX_DUMP
private final java.util.concurrent.atomic.AtomicInteger stickyClientHitCounter
We use an AtomicInteger to avoid having to take a lock.
private final java.util.concurrent.atomic.AtomicInteger hitCounter
We use an AtomicInteger to avoid having to take a lock.
private final java.util.concurrent.atomic.AtomicInteger catPageHitCounter
We use an AtomicInteger to avoid having to take a lock.
private static final boolean CHECK_DNSRBL_EARLY
private static final java.lang.String ANTI_DUP_ATTR_NAME
private static final int DNSBL_RESULT_CACHE_MS
private final MemoryTools.SimpleLRUMapAutoSizeForHitRate<java.net.InetAddress,Tuple.Pair<java.lang.Long,java.lang.String>> inBL
A thread-safe LRU map is used to limit memory use (it does not grow if it can discard an old/expired entry). The underlying DNS service should also be cacheing for us, so a cache-miss here is probably not desperately expensive. We allow a large range in capacity to help cope with DDoS-like bursts of distinct clients (ie distinct remote IP addresses), while whittling down memory consumption in quieter times.
We're prepared to discard this entirely under acute memory stress.
| Constructor Detail |
|---|
public ThroughputMonitorFilterPG2K()
| Method Detail |
|---|
protected void onIdle()
onIdle in class org.hd.d.tmf.ThroughputMonitorFilterBasepublic void destroy()
destroy in interface javax.servlet.Filterdestroy in class org.hd.d.tmf.ThroughputMonitorFilterBasepublic void init(javax.servlet.FilterConfig filterConfig)
init in interface javax.servlet.Filterinit in class org.hd.d.tmf.ThroughputMonitorFilterBaseprotected int expectedBpsPerStickyClient()
expectedBpsPerStickyClient in class org.hd.d.tmf.ThroughputMonitorFilterBase
protected void tick(int availableBpsPerClientBasic,
int allVisitorCount,
int stickyVisitorCount,
float ltbpss,
int dailyUniqueVisitors,
float busyFractionSmoothed,
boolean tooManyVisitors,
boolean connectionTooBusy,
boolean systemTooBusy)
tick in class org.hd.d.tmf.ThroughputMonitorFilterBaseavailableBpsPerClientBasic - estimated available bytes/sec
available for one new client (or an existing client); non-negativeallVisitorCount - approximate count of "live" visitors;
non-negativestickyVisitorCount - approximate count of "live" "sticky" visitors;
non-negativeltbpss - long-term bytes/sec smoothed throughputdailyUniqueVisitors - estimated unique visitors per day;
non-negativebusyFractionSmoothed - smoothed system "busy-ness" value
ranging from 0.0 (idle) to 1.0 (busy)tooManyVisitors - true if well over capacity by user countconnectionTooBusy - true if well over capacity by bandwidthsystemTooBusy - true if system busy fraction dangerously highprivate static boolean slowProfileEnabled(GenProps gp)
protected void logBusyThreads(int connCount)
logBusyThreads in class org.hd.d.tmf.ThroughputMonitorFilterBaseconnCount - current active-connection count; non-negative
private void _logThreads(int connCount,
boolean dontPrint)
throws java.io.IOException
connCount - number of open inbound connections if non-negativedontPrint - if false then log to the servlet context log too
java.io.IOExceptionprivate static void _perfSampleThreadsQuick(java.util.concurrent.ConcurrentHashMap<java.lang.StackTraceElement,java.util.concurrent.atomic.AtomicInteger> counts)
This logs the top-most (current) activation record for every live thread (non-NEW, non-TERMINATED) in the system as a count in the table.
The calling thread is omitted.
It is safe for other threads to read the counts map while it is being updated in here: the map is always kept in a consistent state.
counts - caller-supplied map to be updated with counts of samples
at each execution site; never null
protected boolean isStickyClient(boolean isGET,
javax.servlet.http.HttpServletRequest requestH,
java.net.InetAddress clientIP)
This means that we should capture hits by a user on their second and subsequent page views.
isStickyClient in class org.hd.d.tmf.ThroughputMonitorFilterBaseisGET - true if the method is GETrequestH - the HTTP request; never nullclientIP - the client's IP address; never null
protected void stickyClientPageHit(java.net.InetAddress clientIP)
clientIP - client's IP address, never null.
public void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
throws java.io.IOException,
javax.servlet.ServletException
We may also redirect a client if a non-preferred (or unrecognised) hostname is used to contact the server.
We call super.doFilter() to get all the basic throughput measurement tasks done.
doFilter in interface javax.servlet.FilterdoFilter in class org.hd.d.tmf.ThroughputMonitorFilterBasejava.io.IOException
javax.servlet.ServletException
private void _doCoda(javax.servlet.FilterConfig config,
javax.servlet.http.HttpServletRequest requestH,
boolean isGET,
java.lang.String reqURI,
Tuple.Pair<java.lang.Long,java.lang.String> statusInRBL,
java.net.InetAddress clientIP,
boolean checkBL)
throws java.io.IOException
java.io.IOExceptionprivate java.util.Set<java.lang.String> getDNSBLs()
protected boolean dontMonitorMe(javax.servlet.http.HttpServletRequest httpServletRequest)
dontMonitorMe in class org.hd.d.tmf.ThroughputMonitorFilterBase
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||