Interviewer - Server > Monitoring and tuning system performance > Load balancing interviewing engines > Default UNICOM Intelligence Interviewer load balancing script
 
Default UNICOM Intelligence Interviewer load balancing script
The default load balancing script has been designed to balance memory use across a cluster. This topic is an overview of how the script works, and describes some of the ways in which it can be customized.
The load balancing distribution between the interviewing engines within a cluster is determined by the Percent Loaded counter on each engine in the cluster. The load balancing algorithm uses Percent Loaded to try to ensure that the load on the interviewing engines is even. For example, if there are two interviewing servers in a cluster and Percent Loaded is 70 on one engine (server) and 50 on the second, no more interviews will be allowed to start on the first engine; they will all be allocated to the second engine instead. This continues until PercentLoaded is 60 for both engines.
The default load script is called defaultload.mrs. It is in the Server folder of the UNICOM Intelligence Interviewer installation folder. Before changing anything in the script, read the comments in it carefully.
Limits in the load script
Limit imposed on
Limit set
Working set
1200Mb (1.2 Gb). This is based on Microsoft performance tuning guidelines; alternatively set it to 60% of physical memory.
Virtual address space
1.9Gb for cached projects and 1.7Gb for uncached projects. This limit is set to safeguard the engine. Once hit, no further new interviews can be run on that engine.
Number of interviews started
This value is obtained from the Engine.StartPerSecLimit registry setting. If a value is not specified for the registry setting, the default value is 5 per second.
Completed interviews
100 per second.
Errors
30 per second
These connection limits can be changed in the registry in:
HKEY_LOCAL_MACHINE\Software\SPSS\mrInterview\3\LoadBalancing
At a high level, the default load script does the following:
Checks the connection limits. If any are exceeded, Percent Loaded is reported as 100%.
Percent Loaded is then taken from the larger of Memory Usage and Concurrent Interviews.
If the project for the new interview is cached, the percent loaded is reduced for project affinity to an engine.
Finally, the available virtual address space is checked.
The default load script has the following limitations:
It does not take CPU usage into account when calculating percent loaded. For example, if you have a project with processor intensive routing logic, the server running this project may become overloaded, but will still have sufficient memory to take additional interviews.
If you are running other applications on the server, total available memory and total CPU time are not considered. You may be able to get round this problem by artificially increasing Percent Loaded for servers that are running other applications, or by creating fewer engines.
Default load balancing script in 64-bit environments
The script should execute as a single flow of execution and populate the PercentLoaded variable with a value:
PercentLoaded value
Description
0
The engine always accepts the interview
> 0 and < 100
The engine with the lowest PercentLoaded value is assigned the interview
100
The engine does not accept the interview
To use project affinity (that is, the ability to favour running interviews on an engine that has the project cached), set the CachedProjectWeight registry value (REG_DWORD) to a percentage weighting. The default value is 50%, which reduces the percent loaded value by 50% if the project is already cached on the interviewing engine. For Telephone Interviewing, the use of project affinity is hard‑coded in the default load balancing script.
Registry values are set under the following key:
SOFTWARE\SPSS\mrInterview\3.0\LoadBalancing
After this script has been modified the services on the web and engine servers need to be restarted.
Dim ConcurrentInterviewsLimit, ConcurrentInterviewersLimit
Dim IsProjectCached, IsTelephone

If (Engine.IsCachedInterview(ProjectName, InterviewProperties)) Then
' This engine is already running the requested interview. Return PercentLoaded=0
' to cause the CreateInterviewWithAuthentication request to go to this engine.
PercentLoaded = 0
Exit
End If

' The max number of concurrent interviews per engine
ConcurrentInterviewsLimit = Engine.ConnectionLimit

' The max interviewers for each engine, based on the max interviews limit
ConcurrentInterviewersLimit = ConcurrentInterviewsLimit / 5

' 1 . Check the limits are not exceeded
If ((Engine.StartsPerSec + Engine.RestartsPerSec) > Engine.StartsPerSecLimit) or _
((Engine.CompletesPerSec + Engine.TimeoutsPerSec) > Engine.CompletesPerSecLimit) or _
(Engine.ErrorsPerSec > Engine.ErrorsPerSecLimit) or _
(Engine.CurrentInterviews >= ConcurrentInterviewsLimit) or _
(Engine.CurrentInterviewers >= ConcurrentInterviewersLimit) Then
' Either the Startup, Completes, ErrorsPerSec, Current interviews or Current interviewers limit has been reached.
' Set percent loaded to 100 to refuse to accept the interview or interviewer
PercentLoaded = 100
Exit
End If

' If the project name is not set, PercentLoaded is being called for the engine status reports
If Len(ProjectName) = 0 Then
' Return percent loaded based on the concurrent interviews/interviewer limits
PercentLoaded = MaxOf(Engine.CurrentInterviewers * 100 / ConcurrentInterviewersLimit, Engine.CurrentInterviews * 100 / ConcurrentInterviewsLimit)
Exit
End If

' 2. Check to see if the project is cached or should be cached on this engine
' TODO - this is where custom checks for whether the project should run on this engine should occur
IsProjectCached = Engine.IsCachedProject(ProjectName)

' 3. Calculate percent loaded for Web or Telephone
' Determine whether the PercentLoaded call is for Telephone or Web
Dim InterviewerID
Set InterviewerID = FindItem(InterviewProperties, "InterviewerID")
IsTelephone = (Not IsNullObject(InterviewerID))

If IsTelephone Then
' For *Telephone*, always connect to the engine that has the project cached,
' otherwise base percent loaded on the number of Interviewers connected to the engine
If IsProjectCached Then
PercentLoaded = 0
Else
PercentLoaded = (Engine.CurrentInterviewers * 100 / ConcurrentInterviewersLimit)

' Return percent loaded as at least 1% so project affinity takes priority
If PercentLoaded = 0 Then PercentLoaded = 1
End If
Else
' For *Web*, base percent loaded on the number of concurrent interviews,
' reducing percent loaded if the project is cached
PercentLoaded = (Engine.CurrentInterviews * 100 / ConcurrentInterviewsLimit)
If IsProjectCached Then
PercentLoaded = PercentLoaded - (Engine.CachedProjectWeight * 100)
If (PercentLoaded < 0) Then PercentLoaded = 0
' Return percent loaded of 1 so the IsCachedInterview case takes priority
PercentLoaded = 1
End If
End If
See also
Load balancing interviewing engines