Performance Testing Through The Network Layers

Problem this snippet solves:

This script will perform timing tests at various layers in the network stack in an attempt to isolate performance issues.

Code :

param(
$domain = $null,
$url = $null,
$count = 5,
[string[]]$groups
);

$UA = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0";

$VIP_IPS = (
  ("Outside-Vip", "XXX.XXX.XXX.XXX", 443),
  ("Inside-Vip", "YYY.YYY.YYY.YYY", 443)
)

$APP_IPS = (
  ("app-01", "10.10.10.1", 80),
  ("app-02", "10.10.10.2", 80)
)

function Show-Usage()
{
Write-Host ".\Time-EntryPoints.ps1 -url  -count <5> -groups [vips|apps|all]";
}

function Get-IPFromHostname()
{
  param($hostname);
  ([System.Net.Dns]::GetHostAddresses($hostname))[0].ToString()
}

function Get-Stats()
{
  param($stats, $hostname, $ip, $port, $secs, $url);
  
  $o = 1 | Select Host, IP, Port, Url, Count, Min, Max, Avg, Sum, Secs;
  $o.Host = $hostname.Split(".")[0];
  $o.IP = $ip;
  $o.Port = $port;
  $o.Url = $url;
  $o.Count = $stats.Count;
  $o.Min = $stats.Minimum;
  $o.Max = $stats.Maximum;
  $o.Avg = $stats.Average;
  $o.Sum = $stats.Sum;
  $o.Secs = $secs;
  $o;
}

function Get-HostsToTest()
{
  param([string[]]$groups);
  
  $HOSTS = @();
  
  foreach($group in $groups )
  {
    switch ($group.ToLower())
    {
      "vips"    { $HOSTS += $VIP_IPS; }
      "apps"    { $HOSTS += $APP_IPS; }
      "all"     { $HOSTS += ($VIP_IPS + $APP_IPS); }
      default   { $HOSTS += ( ($group, "", 80), ("", "", 80) ); }
    }
  }
  
  $HOSTS;
}

if ( ($null -ne $domain) -and ($null -ne $url) )
{
  $secs = @();
  
  [System.Object[]]$hostEntries = Get-HostsToTest $groups;

  foreach($hostEntry in $hostEntries)
  {
    $hostname = $hostEntry[0];
    if ( $hostname.Length -gt 0 )
    {
      $ip = $hostEntry[1];
      if ( "" -eq $ip ) { $ip = Get-IPFromHostname $hostname; }
      $port = $hostEntry[2];
    
      $fullUrl = "http";
      if ( $port -eq 443 ) { $fullUrl += "s"; }
      $fullUrl += "://$domain";
      $fullUrl += $url;
    
      foreach($i in 1..$count)
      {
        $sec = (Measure-Command {curl --insecure -sNA $UA --resolve "${domain}:${port}:${ip}" $fullUrl | Out-Null}).TotalSeconds;
        $secs += (, $sec);
        
        Start-Sleep -Milliseconds 10;
      }
      $len = $secs.Length;

      $stats = Get-Stats ($secs | Measure-Object -Average -Minimum -Maximum -Sum) $hostname $ip $port $secs $url;
      $stats;
    }
    $secs = @();
  }
}
else
{
Show-Usage;
}
Published Mar 12, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment