Load Test Network Connection Monitoring

Questions around how to understand the number of connections an application is using have always existed, and have become important for various reasons over the years. There was one instance that changed my perspective on monitoring active and inactive network connections. It was an application which used an Oracle backend. At the time we were seeing issues in production and it turned out that they were happening when the number of connections grew to over 10,000. Using netstat we were able to determine that a majority of the connections were not even being used and were created with the IIS connection pool in the connection strings. So, the easy resolution was to reduce the minpool size for the connection strings in the webconfig.

Using netstat is not a new idea either, but I have put together some Powershell to make it easier. This will allow you to monitor any server’s connections, then after your test is done you can dump the data into an excel spreadsheet and perform some analysis.

$ErrorActionPreference="SilentlyContinue"
$TimetoRunInMinutes = 5
$srvName = $env:computername
$outDir = 'C:\output\'
$outFile = $outDir+“NetstatReport_” + $srvName + ".txt"

for( $n = 1;$n -le $TimetoRunInMinutes; $n++)

{
$Time = Get-Date -Format G | out-File $outfile -append
netstat -an |out-file $outfile -append
# wait for a minute
Start-Sleep 60
}

 

Have fun and let me know if you find an interesting way to use this!