Author: adrianc Date: Sun Jul 15 16:10:50 2012 New Revision: 1361725 URL: http://svn.apache.org/viewvc?rev=1361725&view=rev Log: New feature - performance metrics. Service engine integration.
Modified: ofbiz/trunk/framework/service/dtd/services.xsd ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Modified: ofbiz/trunk/framework/service/dtd/services.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/dtd/services.xsd?rev=1361725&r1=1361724&r2=1361725&view=diff ============================================================================== --- ofbiz/trunk/framework/service/dtd/services.xsd (original) +++ ofbiz/trunk/framework/service/dtd/services.xsd Sun Jul 15 16:10:50 2012 @@ -43,6 +43,7 @@ under the License. <xs:element minOccurs="0" maxOccurs="1" ref="permission-service"/> <xs:element minOccurs="0" maxOccurs="unbounded" ref="required-permissions"/> <xs:element minOccurs="0" maxOccurs="unbounded" ref="implements"/> + <xs:element minOccurs="0" ref="metric"/> <xs:choice maxOccurs="1" minOccurs="0"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="auto-attributes"/> @@ -260,6 +261,48 @@ under the License. </xs:attribute> </xs:attributeGroup> + <xs:element name="metric"> + <xs:annotation> + <xs:documentation> + Calculate and maintain an average response time for this service. Service metrics can be used + for monitoring and reporting. + <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:complexType> + </xs:element> <xs:element name="auto-attributes"> <xs:complexType> <xs:sequence> Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?rev=1361725&r1=1361724&r2=1361725&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Sun Jul 15 16:10:50 2012 @@ -59,6 +59,7 @@ import javax.xml.parsers.DocumentBuilder import javolution.util.FastList; import javolution.util.FastMap; +import org.ofbiz.base.metrics.Metrics; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.ObjectType; @@ -205,6 +206,11 @@ public class ModelService extends Abstra /** Flag to say if we have pulled in our addition parameters from our implemented service(s) */ protected boolean inheritedParameters = false; + /** + * Service metrics. + */ + public Metrics metrics = null; + public ModelService() {} public ModelService(ModelService model) { @@ -231,7 +237,7 @@ public class ModelService extends Abstra this.inheritedParameters = model.inheritedParameters(); this.internalGroup = model.internalGroup; this.hideResultInLog = model.hideResultInLog; - + this.metrics = model.metrics; List<ModelParam> modelParamList = model.getModelParamList(); for (ModelParam param: modelParamList) { this.addParamClone(param); Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java?rev=1361725&r1=1361724&r2=1361725&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java Sun Jul 15 16:10:50 2012 @@ -20,8 +20,6 @@ package org.ofbiz.service; import java.io.IOException; import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.URL; import java.util.Iterator; import java.util.LinkedHashMap; @@ -35,9 +33,9 @@ import javolution.util.FastMap; import org.ofbiz.base.config.GenericConfigException; import org.ofbiz.base.config.ResourceHandler; +import org.ofbiz.base.metrics.MetricsFactory; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; @@ -46,7 +44,6 @@ import org.ofbiz.entity.GenericEntityExc import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelField; import org.ofbiz.entity.model.ModelFieldType; -import org.ofbiz.service.engine.GenericEngine; import org.ofbiz.service.group.GroupModel; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -283,7 +280,11 @@ public class ModelServiceReader implemen this.createAutoAttrDefs(serviceElement, service); this.createAttrDefs(serviceElement, service); this.createOverrideDefs(serviceElement, service); - + // Get metrics. + Element metricsElement = UtilXml.firstChildElement(serviceElement, "metric"); + if (metricsElement != null) { + service.metrics = MetricsFactory.getInstance(metricsElement); + } return service; } Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1361725&r1=1361724&r2=1361725&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Sun Jul 15 16:10:50 2012 @@ -595,6 +595,9 @@ public class ServiceDispatcher { } Debug.logVerbose("Sync service [" + localName + "/" + modelService.name + "] finished with response [" + resultStr + "]", module); } + if (modelService.metrics != null) { + modelService.metrics.recordServiceRate(1, timeToRun); + } return result; }