SBX - Search With Button

SBX - Forum Post Title

How to Balance NAV "Windows Clients" / Dynamics NAV Server

Microsoft Dynamics NAV Forum

NAVxHH asked a question on 16 Oct 2017 3:57 AM

Question Status

Unanswered

Hi together,

 

are you looking for a clever balancing between your Microsoft Dynamics NAV Server’s (NST)?

 I'm searching for a long time and find no standard way in NAV (NAV2013, NAV2015, NAV2016, NAV2017 or NAV2018). 

 

For sure you know that you can add some parameter to RTC to make sure the NAV users are on the right database

 

Something like that:

 

"C:\Program Files (x86)\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe" -"settings:\\SERVERXY\Config\SettingsNAV2017.config "

 

With that in mind we are very close to the Solution:

 


 

All 3 Microsoft Dynamics NAV Service Tiers (NST’s) are connected to database NAV2017.

 

 

 

Windows Task scheduler start‘s every 5 or 10min our Powershell Skipt.

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

-command "C:\scripts\NavBalancer.ps1" -noninteractive

 

  

At „C:\NAV\Config“ on our NST Windows Server "SERVERXY"  is our standard „RTC Config file“ “SettingsNAV2017.config” for all clients in the company.

 

I our example it’ also a shared folder (\\SERVERXY\Config).

 

For our 3 NSTs, we need also 3 different „RTC Config file“.

NST1 have a „RTC Config file“ that belongs to NST1 “NAV2017_1” – Port 7046

NST2 have a „RTC Config file“ that belongs to NST2 “NAV2017_2” – Port 8046

NST3 have a „RTC Config file“ that belongs to NST3 “NAV2017_3” – Port 9046

 

Powershell:

 

So, what’s in that magic script you are looking for:

No magic, just a simple NST counter check

 

PS1

 

1. Definition ot the counters:

  • Definition of the counter that you want to check at each NSt (with Powershell) before you choose the right NST.
  • Minimum users at a NST should be round about 10. After you reach 10, the next NST is in our example the best one.
  • You can also choose 50 or more. Or combine it with MS NLB.
  • Number of the NSTs that I want to use for the balancing. In our example 3.

 

2. Process to check what’s up at the NST

  • We call with PowerShell the standard MS counter of the “Microsoft Dynamics NAV” Server. NAV2017_1; NAV2017_2; NAV2017_3.
  • We don’t switch wild between the NSt’s We allwas checkk the “Activs Session“. It’s the same like Page9506.
  • In Perfom or Powershell we have to search for this counter „# Active sessions“
  • That give us a live view into the current user load. And some of you know, there are more counters. Maybe later

 

3. Copy process to give the useres the prefert „RTC Config file“ at the shared Folder

  • \\SERVERXY\config\“  is the default "SettingsNAV2017.config" folder that all RTC users are using.

  • "C:\Program Files (x86)\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe" -"settings:\\SERVERXY\Config\SettingsNAV2017.config”

 

#  Script name:   NavBalancer.ps1

#  Created on:    12.10.2017

#  Updated on:    01.12.2017

#  Author:        T.B. & S.K.

#  Purpose:       Check currently usage of NST and change config files if usage has reached minimum tier usage

#  posible counters are:

 

### common config file name ###

$configFileName = "SettingsNAV2017.config"

### path of currently used configuration ###

$activeConfigPath = "\\SERVERXY\Config\" + $configFileName

### base path for tiering config files: add tiernumber to acces specific config file ###

$configPath = "C:\NAV\BalanceNSTConfig\NST"

### base name of performance counter

$counterBaseName = "nav2017_"

 

### number of tier for this server: !!! tier numbers start at 1 !!! ###

$numberOfTiers = 3

### set minimum users per tier ###

$minimumUsersPerTier = 10

### active tier: default 0 ###

$activeTier = 0

### vars for less used tier ###

$lessUsedTier = 0

[int]$lessUsedTierCounter = 0

 

