# önder online
Teknoloji ve siber güvenlik dünyasına hoş geldiniz Güncel siber tehditler ve korunma yöntemleri Yapay zekâ ve otomasyonun güvenliğe etkileri Microsoft 365 ve Active Directory güvenlik rehberleri Yazılım geliştirmede güvenlik odaklı yaklaşımlar Teknoloji ve siber güvenlik dünyasına hoş geldiniz Güncel siber tehditler ve korunma yöntemleri

Menu

Disk performansını ölçmek için PowerShell scripti

Disk performansını ölçmek için PowerShell scripti

Script, write ve read latency değerlerini milisaniye cinsinden ölçer ve ortalama, minimum ve maximum değerleri gösterir.

Disk performansını ölçmek için PowerShell scripti, İşte hem read hem de write latency değerlerini ölçen kapsamlı bir script:

 
# Disk Latency Test Script
# Read ve Write latency değerlerini ölçer

param(
    [string]$TestPath = "C:\",
    [int]$TestFileSizeMB = 100,
    [int]$BlockSizeKB = 4,
    [int]$Iterati
)

Write-Host "=== Disk Latency Test Başlatılıyor ===" -ForegroundColor Cyan
Write-Host "Test Yolu: $TestPath"
Write-Host "Test Dosya Boyutu: $TestFileSizeMB MB"
Write-Host "Block Size: $BlockSizeKB KB"
Write-Host "İterasyon Sayısı: $IterationCount"
Write-Host ""

# Test dosyası yolu
$testFile = Join-Path $TestPath "disk_latency_test.tmp"

# Sonuçları tutacak arrayler
$writeLatencies = @()
$readLatencies = @()

try {
    # Write Latency Testi
    Write-Host "Write Latency Testi Başlıyor..." -ForegroundColor Yellow
    
    $blockSize = $BlockSizeKB * 1024
    $data = New-Object byte[] $blockSize
    $random = New-Object System.Random
    $random.NextBytes($data)
    
    for ($i = 1; $i -le $IterationCount; $i++) {
        $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
        
        $fileStream = [System.IO.File]::Open($testFile, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write, [System.IO.FileShare]::None)
        $fileStream.Write($data, 0, $data.Length)
        $fileStream.Flush()
        $fileStream.Close()
        
        $stopwatch.Stop()
        $writeLatencies += $stopwatch.Elapsed.TotalMilliseconds
        
        Write-Progress -Activity "Write Test" -Status "İterasyon $i/$IterationCount" -PercentComplete (($i / $IterationCount) * 100)
    }
    
    Write-Host "Write Latency Testi Tamamlandı!" -ForegroundColor Green
    Write-Host ""
    
    # Read Latency Testi
    Write-Host "Read Latency Testi Başlıyor..." -ForegroundColor Yellow
    
    for ($i = 1; $i -le $IterationCount; $i++) {
        $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
        
        $fileStream = [System.IO.File]::Open($testFile, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read)
        $buffer = New-Object byte[] $blockSize
        $fileStream.Read($buffer, 0, $buffer.Length) | Out-Null
        $fileStream.Close()
        
        $stopwatch.Stop()
        $readLatencies += $stopwatch.Elapsed.TotalMilliseconds
        
        Write-Progress -Activity "Read Test" -Status "İterasyon $i/$IterationCount" -PercentComplete (($i / $IterationCount) * 100)
    }
    
    Write-Host "Read Latency Testi Tamamlandı!" -ForegroundColor Green
    Write-Host ""
    
    # Sonuçları hesapla
    $writeStats = $writeLatencies | Measure-Object -Average -Minimum -Maximum
    $readStats = $readLatencies | Measure-Object -Average -Minimum -Maximum
    
    # Sonuçları göster
    Write-Host "=== TEST SONUÇLARI ===" -ForegroundColor Cyan
    Write-Host ""
    Write-Host "WRITE LATENCY:" -ForegroundColor Yellow
    Write-Host "  Ortalama: $([math]::Round($writeStats.Average, 2)) ms"
    Write-Host "  Minimum:  $([math]::Round($writeStats.Minimum, 2)) ms"
    Write-Host "  Maximum:  $([math]::Round($writeStats.Maximum, 2)) ms"
    Write-Host ""
    Write-Host "READ LATENCY:" -ForegroundColor Yellow
    Write-Host "  Ortalama: $([math]::Round($readStats.Average, 2)) ms"
    Write-Host "  Minimum:  $([math]::Round($readStats.Minimum, 2)) ms"
    Write-Host "  Maximum:  $([math]::Round($readStats.Maximum, 2)) ms"
    Write-Host ""
    
    # IOPS hesapla (kabaca)
    $writeIOPS = [math]::Round(1000 / $writeStats.Average, 0)
    $readIOPS = [math]::Round(1000 / $readStats.Average, 0)
    
    Write-Host "TAHMINI IOPS (${BlockSizeKB}KB block size):" -ForegroundColor Yellow
    Write-Host "  Write IOPS: ~$writeIOPS"
    Write-Host "  Read IOPS:  ~$readIOPS"
    Write-Host ""
    
}
catch {
    Write-Host "HATA: $($_.Exception.Message)" -ForegroundColor Red
}
finally {
    # Test dosyasını temizle
    if (Test-Path $testFile) {
        Remove-Item $testFile -Force
        Write-Host "Test dosyası temizlendi." -ForegroundColor Gray
    }
}

Kullanım örnekleri:

# Varsayılan ayarlarla çalıştır (C:\ sürücüsünde)
.\disk-latency-test.ps1

# D:\ sürücüsünde test et
.\disk-latency-test.ps1 -TestPath "D:\"

# Daha küçük dosya ve daha az iterasyon ile hızlı test
.\disk-latency-test.ps1 -TestFileSizeMB 10 -IterationCount 50

# Farklı block size ile test (örn: 64KB)
.\disk-latency-test.ps1 -BlockSizeKB 64

Not:

  • Script'i çalıştırmak için PowerShell'i yönetici olarak açmanız gerekebilir
  • Test sırasında disk üzerine dosya yazılacağı için yeterli alan olduğundan emin olun
  • Daha doğru sonuçlar için arka planda çalışan programları kapatın