Business logic is often written in a way that keeps a map of the metric’s resource structure for use during calculations. Since the resource structure changes over time, such business logic needs to update the structure in the map when the resource structure changes.
The OnRegistration method is called when the resource structure changes, as it is responsible for managing engine behavior that has to do with the changes in the registrations and clustering due to resource structure changes. The fact that this method is called for each resource structure change makes it is a convenient place to update the map mentioned above. However, filling the map is not relevant to the registration process. This means that filling the map detracts from the performance of the OnRegistration function. This is not important during runtime, as it normally does not happen very often. However, the OnRegistration method is also called during the infrastructure processing process of the engine, during which the system figures out whether resource structure changes are relevant to the registration of each specific metric the instance is responsible for. During this process, the OnRegistration method is called for every change in resource structure, even if the structure change is not relevant to the current metric. This means that the method may be called a large number of times per metric.
If such logic is implemented in the OnRegistration method, a small degradation in performance during runtime might become a very significant degradation in performance during infrastructure processing.
To solve this problem, filling maps or any other initialization that needs to be run when a change in resource structure occurs, but is not relevant to the registration, can be done in two ways:
Using the IsRunTimeMode property in the dispatcher object.
This property allows the user to find out if the current run is a calculation run or not, and to encase logic that is not relevant to the registration in an ‘if’ statement that will ensure that it will run only during runtime.
In the example below, the part marked in blue is the part of the business logic that is relevant to the registration and always needs to run. The part marked in green is not relevant to the registration and can be encased in the new ‘If’ statement.
Sub OnRegistration (dispatcher)
Dim MyResource
MyResource = Context.ClusterItem
Dispatcher.RegisterByResource “OnEvent”, “My Event Type”, MyResource
Dim ThisResourceMap
Set GlobalResourceVector= CreateObject("SlalomVector.Vector")
Dim resource
Set ThisResourceMap = Context.ResourcesOfResourceGroup(Context.ClusterItem)
For Each resource In ThisResourceMap
GlobalResourceVector.Add resource
Next
End Sub
This code can be improved by changing it in the following way:
Sub OnRegistration (dispatcher)
Dim MyResource
MyResource = Context.ClusterItem
Dispatcher.RegisterByResource “OnEvent”, “My Event Type”, MyResource
If Dispatcher.IsRunTimeMode Then
Dim ThisResourceMap
Set GlobalResourceVector= CreateObject("SlalomVector.Vector")
Dim resource
ThisResourceMap = Context.ResourcesOfResourceGroup(Context.ClusterItem)
For Each resource In ThisResourceMap
GlobalResourceVector.Add resource
Next
End If
End Sub
Using the OnResourceStructureChanged method.
This method runs right after the OnRegistration method and so gives the same functionality as the original methodology, but it only runs during runtime. This method is not called during infrastructure processing and thus, performance is not damaged.
In the example below, the part marked in blue is the part of the business logic that is relevant to the registration and need to stay in the OnRegistration method. The part marked in green is not relevant to the registration and can be placed in the new function.
Sub OnRegistration (dispatcher)
Dim MyResource
MyResource = Context.ClusterItem
Dispatcher.RegisterByResource “OnEvent”, “My Event Type”, MyResource
Dim ThisResourceMap
Set GlobalResourceVector= CreateObject("SlalomVector.Vector")
Dim resource
Set ThisResourceMap = Context.ResourcesOfResourceGroup(Context.ClusterItem)
For Each resource In ThisResourceMap
GlobalResourceVector.Add resource
Next
End Sub
This code can be improved by changing it in the following way:
Sub OnRegistration (dispatcher)
Dim MyResource
MyResource = Context.ClusterItem
Dispatcher.RegisterByResource “OnEvent”, “My Event Type”, MyResource
End Sub
Sub OnResourceStructureChanged(time)
Dim ThisResourceMap
Set GlobalResourceVector= CreateObject("SlalomVector.Vector")
Dim resource
Set ThisResourceMap = Context.ResourcesOfResourceGroup(Context.ClusterItem)
For Each resource In ThisResourceMap
GlobalResourceVector.Add resource
Next
End Sub
|
Copyright © 2013 CA.
All rights reserved.
|
|