### get currently used tier from active config file ###

[xml]$activeConfigFile = Get-Content $activeConfigPath

$currentTier = ($activeConfigFile.configuration.appSettings.add | Where-Object {$_.key -eq "ServerInstance" }).value.split("_")[-1]

 

### check current usage of each service tier ###

for($i=1; $i -le $numberOfTiers; $i++) {

   $counterName = $counterBaseName + $i

   if (get-counter -counter "\Microsoft Dynamics NAV($counterName)\# Active sessions") {

       [int]$counterVal = (get-counter -counter "\Microsoft Dynamics NAV($counterName)\# Active sessions").countersamples.cookedvalue

       # set vars for less used tier on first run

       if ($lessUsedTier -eq 0) {

           $lessUsedTier = 1

           $lessUsedTierCounter = $counterVal

       } else {

           # if new less tier was detected update vars

           [boolean]$setNewLessCounterVars = $counterVal -lt $lessUsedTierCounter

           if ($setNewLessCounterVars) {

               $lessUsedTier = $i

               $lessUsedTierCounter = $counterVal

           }

       }

      

       if($counterVal -lt $minimumUsersPerTier) {

           if($activeTier -eq 0) {

               $activeTier = $i

           }

       }

   }

}

### set active tier to less used if all tiers have more than minimum users

if ($activeTier -eq 0) {

   $activeTier = $lessUsedTier

}

 

#[Console]::WriteLine("CurrentTier: " + $currentTier + " -- NewActiveTier: " + $activeTier)

### copy config file if active is not currently used tier ###

if($currentTier -ne $activeTier) {

   ### define source item path and copy to active config path ###

   $configFilePath = $configPath + $activeTier + "\" + $configFileName

   #[Console]::WriteLine("Copy: " + $configFilePath + " to: " + $activeConfigPath)

   Copy-Item -Path $configFilePath -Destination $activeConfigPath

}

 #Updated TB Code

 

### global info ###

 

### display all counters for microsoft dynamics nav ###

#(get-counter -listset "microsoft dynamics nav").counter

 

### get counter values for all instances ###

#get-counter -counter "\Microsoft Dynamics NAV(*)\# Active sessions"

 

### get counter value object for "nav2017" instance ###

#(get-counter -counter "\Microsoft Dynamics NAV(nav2017)\# Active sessions")

 

### get numeric counter value for "nav2017" instance ###

#(get-counter -counter "\Microsoft Dynamics NAV(nav2017)\# Active sessions").countersamples.cookedvalue

 #===============================================================================================

 

#maybe you want to expand the check:-)

#ALL COUNTERS:

#"% Primary key cache hit rate"
#"# Primary key cache total requests"
#"% Command cache hit rate"
#"# Command cache total requests"
#"% Preferred connection cache hit rate"
#"# Preferred connection total requests"
#"# Open connections"
#"% Query repositioning rate"
#"% Result set cache hit rate"
#"# Result set cache total requests"
#"% Calculated fields cache hit rate"
#"# Calculated fields cache total requests"
#"Heartbeat time (ms)"
#"# Rows in all temporary tables"
#"Soft throttled connections"
#"Hard throttled connections"
#"Transient errors"
#"# Mounted tenants"
#"Server operations/sec"
#"# Active sessions"
#"Average server operation time (ms)"
#"Total # Pending tasks"
#"Total # Running tasks"
#"# Running tasks"
#"# Available tasks"
#"Maximum # of tasks"
#"# of task errors/sec"
#"Average task execution time"
#"Time (ms) since the list of running tasks last had capacity for new tasks"
#"# Open tenant connections"
#"# Open application Connections"

Reply
Marco Rodriquez responded on 16 Oct 2017 4:23 AM
My Badges

Great solution, and thanks for sharing it!

Reply
Eric Roy responded on 11 Oct 2018 4:19 PM

Hi,

is it working?

thanks?

Reply

SBX - Two Col Forum

SBX - Migrated JS