DataService-Specific
Best Practices
DataService
-Specific
Best PracticesFollowing these
recommendations and best practices for writing Data Service queries, helps you
improve the performance and scalability of your extensions.
- To increase the performance of your extension, you must avoid creating constraints, such asObjectIdentityConstraints,PropertyConstraints, andRelationalConstraints, and definingOrderingPropertySpecobjects that have multi-valued properties such as collections and arrays.For example, when you create aPropertyConstraintobject that filters allVirtualMachineobjects based on theirnetworkproperty, the filtering process is slowed down. This situation occurs because the back end Data Provider does not support such requests. In such cases, the Data Service fetches the entire data set and then filters the received data.
- To improve the performance of your extension, you must avoid creating constraints and definingOrderingPropertySpecobjects by using the length of multi-valued properties such as collections and arrays.For example, when you create aPropertyConstraintobject that filters query results by using the propertynetwork._lengthfor allVirtualMachineobjects, the filtering process is slowed down. This situation occurs because the back end Data Provider does not support such requests or does not maintain a separate index for property length. In such cases, the Data Service fetches the entire data set and then proceeds with filtering the received data.
- To improve the performance of your extensions, you can useQuerySpec.resultSpec.maxResultCountfield to limit the returned result set.
- To improve the performance of your extensions in case you usePropertyConstraints, you must use thecom.vmware.vise.data.query.Comparator.EQUALScomparator instead of a text-matching comparator such ascom.vmware.vise.data.query.Comparator.CONTAINSandcom.vmware.vise.data.query.Comparator.TEXTUALLY_MATCHESfor thePropertyConstraintqueries. Text-matching operations require a specific database indexing which only a few properties, such asname, have. If you need to use a text-matching comparator, you can useCONTAINSinstead ofTEXTUALLY_MATCHES, becauseTEXTUALLY_MATCHESrequires more complex processing.
- To improve the performance of your extensions, you can set a value to thetargetTypefield of eachcom.vmware.vise.data.PropertySpecandcom.vmware.vise.data.query.OrderingPropertySpecobject. The Data Service uses thetargetTypefield to optimize the performance of the queries.
- To avoid future compatibility issues with your extension, you must avoid using multi-valued properties, such as collections and arrays, as the middle nodes in the property paths.For example, you must not use the property pathconfigurationEx.drsVmConfig.keyforClusterComputeResourceobjects because thedrsVmConfigproperty of thevim.cluster.ConfigInfoExdata object is a collection. In this case, you must request the wholevim.cluster.ConfigInfoExdata object.
- To avoid future compatibility issues with your extension, you must not use any custom properties defined by thevSphere Clientmodules. These properties are prone to change in the future. You must use only the properties defined in the vSphere Web Services API for the managed objects and data objects.
- To avoid future compatibility issues with your extension, you must avoid using thecom.vmware.vise.data.query.Conjoiner.EXCEPToperator in yourCompositeConstraints. Instead you must use negation and De Morgan's laws.
- To avoid future incompatibility, avoid using therelationfield of thecom.vmware.vise.data.PropertySpecobjects.
- To avoid future incompatibility, avoid using thefacetsfield of thecom.vmware.vise.data.query.ResultSpecobjects.
- The Data Service uses the value of thetargetTypefield to optimize query run time. To improve the performance of your extensions, set thetargetTypefield on every constraint except for the following cases:
- com.vmware.vise.data.query.ObjectIdentityConstraint- You must not specify thetargetTypefield because the type is already present in the object reference. You can set the type by using thetargetfield of theObjectIdentityConstraintclass.
- com.vmware.vise.data.query.RelationalConstraintwithhasInverseRelationfield set to true - ThetargetTypefield is ignored for such constraints.
- To avoid performance issues with your extension in case you use constraints, you must use a specific managed object type as a value for thetargetTypefield. For example, if you use an abstract base type such as theManagedEntitymanaged object type, the speed of the query is slowed down.
- To ease the future optimization of your extensions, you must limit the size of eachCompositeConstraintby limiting the number of child constraints in thenestedConstraintsfield of theCompositeConstraintclass, and you must avoid also nesting multipleCompositeConstraint.
- Make sure that your Data Provider Adapter takes less than 3 seconds to process a query. If your adapter takes too long to process a request, the Data Service cuts the adapter from the result.