Interviewer - Server > Monitoring and tuning system performance > Load balancing interviewing engines > Examples of UNICOM Intelligence Interviewer load balancing algorithms > Setting PercentLoaded based on memory usage or the number of concurrent interviews
 
Setting PercentLoaded based on memory usage or the number of concurrent interviews
This example bases the value of PercentLoaded on either memory usage or the number of interviews currently running, whichever is higher. If virtual memory is more than twice the size of normal memory usage, then PercentLoaded is set to memory usage+15. PercentLoaded is set to 100 if:
More than 60 interviews are running at the same time.
The computer is out of resources.
There are more than ten interviews starting per second.
There are more than 50 errors per second.
Dim totalSystemMemory, pctEngineMemory, pctInterviewLimit, concurrentLimit,
minPctOfFreeResources
 
' The following values can be set on a per machine basis
' Limit the number of concurrent interviews
concurrentLimit = 60
' Set a maximum value for min % free resources on machine
minPctOfFreeResources = 15
 
' Get amount of memory being used by the Interview Engine
pctEngineMemory = 100 * _
(0.5 * Process.MemoryUsage + Process.VirtualMemoryUsage)) _
/ System.TotalPhysical
 
' Get percentage of current interviews based on concurrent limit
pctInterviewLimit = (100 * Engine.CurrentInterviews) / concurrentLimit
 
' Set PercentLoaded ....
' ... 1. If too few resources on machine
If (pctEngineMemory > 100 - MinPctOfFreeResources) Then
PercentLoaded = 100
 
' ... 2. If concurrentLimit is reached
ElseIf (Engine.CurrentInterviews > concurrentLimit) Then
PercentLoaded = 100
 
' ... 3. If too many interviews are starting simultaneously
ElseIf (Engine.StartsPerSec > 10) Then
PercentLoaded = 100
 
' ... 4. If too many errors per second
ElseIf (Engine.ErrorsPerSec > 50) Then
PercentLoaded = 100
 
Else
If (pctInterviewLimit > pctEngineMemory) Then
PercentLoaded = pctInterviewLimit
Else
' Ensure that virtual memory is not too high compared to normal memory
If (Process.virtualMemoryUsage > (Process.MemoryUsage * 2)) Then
PercentLoaded = (pctEngineMemory + 15)
Else
PercentLoaded = pctEngineMemory
End If
End If
End If
See also
Examples of UNICOM Intelligence Interviewer load balancing algorithms