|
Author: adrianc
Date: Sun Jul 15 16:11:44 2012 New Revision: 1361727 URL: http://svn.apache.org/viewvc?rev=1361727&view=rev Log: New feature - performance metrics. Web application integration. Modified: ofbiz/trunk/framework/webapp/dtd/site-conf.xsd ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Modified: ofbiz/trunk/framework/webapp/dtd/site-conf.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd?rev=1361727&r1=1361726&r2=1361727&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/dtd/site-conf.xsd (original) +++ ofbiz/trunk/framework/webapp/dtd/site-conf.xsd Sun Jul 15 16:11:44 2012 @@ -189,6 +189,7 @@ under the License. <xs:sequence> <xs:element minOccurs="0" ref="description"/> <xs:element minOccurs="0" ref="security"/> + <xs:element minOccurs="0" ref="metric"/> <xs:element minOccurs="0" ref="event"/> <xs:element maxOccurs="unbounded" ref="response"/> </xs:sequence> @@ -336,6 +337,60 @@ under the License. </xs:simpleType> </xs:attribute> </xs:attributeGroup> + <xs:element name="metric"> + <xs:annotation> + <xs:documentation> + Calculate and maintain an average response time for this request. Request metrics can be used + for monitoring and reporting. Metrics can also be used to trigger an alternate + response if the optional threshold attribute is used. + <br/><br/> + The metric works by gathering statistics until a configurable maximum is reached (number of + requests or elapsed time), then the average is calculated. A smoothing factor is used to + smooth differences between calculations. + </xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:attribute name="name" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation> + Each metric must have a unique name. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="estimation-size" type="xs:string"> + <xs:annotation> + <xs:documentation> + Positive integer number of requests to include in the metrics calculation. Defaults to "100". + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="estimation-time" type="xs:string"> + <xs:annotation> + <xs:documentation> + Positive integer number of milliseconds to include in the metrics calculation. Defaults to "1000". + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="smoothing" type="xs:string"> + <xs:annotation> + <xs:documentation> + Positive decimal smoothing factor - used to smooth the differences between calculations. A value of "1" disables smoothing. Defaults to "0.7". + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="threshold" type="xs:string"> + <xs:annotation> + <xs:documentation> + The metric threshold in milliseconds. If the average response time exceeds this setting, + then a "threshold-exceeded" response code will be generated. That response code can be used + in a response element. The threshold check will ignore the first three requests - to give + the metric a chance to stablize after startup. A value of "0.0" disables the threshold. + Defaults to "0.0". + </xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + </xs:element> <xs:element name="event"> <xs:annotation> <xs:documentation> Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?rev=1361727&r1=1361726&r2=1361727&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java Sun Jul 15 16:11:44 2012 @@ -33,6 +33,8 @@ import javolution.util.FastMap; import javolution.util.FastSet; import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.metrics.Metrics; +import org.ofbiz.base.metrics.MetricsFactory; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.FileUtil; import org.ofbiz.base.util.GeneralException; @@ -523,6 +525,7 @@ public class ConfigXMLReader { public boolean securityDirectRequest = true; public Map<String, RequestResponse> requestResponseMap = FastMap.newInstance(); + public Metrics metrics = null; public RequestMap(Element requestMapElement) { @@ -556,6 +559,11 @@ public class ConfigXMLReader { RequestResponse response = new RequestResponse(responseElement); requestResponseMap.put(response.name, response); } + // Get metrics. + Element metricsElement = UtilXml.firstChildElement(requestMapElement, "metric"); + if (metricsElement != null) { + this.metrics = MetricsFactory.getInstance(metricsElement); + } } } Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=1361727&r1=1361726&r2=1361727&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Sun Jul 15 16:11:44 2012 @@ -106,6 +106,7 @@ public class RequestHandler { public void doRequest(HttpServletRequest request, HttpServletResponse response, String chain, GenericValue userLogin, Delegator delegator) throws RequestHandlerException { + long startTime = System.currentTimeMillis(); HttpSession session = request.getSession(); // get the controllerConfig once for this method so we don't have to get it over and over inside the method @@ -155,8 +156,11 @@ public class RequestHandler { if (requestMap == null) { throw new RequestHandlerException(requestMissingErrorMessage); } - String eventReturn = null; + if (requestMap.metrics != null && requestMap.metrics.getThreshold() != 0.0 && requestMap.metrics.getTotalEvents() > 3 && requestMap.metrics.getThreshold() < requestMap.metrics.getServiceRate()) { + eventReturn = "threshold-exceeded"; + } + boolean interruptRequest = false; // Check for chained request. @@ -650,6 +654,9 @@ public class RequestHandler { if (Debug.verboseOn()) Debug.logVerbose("[RequestHandler.doRequest]: Response is handled by the event." + " sessionId=" + UtilHttp.getSessionId(request), module); } } + if (requestMap.metrics != null) { + requestMap.metrics.recordServiceRate(1, System.currentTimeMillis() - startTime); + } } /** Find the event handler and invoke an event. */ |
| Free forum by Nabble | Edit this page |
