302018 301089 300933 Improve statistics
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1268 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
37fe212f35
commit
176ba8073f
27
VERSION.txt
27
VERSION.txt
|
@ -9,25 +9,26 @@ jetty-7.0.2-SNAPSHOT
|
|||
+ 298234 Unit test for jetty-client handling different HTTP error codes
|
||||
+ 298667 DeploymentManager uses ContextProvider and WebAppProvider
|
||||
+ 299455 Enum support in JSONPojoConvertor
|
||||
+ 302198 Rename HttpClient authorization classes to Authentication
|
||||
+ 302244 invalid configuration boolean conversion in FormAuthenticator
|
||||
+ 302246 redirect loop using form authenticator
|
||||
+ JETTY-776 Make new session-tests module to concentrate all reusable session clustering test code
|
||||
+ JETTY-910 Allow request listeners to access session
|
||||
+ JETTY-983 Range handling cleanup
|
||||
+ JETTY-1153 System property for UrlEncoded charset
|
||||
+ JETTY-1155 HttpConnection.close notifies HttpExchange
|
||||
+ JETTY-1156 SSL blocking close with JVM Bug busy key fix
|
||||
+ JETTY-1157 Don't hold array passed in write(byte[])
|
||||
+ JETTY-1151 JETTY-1098 allow UTF-8 with 0 carry bits
|
||||
+ JETTY-1177 Allow error handler to set cacheControl
|
||||
+ COMETD-46 reset ContentExchange response content on resend
|
||||
+ 300178 HttpClients opens too many connections that are immediately closed
|
||||
+ 300733 Jars from lib/ext are not visible for my web application
|
||||
+ 300933 AbstractConnector uses concurrent objects for stats
|
||||
+ 301089 Improve statistics available in StatisticsHandler and AbstractConnector
|
||||
+ 302018 Improve statistics available in AbstractSessionHandler
|
||||
+ 302198 Rename HttpClient authorization classes to Authentication
|
||||
+ 302244 invalid configuration boolean conversion in FormAuthenticator
|
||||
+ 302246 redirect loop using form authenticator
|
||||
+ 302556 CrossOriginFilter does not work correctly when Access-Control-Request-Headers header is not present
|
||||
+ 302669 WebInfConfiguration.unpack() unpacks WEB-INF/* from a ResourceCollection, breaking JSP reloading with ResourceCollections
|
||||
+ JETTY-776 Make new session-tests module to concentrate all reusable session clustering test code
|
||||
+ JETTY-910 Allow request listeners to access session
|
||||
+ JETTY-983 Range handling cleanup
|
||||
+ JETTY-1151 JETTY-1098 allow UTF-8 with 0 carry bits
|
||||
+ JETTY-1153 System property for UrlEncoded charset
|
||||
+ JETTY-1155 HttpConnection.close notifies HttpExchange
|
||||
+ JETTY-1156 SSL blocking close with JVM Bug busy key fix
|
||||
+ JETTY-1157 Don't hold array passed in write(byte[])
|
||||
+ JETTY-1177 Allow error handler to set cacheControl
|
||||
+ COMETD-46 reset ContentExchange response content on resend
|
||||
|
||||
jetty-7.0.1.v20091125 25 November 2009
|
||||
+ 274251 DefaultServlet supports exact match mode.
|
||||
|
|
|
@ -15,9 +15,7 @@ package org.eclipse.jetty.embedded;
|
|||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import org.eclipse.jetty.deploy.ContextDeployer;
|
||||
import org.eclipse.jetty.deploy.DeploymentManager;
|
||||
import org.eclipse.jetty.deploy.WebAppDeployer;
|
||||
import org.eclipse.jetty.deploy.providers.ContextProvider;
|
||||
import org.eclipse.jetty.deploy.providers.WebAppProvider;
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
|
@ -30,6 +28,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
|||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.RequestLogHandler;
|
||||
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -61,6 +60,8 @@ public class LikeJettyXml
|
|||
connector.setPort(8080);
|
||||
connector.setMaxIdleTime(30000);
|
||||
connector.setConfidentialPort(8443);
|
||||
connector.setStatsOn(true);
|
||||
|
||||
server.setConnectors(new Connector[]
|
||||
{ connector });
|
||||
|
||||
|
@ -71,6 +72,7 @@ public class LikeJettyXml
|
|||
ssl_connector.setKeyPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
|
||||
ssl_connector.setTruststore(jetty_home + "/etc/keystore");
|
||||
ssl_connector.setTrustPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
|
||||
ssl_connector.setStatsOn(true);
|
||||
server.addConnector(ssl_connector);
|
||||
|
||||
HandlerCollection handlers = new HandlerCollection();
|
||||
|
@ -78,7 +80,11 @@ public class LikeJettyXml
|
|||
RequestLogHandler requestLogHandler = new RequestLogHandler();
|
||||
handlers.setHandlers(new Handler[]
|
||||
{ contexts, new DefaultHandler(), requestLogHandler });
|
||||
server.setHandler(handlers);
|
||||
|
||||
StatisticsHandler stats = new StatisticsHandler();
|
||||
stats.setHandler(handlers);
|
||||
|
||||
server.setHandler(stats);
|
||||
|
||||
// Setup deployers
|
||||
DeploymentManager deployer = new DeploymentManager();
|
||||
|
|
|
@ -18,16 +18,3 @@ integralPort: Port to use for integral redirections.
|
|||
integralScheme: Scheme to use for integral redirections.
|
||||
lowResourcesConnections: The number of connections, which if exceeded represents low resources
|
||||
lowResourcesMaxIdleTime: The period in ms that a connection may be idle when the connector has low resources, before it is closed.
|
||||
statsOnMs: Time in milliseconds statistics have been collected for.
|
||||
statsReset(): Resets statistics.
|
||||
requests: Number of requests since statsReset() called.
|
||||
connections: Number of connections since statsReset() called.
|
||||
connectionsOpen: Number of open connections since statsReset() called.
|
||||
connectionsOpenMax: Maximum number of open connections since statsReset() called.
|
||||
connectionsRequestsMax: Maximum number of requests per connection since statsReset() called.
|
||||
connectionsRequestMean: Mean of number of requests per connection since statsReset() called.
|
||||
connectionsRequestStdDev: Standard deviation of number of requests per connection since statsReset() called.
|
||||
connectionsDurationTotal: Total amount of time in milliseconds connections were open since statsReset() called.
|
||||
connectionsDurationMax: Maximum amount of time in milliseconds a connection was open since statsReset() called.
|
||||
connectionsDurationMean: Mean of amount of time in milliseconds a connection was open since statsReset() called.
|
||||
connectionsDurationStdDev: Standard deviation of amount of time in milliseconds a connection was open since statsReset() called.
|
||||
|
|
|
@ -15,14 +15,13 @@ statsOnMs: Time in milliseconds stats have been collected for.
|
|||
statsReset(): Reset statistics.
|
||||
connections: Number of connections accepted by the server since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsOpen: Number of connections currently open that were opened since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsOpenMin: Minimim number of connections opened simultaneously since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsOpenMax: Maximum number of connections opened simultaneously since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsDurationAve: Average duration in milliseconds of open connections since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsDurationMin: Minimum duration in milliseconds of an open connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsDurationMean: Mean duration in milliseconds of open connections since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsDurationStdDev: Standard deviation of duration in milliseconds of an open connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsDurationMax: Maximum duration in milliseconds of an open connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsDurationTotal: Total duration in milliseconds of all open connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsRequestsAve: Average number of requests per connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsRequestsMin: Minimum number of requests per connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsRequestsMean: Mean number of requests per connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsRequestsStdDev: Standard deviation of number of requests per connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
connectionsRequestsMax: Maximum number of requests per connection since statsReset() called. Undefined if setStatsOn(false).
|
||||
requests: Number of requests since statsReset() called. Undefined if setStatsOn(false).
|
||||
open(): Open the listening port
|
||||
|
|
|
@ -3,13 +3,16 @@ httpOnly: True if cookies use the http only flag
|
|||
idManager: MObject:RO:The ID Manager instance
|
||||
maxCookieAge: if greater than zero, the time in seconds a session cookie will last for
|
||||
maxInactiveInterval: default maximim time in seconds a session may be idle
|
||||
maxSessions: The maximum number of simultaneous sessions
|
||||
minSessions: The minimum number of simultaneous sessions
|
||||
refreshCookieAge: The time in seconds after which a session cookie is re-set
|
||||
secureCookies: If true, the secure cookie flag is set on session cookies
|
||||
sessionCookie: The set session cookie
|
||||
sessionDomain: The domain of the session cookie or null for the default
|
||||
sessionPath: The path of the session cookie or null for the default
|
||||
sessions: The instantaneous number of sessions
|
||||
sessionsTotal: The total number of sessions
|
||||
sessionsMax: The maximum number of simultaneous sessions
|
||||
sessionTimeMax: The maximum session lifetime in seconds
|
||||
sessionTimeMean: The mean session lifetime in seconds
|
||||
sessionTimeStdDev: The standard deviation of session lifetime in seconds
|
||||
sessionIdPathParameterName: The name to use for URL session tracking
|
||||
resetStats(): Reset statistics
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,131 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import org.eclipse.jetty.util.RunningStats;
|
||||
import org.eclipse.jetty.util.SimpleStats;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* ServerStats
|
||||
*
|
||||
* Aggregates classes that computes statistic values
|
||||
*/
|
||||
public class ServerStats
|
||||
{
|
||||
private ServerStats() {}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* CounterStats
|
||||
*
|
||||
* Computes statistic values for counter variables
|
||||
*/
|
||||
public static class CounterStats
|
||||
extends SimpleStats
|
||||
{
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Construct the request statistics object
|
||||
*/
|
||||
public CounterStats()
|
||||
{
|
||||
super(true, true, false, true); // track current, total, and max
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.util.SimpleStats#set(long)
|
||||
*/
|
||||
@Override
|
||||
public void set(long value)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* MeasuredStats
|
||||
*
|
||||
* Computes statistic values for measured variables
|
||||
*/
|
||||
public static class MeasuredStats
|
||||
extends SimpleStats
|
||||
{
|
||||
private final RunningStats _stats = new RunningStats();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Construct the request statistics object
|
||||
*/
|
||||
public MeasuredStats()
|
||||
{
|
||||
super(false, true, false, true); // track total and max only
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.util.SimpleStats#reset()
|
||||
*/
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
super.reset();
|
||||
_stats.reset();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.util.SimpleStats#set(long)
|
||||
*/
|
||||
@Override
|
||||
public void set(long value)
|
||||
{
|
||||
super.set(value);
|
||||
_stats.update(value);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.util.SimpleStats#add(long)
|
||||
*/
|
||||
@Override
|
||||
public void add(long delta)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return mean value of requests per connection
|
||||
*/
|
||||
public double getMean()
|
||||
{
|
||||
return _stats.getMean();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return standard deviation of requests per connection
|
||||
*/
|
||||
public double getStdDev()
|
||||
{
|
||||
return _stats.getStdDev();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -948,7 +948,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
final int s=LazyList.size(_requestListeners);
|
||||
final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
|
||||
for(int i=0;i<s;i++)
|
||||
((ServletRequestListener)LazyList.get(_requestListeners,i)).requestInitialized(sre);
|
||||
((ServletRequestListener)LazyList.get(_requestListeners,i)).requestDestroyed(sre);
|
||||
}
|
||||
|
||||
if (_requestAttributeListeners!=null)
|
||||
|
|
|
@ -26,18 +26,18 @@ import org.eclipse.jetty.continuation.ContinuationListener;
|
|||
import org.eclipse.jetty.server.AsyncContinuation;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Response;
|
||||
import org.eclipse.jetty.server.ServerStats.CounterStats;
|
||||
import org.eclipse.jetty.server.ServerStats.MeasuredStats;
|
||||
import org.eclipse.jetty.util.statistic.SampleStatistic;
|
||||
import org.eclipse.jetty.util.statistic.CounterStatistic;
|
||||
|
||||
public class StatisticsHandler extends HandlerWrapper
|
||||
{
|
||||
private final AtomicLong _statsStartedAt = new AtomicLong();
|
||||
|
||||
private final CounterStats _requestStats = new CounterStats();
|
||||
private final MeasuredStats _requestTimeStats = new MeasuredStats();
|
||||
private final CounterStats _dispatchedStats = new CounterStats();
|
||||
private final MeasuredStats _dispatchedTimeStats = new MeasuredStats();
|
||||
private final CounterStats _suspendStats = new CounterStats();
|
||||
private final CounterStatistic _requestStats = new CounterStatistic();
|
||||
private final SampleStatistic _requestTimeStats = new SampleStatistic();
|
||||
private final CounterStatistic _dispatchedStats = new CounterStatistic();
|
||||
private final SampleStatistic _dispatchedTimeStats = new SampleStatistic();
|
||||
private final CounterStatistic _suspendStats = new CounterStatistic();
|
||||
|
||||
private final AtomicInteger _resumes = new AtomicInteger();
|
||||
private final AtomicInteger _expires = new AtomicInteger();
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import static java.lang.Math.round;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -40,6 +42,8 @@ import org.eclipse.jetty.server.SessionManager;
|
|||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.LazyList;
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.statistic.CounterStatistic;
|
||||
import org.eclipse.jetty.util.statistic.SampleStatistic;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -72,9 +76,6 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
protected int _dftMaxIdleSecs=-1;
|
||||
protected SessionHandler _sessionHandler;
|
||||
protected boolean _httpOnly=false;
|
||||
protected int _maxSessions=0;
|
||||
|
||||
protected int _minSessions=0;
|
||||
protected SessionIdManager _sessionIdManager;
|
||||
protected boolean _secureCookies=false;
|
||||
protected Object _sessionAttributeListeners;
|
||||
|
@ -91,6 +92,9 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
protected int _refreshCookieAge;
|
||||
protected boolean _nodeIdInSessionId;
|
||||
|
||||
protected final CounterStatistic _sessionsStats = new CounterStatistic();
|
||||
protected final SampleStatistic _sessionTimeStats = new SampleStatistic();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public AbstractSessionManager()
|
||||
{
|
||||
|
@ -265,11 +269,33 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
{
|
||||
return _dftMaxIdleSecs;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see getSessionsMax()
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMaxSessions()
|
||||
{
|
||||
return _maxSessions;
|
||||
return getSessionsMax();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return maximum number of sessions
|
||||
*/
|
||||
public int getSessionsMax()
|
||||
{
|
||||
return (int)_sessionsStats.getMax();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return total number of sessions
|
||||
*/
|
||||
public int getSessionsTotal()
|
||||
{
|
||||
return (int)_sessionsStats.getTotal();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -283,9 +309,13 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see getSessionsMin()
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMinSessions()
|
||||
{
|
||||
return _minSessions;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -357,7 +387,10 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public abstract int getSessions();
|
||||
public int getSessions()
|
||||
{
|
||||
return (int)_sessionsStats.getCurrent();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String getSessionIdPathParameterName()
|
||||
|
@ -421,12 +454,25 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
if (listener instanceof HttpSessionListener)
|
||||
_sessionListeners=LazyList.remove(_sessionListeners,listener);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see statsReset()
|
||||
*/
|
||||
@Deprecated
|
||||
public void resetStats()
|
||||
{
|
||||
_minSessions=getSessions();
|
||||
_maxSessions=getSessions();
|
||||
statsReset();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Reset statistics values
|
||||
*/
|
||||
public void statsReset()
|
||||
{
|
||||
_sessionsStats.reset(getSessions());
|
||||
_sessionTimeStats.reset();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -554,26 +600,28 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
synchronized (this)
|
||||
{
|
||||
addSession(session);
|
||||
if (getSessions()>this._maxSessions)
|
||||
this._maxSessions=getSessions();
|
||||
}
|
||||
}
|
||||
|
||||
if (!created)
|
||||
if (created)
|
||||
{
|
||||
_sessionsStats.increment();
|
||||
if (_sessionListeners!=null)
|
||||
{
|
||||
HttpSessionEvent event=new HttpSessionEvent(session);
|
||||
for (int i=0; i<LazyList.size(_sessionListeners); i++)
|
||||
((HttpSessionListener)LazyList.get(_sessionListeners,i)).sessionCreated(event);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
session.didActivate();
|
||||
}
|
||||
else if (_sessionListeners!=null)
|
||||
{
|
||||
HttpSessionEvent event=new HttpSessionEvent(session);
|
||||
for (int i=0; i<LazyList.size(_sessionListeners); i++)
|
||||
((HttpSessionListener)LazyList.get(_sessionListeners,i)).sessionCreated(event);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Get a known existingsession
|
||||
* Get a known existing session
|
||||
* @param idInCluster The session ID in the cluster, stripped of any worker name.
|
||||
* @return A Session or null if none exists.
|
||||
*/
|
||||
|
@ -642,9 +690,12 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
removeSession(session.getClusterId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (removed)
|
||||
{
|
||||
_sessionsStats.decrement();
|
||||
_sessionTimeStats.set(round((System.currentTimeMillis() - session.getCreationTime())/1000.0));
|
||||
|
||||
// Remove session from all context and global id maps
|
||||
_sessionIdManager.removeSession(session);
|
||||
if (invalidate)
|
||||
|
@ -666,6 +717,42 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected abstract void removeSession(String idInCluster);
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return maximum amount of time session remained valid
|
||||
*/
|
||||
public long getSessionTimeMax()
|
||||
{
|
||||
return _sessionTimeStats.getMax();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return total amount of time all sessions remained valid
|
||||
*/
|
||||
public long getSessionTimeTotal()
|
||||
{
|
||||
return _sessionTimeStats.getTotal();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return mean amount of time session remained valid
|
||||
*/
|
||||
public double getSessionTimeMean()
|
||||
{
|
||||
return _sessionTimeStats.getMean();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return standard deviation of amount of time session remained valid
|
||||
*/
|
||||
public double getSessionTimeStdDev()
|
||||
{
|
||||
return _sessionTimeStats.getStdDev();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
|
|
@ -139,7 +139,13 @@ public class HashSessionManager extends AbstractSessionManager
|
|||
@Override
|
||||
public int getSessions()
|
||||
{
|
||||
return _sessions.size();
|
||||
int sessions=super.getSessions();
|
||||
if (Log.isDebugEnabled())
|
||||
{
|
||||
if (_sessions.size()!=sessions)
|
||||
Log.warn("sessions: "+_sessions.size()+"!="+sessions);
|
||||
}
|
||||
return sessions;
|
||||
}
|
||||
|
||||
|
||||
|
@ -294,9 +300,6 @@ public class HashSessionManager extends AbstractSessionManager
|
|||
if (idleTime>0&&session._accessed+idleTime<System.currentTimeMillis())
|
||||
{
|
||||
session.timeout();
|
||||
int nbsess=this._sessions.size();
|
||||
if (nbsess<this._minSessions)
|
||||
this._minSessions=nbsess;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -429,7 +432,7 @@ public class HashSessionManager extends AbstractSessionManager
|
|||
}
|
||||
}
|
||||
|
||||
_sessionsLoaded = true;
|
||||
_sessionsLoaded = true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -769,9 +769,6 @@ public class JDBCSessionManager extends AbstractSessionManager
|
|||
{
|
||||
session.timeout();
|
||||
itor.remove();
|
||||
int count = this._sessions.size();
|
||||
if (count < this._minSessions)
|
||||
this._minSessions=count;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* StatsEstimator
|
||||
*
|
||||
* Calculates estimates of mean, variance, and standard deviation
|
||||
* characteristics of a sample using on-line algorithm presented
|
||||
* in Donald Knuth's Art of Computer Programming, Volume 2,
|
||||
* Seminumerical Algorithms, 3rd edition, page 232,
|
||||
* Boston: Addison-Wesley. that cites a 1962 paper by B.P. Welford
|
||||
* that can be found by following the link below.
|
||||
*
|
||||
* http://www.jstor.org/pss/1266577
|
||||
*
|
||||
* This algorithm can be found in Wikipedia article about computing
|
||||
* standard deviation found by following the link below.
|
||||
*
|
||||
* http://en.wikipedia.org/w/index.php?title=Algorithms_for_calculating_variance§ion=4#On-line_algorithm
|
||||
*/
|
||||
public class RunningStats
|
||||
{
|
||||
private volatile long _size;
|
||||
private volatile double _mean;
|
||||
private volatile double _rsum;
|
||||
|
||||
public synchronized void reset()
|
||||
{
|
||||
_size = 0;
|
||||
_mean = 0.0;
|
||||
_rsum = 0.0;
|
||||
}
|
||||
|
||||
public synchronized void update(final double x)
|
||||
{
|
||||
double mean = _mean;
|
||||
_mean += (x - mean) / ++_size;
|
||||
_rsum += (x - mean) * (x - _mean);
|
||||
}
|
||||
|
||||
public long getSize()
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
public double getMean()
|
||||
{
|
||||
return _mean;
|
||||
}
|
||||
|
||||
public synchronized double getVariance()
|
||||
{
|
||||
return _size > 1 ? _rsum/(_size-1) : 0.0;
|
||||
}
|
||||
|
||||
public synchronized double getStdDev()
|
||||
{
|
||||
return Math.sqrt(getVariance());
|
||||
}
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*/
|
||||
public class SimpleStats
|
||||
{
|
||||
private final AtomicLong _curr;
|
||||
private final AtomicLong _total;
|
||||
private final AtomicLong _min;
|
||||
private final AtomicLong _max;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*/
|
||||
public SimpleStats()
|
||||
{
|
||||
this(true, true, true, true);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param curr
|
||||
* @param total
|
||||
* @param min
|
||||
* @param max
|
||||
*/
|
||||
public SimpleStats(boolean curr, boolean total, boolean min, boolean max)
|
||||
{
|
||||
_curr = new AtomicLong(curr ? 0 : -1);
|
||||
_total = new AtomicLong(total ? 0 : -1);
|
||||
_min = new AtomicLong(min ? 0 : -1);
|
||||
_max = new AtomicLong(max ? 0 : -1);
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
if (_curr.get() != -1)
|
||||
_curr.set(0);
|
||||
|
||||
if (_total.get() != -1)
|
||||
_total.set(0);
|
||||
|
||||
if (_min.get() != -1)
|
||||
_min.set(0);
|
||||
|
||||
if (_max.get() != -1)
|
||||
_max.set(0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
public void set(final long value)
|
||||
{
|
||||
if (_curr.get() != -1)
|
||||
_curr.set(value);
|
||||
|
||||
if (_total.get() != -1)
|
||||
_total.addAndGet(value);
|
||||
|
||||
if (_min.get() != -1)
|
||||
updateMin(value);
|
||||
|
||||
if (_max.get() != -1)
|
||||
updateMax(value);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param delta
|
||||
*/
|
||||
public void add(final long delta)
|
||||
{
|
||||
if (_curr.get() != -1)
|
||||
{
|
||||
long curr = _curr.addAndGet(delta);
|
||||
|
||||
if (_min.get() != -1)
|
||||
updateMin(curr);
|
||||
|
||||
if (_max.get() != -1)
|
||||
updateMax(curr);
|
||||
}
|
||||
|
||||
if (_total.get() != -1 && delta < 0)
|
||||
_total.addAndGet(abs(delta));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*/
|
||||
public void increment()
|
||||
{
|
||||
add(1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*/
|
||||
public void decrement()
|
||||
{
|
||||
add(-1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getCurrent()
|
||||
{
|
||||
return _curr.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getTotal()
|
||||
{
|
||||
return _total.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getMax()
|
||||
{
|
||||
return _max.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getMin()
|
||||
{
|
||||
return _min.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
private void updateMin(long value)
|
||||
{
|
||||
long oldValue = _min.get();
|
||||
while (value < oldValue)
|
||||
{
|
||||
if (_min.compareAndSet(oldValue, value))
|
||||
break;
|
||||
oldValue = _min.get();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
private void updateMax(long value)
|
||||
{
|
||||
long oldValue = _max.get();
|
||||
while (value > oldValue)
|
||||
{
|
||||
if (_max.compareAndSet(oldValue, value))
|
||||
break;
|
||||
oldValue = _max.get();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.util.statistic;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Statistics on a counter value.
|
||||
* <p>
|
||||
* Keep total, current and maximum values of a counter that
|
||||
* can be incremented and decremented. The total refers only
|
||||
* to increments.
|
||||
*
|
||||
*/
|
||||
public class CounterStatistic
|
||||
{
|
||||
protected final AtomicLong _max = new AtomicLong();
|
||||
protected final AtomicLong _curr = new AtomicLong();
|
||||
protected final AtomicLong _total = new AtomicLong();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void reset()
|
||||
{
|
||||
reset(0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void reset(final long value)
|
||||
{
|
||||
_max.set(value);
|
||||
_curr.set(value);
|
||||
_total.set(0); // total always set to 0 to properly calculate cumulative total
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param delta
|
||||
*/
|
||||
public void add(final long delta)
|
||||
{
|
||||
updateMax(_curr.addAndGet(delta));
|
||||
if (delta > 0)
|
||||
_total.addAndGet(delta);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param delta
|
||||
*/
|
||||
public void subtract(final long delta)
|
||||
{
|
||||
add(-delta);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*/
|
||||
public void increment()
|
||||
{
|
||||
add(1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*/
|
||||
public void decrement()
|
||||
{
|
||||
add(-1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getMax()
|
||||
{
|
||||
return _max.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getCurrent()
|
||||
{
|
||||
return _curr.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getTotal()
|
||||
{
|
||||
return _total.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void updateMax(long value)
|
||||
{
|
||||
long oldValue = _max.get();
|
||||
while (value > oldValue)
|
||||
{
|
||||
if (_max.compareAndSet(oldValue, value))
|
||||
break;
|
||||
oldValue = _max.get();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.util.statistic;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* SampledStatistics
|
||||
* <p>
|
||||
* Provides max, total, mean, count, variance, and standard
|
||||
* deviation of continuous sequence of samples.
|
||||
* <p>
|
||||
* Calculates estimates of mean, variance, and standard deviation
|
||||
* characteristics of a sample using a non synchronised
|
||||
* approximation of the on-line algorithm presented
|
||||
* in Donald Knuth's Art of Computer Programming, Volume 2,
|
||||
* Seminumerical Algorithms, 3rd edition, page 232,
|
||||
* Boston: Addison-Wesley. that cites a 1962 paper by B.P. Welford
|
||||
* that can be found by following the link http://www.jstor.org/pss/1266577
|
||||
* <p>
|
||||
* This algorithm is also described in Wikipedia at
|
||||
* http://en.wikipedia.org/w/index.php?title=Algorithms_for_calculating_variance§ion=4#On-line_algorithm
|
||||
*/
|
||||
public class SampleStatistic
|
||||
{
|
||||
protected final AtomicLong _max = new AtomicLong();
|
||||
protected final AtomicLong _total = new AtomicLong();
|
||||
protected final AtomicLong _count = new AtomicLong();
|
||||
protected final AtomicLong _totalVariance100 = new AtomicLong();
|
||||
|
||||
public void reset()
|
||||
{
|
||||
_max.set(0);
|
||||
_total.set(0);
|
||||
_count.set(0);
|
||||
_totalVariance100.set(0);
|
||||
}
|
||||
|
||||
public void set(final long sample)
|
||||
{
|
||||
long oldMax = _max.get();
|
||||
while (sample > oldMax)
|
||||
{
|
||||
if (_max.compareAndSet(oldMax, sample))
|
||||
break;
|
||||
oldMax = _max.get();
|
||||
}
|
||||
|
||||
long total = _total.addAndGet(sample);
|
||||
long count = _count.incrementAndGet();
|
||||
|
||||
if (count>1)
|
||||
{
|
||||
long mean10 = total*10/count;
|
||||
long delta10 = sample*10 - mean10;
|
||||
_totalVariance100.addAndGet(delta10*delta10);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getMax()
|
||||
{
|
||||
return _max.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public long getTotal()
|
||||
{
|
||||
return _total.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public long getCount()
|
||||
{
|
||||
return _count.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public double getMean()
|
||||
{
|
||||
return (double)_total.get()/_count.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public double getVariance()
|
||||
{
|
||||
final long variance100 = _totalVariance100.get();
|
||||
final long count = _count.get();
|
||||
|
||||
return count>1?((double)variance100)/100.0/(count-1):0.0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public double getStdDev()
|
||||
{
|
||||
return Math.sqrt(getVariance());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package org.eclipse.jetty.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Test data and results used in this test are from National Institute
|
||||
* of Standards and Technology Information Technology Laboratory study.
|
||||
*
|
||||
* http://www.itl.nist.gov/div898/handbook/eda/section3/eda359.htm
|
||||
*/
|
||||
public class RunningStatsTest extends TestCase
|
||||
{
|
||||
private static double[] data1 = {608.781,689.556,618.134,680.203,726.232,518.655,740.447,666.830,710.272,751.669,697.979,708.583,624.972,695.070,769.391,720.186,723.657,703.700,697.626,714.980,657.712,609.989,650.771,707.977,712.199,709.631,703.160,744.822,719.217,619.137,753.333,677.933,735.919,695.274,504.167,693.333,625.000,596.667,640.898,720.506,700.748,691.604,636.738,731.667,635.079,716.926,759.581,673.903,736.648,675.957,729.230,697.239,728.499,797.662,668.530,815.754,777.392,712.140,663.622,684.181,629.012,640.193,644.156,642.469,639.090,439.418,614.664,537.161,656.773,659.534,695.278,734.040,687.665,710.858,701.716,382.133,719.744,756.820,690.978,670.864,670.308,660.062,790.382,714.750,716.959,603.363,713.796,444.963,723.276,745.527,778.333,723.349,708.229,681.667,566.085,687.448,597.500,637.410,755.864,692.945,766.532,725.663,698.818,760.000,775.272,708.885,727.201,642.560,690.773,688.333,743.973,682.461,761.430,691.542,643.392,697.075,708.229,746.467,744.819,655.029,715.224,614.417,761.363,716.106,659.502,730.781,546.928,734.203,682.051,701.341,759.729,689.942,769.424,715.286,776.197,547.099,619.942,696.046,573.109,638.794,708.193,502.825,632.633,683.382,684.812,738.161,671.492,709.771,685.199,624.973,757.363,633.417,658.754,664.666,663.009,773.226,708.261,739.086,667.786,674.481,695.688,588.288,545.610,752.305,684.523,717.159,721.343,750.623,776.488,750.623,600.840,686.196,687.870,725.527,658.796,690.380,737.144,663.851,766.630,625.922,694.430,730.217,700.770,722.242,763.828,695.668,688.887,531.021,698.915,735.905,732.039,751.832,618.663,744.845,690.826,666.893,759.860,683.752,729.591,730.706,763.124,724.193,630.352,750.338,752.417,707.899,715.582,728.746,591.193,592.252,740.833,786.367,712.386,738.333,741.480,729.167,795.833,723.502,718.333,768.080,747.500,775.000,760.599,758.333,682.500,658.116,738.213,681.236,704.904,693.623,624.993,700.228,611.874,579.167,720.872,690.320,677.933,674.600,611.999,530.680};
|
||||
private static double[] data2 = {569.670,747.541,612.182,607.766,605.380,589.226,588.375,531.384,633.417,619.060,632.447,624.256,575.143,549.278,624.972,587.695,569.207,613.257,565.737,662.131,543.177,512.394,611.190,659.982,569.245,725.792,608.960,586.060,617.441,592.845,631.754,588.113,555.724,702.411,631.754,698.254,616.791,551.953,636.738,571.551,521.667,587.451,700.422,595.819,534.236,606.188,575.303,590.628,729.314,619.313,624.234,651.304,724.175,583.034,620.227,584.861,565.391,622.506,628.336,587.145,584.319,538.239,538.097,595.686,648.935,583.827,534.905,569.858,617.246,610.337,584.192,598.853,554.774,605.694,627.516,574.522,582.682,563.872,715.962,616.430,778.011,604.255,571.906,625.925,682.426,707.604,617.400,689.576,676.678,563.290,581.879,447.701,557.772,593.537,632.585,671.350,569.530,581.667,643.449,581.593,494.122,620.948,615.903,606.667,579.167,662.510,436.237,644.223,586.035,620.833,652.535,593.516,587.451,570.964,645.192,540.079,707.117,621.779,585.777,703.980,698.237,757.120,621.751,472.125,612.700,583.170,599.771,549.227,605.453,569.599,637.233,621.774,558.041,583.170,345.294,570.999,603.232,595.335,581.047,455.878,627.880,464.085,596.129,640.371,621.471,612.727,606.460,571.760,599.304,579.459,761.511,566.969,654.397,611.719,577.409,576.731,617.441,577.409,548.957,623.315,621.761,553.978,657.157,610.882,552.304,545.303,651.934,635.240,641.083,645.321,566.127,647.844,554.815,620.087,711.301,644.355,713.812,696.707,589.453,634.468,599.751,624.542,723.505,674.717,608.539,612.135,591.935,676.656,647.323,811.970,603.883,608.643,630.778,623.063,472.463,645.932,577.176,567.530,821.654,684.490,600.427,686.023,628.109,605.214,640.260,700.767,665.924,555.926,543.299,511.030,583.994,611.048,623.338,679.585,665.004,655.860,715.711,611.999,577.722,615.129,540.316,711.667,639.167,549.491,684.167,672.153,594.534,627.650,551.870,594.534,602.660,585.450,555.724,574.934,584.625,555.724,611.874,698.254,748.130,689.942};
|
||||
|
||||
public void testData1()
|
||||
throws Exception
|
||||
{
|
||||
RunningStats stats = new RunningStats();
|
||||
|
||||
for (double x : data1)
|
||||
stats.update(x);
|
||||
|
||||
assertEquals(data1.length, stats.getSize());
|
||||
assertEquals(688.9986, round(stats.getMean(), 4));
|
||||
assertEquals(4296.683, round(stats.getVariance(), 3));
|
||||
assertEquals(65.54909, round(stats.getStdDev(), 5));
|
||||
}
|
||||
|
||||
public void testData2()
|
||||
throws Exception
|
||||
{
|
||||
RunningStats stats = new RunningStats();
|
||||
|
||||
for (double x : data2)
|
||||
stats.update(x);
|
||||
|
||||
assertEquals(data2.length, stats.getSize());
|
||||
assertEquals(611.1560, round(stats.getMean(), 4));
|
||||
assertEquals(3825.948, round(stats.getVariance(), 3));
|
||||
assertEquals(61.85425, round(stats.getStdDev(), 5));
|
||||
}
|
||||
|
||||
private double round(double x, int places)
|
||||
{
|
||||
return Math.round(x * Math.pow(10.0, (double) places)) / Math.pow(10.0, (double) places);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package org.eclipse.jetty.util.statistic;
|
||||
|
||||
import org.eclipse.jetty.util.statistic.SampleStatistic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public class SampleStatisticTest extends TestCase
|
||||
{
|
||||
private static long[][] data =
|
||||
{
|
||||
{100,100,100,100,100,100,100,100,100,100},
|
||||
{100,100,100,100,100,100,100,100,100,100,90,110},
|
||||
{100,100,100,100,100,100,100,100,90,110,95,105,97,103},
|
||||
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,90,110,95,105,97,103},
|
||||
};
|
||||
|
||||
private static double[][] results =
|
||||
{ /* {mean,stddev}*/
|
||||
{100.0,0.0},
|
||||
{100.0,Math.sqrt((10*10+10*10)/12.0)},
|
||||
{100.0,Math.sqrt((10*10+10*10+5*5+5*5+3*3+3*3)/14.0)},
|
||||
{100.0,Math.sqrt((10*10+10*10+5*5+5*5+3*3+3*3)/24.0)},
|
||||
{100.0,Math.sqrt((10*10+10*10+5*5+5*5+3*3+3*3)/104.0)}
|
||||
};
|
||||
|
||||
|
||||
public void testData()
|
||||
throws Exception
|
||||
{
|
||||
SampleStatistic stats = new SampleStatistic();
|
||||
for (int d=0;d<data.length;d++)
|
||||
{
|
||||
stats.reset();
|
||||
for (long x : data[d])
|
||||
stats.set(x);
|
||||
|
||||
assertEquals("count"+d,data[d].length, (int)stats.getCount());
|
||||
assertNearEnough("mean"+d,results[d][0], stats.getMean());
|
||||
assertNearEnough("stddev"+d,results[d][1], stats.getStdDev());
|
||||
}
|
||||
}
|
||||
|
||||
private void assertNearEnough(String test,double expected, double actual)
|
||||
{
|
||||
double diff = Math.abs(expected-actual);
|
||||
if (diff<0.1)
|
||||
{
|
||||
System.out.println("Near enough "+test+" diff="+diff);
|
||||
return;
|
||||
}
|
||||
String failed = "Not near enough "+test+" expected="+expected+" actual="+actual+" diff="+diff;
|
||||
System.err.println(failed);
|
||||
assertTrue(failed,false);
|
||||
}
|
||||
|
||||
}
|
|
@ -98,7 +98,6 @@ public class TestListener implements HttpSessionListener, HttpSessionAttributeL
|
|||
|
||||
public void requestInitialized(ServletRequestEvent sre)
|
||||
{
|
||||
((HttpServletRequest)sre.getServletRequest()).getSession(true).getId();
|
||||
sre.getServletRequest().setAttribute("requestInitialized","'"+sre.getServletContext().getContextPath()+"'");
|
||||
// System.err.println("requestInitialized "+sre);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue