Network File System (NFS) is a widely-used protocol for sharing files over a network, and is commonly leveraged as a datastore solution within VMware vSphere environments. Maximizing NFS performance ensures optimal virtual machine (VM) operation and high availability of services. In this blog page, we explore a PowerShell script to collect VMware NFS performance metrics, share sample test results, explain the script, and cover best practices for both NFSv3 and NFSv4 with troubleshooting guidance for ESXi servers.
PowerShell Script to Collect VMware NFS Performance Metrics
Below is a PowerShell script that utilizes VMware PowerCLI to gather comprehensive NFS performance metrics for each ESXi host and NFS datastore in your environment. To run this script, ensure you have PowerCLI installed and are connected to your vCenter.
# Connect to vCenter
Connect-VIServer -Server 'your_vcenter_server'
# Retrieve all ESXi hosts
$hosts = Get-VMHost
foreach ($host in $hosts) {
Write-Host "Host: $($host.Name)"
# Get all NFS datastores on the host
$nfsDatastores = Get-Datastore -VMHost $host | Where-Object {$_.Type -eq "NFS" -or $_.Type -eq "NFS41"}
foreach ($datastore in $nfsDatastores) {
Write-Host "`tDatastore: $($datastore.Name) ($($datastore.Type))"
# Get performance stats for the NFS datastore
$stats = Get-Stat -Entity $datastore -Realtime -Stat
"datastore.readAverage",
"datastore.writeAverage",
"datastore.read",
"datastore.write",
"datastore.numberReadAveraged.average",
"datastore.numberWriteAveraged.average"
# Display the stats
if ($stats) {
$latest = $stats | Sort-Object -Property Timestamp -Descending | Select-Object -First 1
Write-Host "`t`tRead MBps: $($latest | Where-Object {$_.MetricId -like "*readAverage*"} | Select-Object -ExpandProperty Value)"
Write-Host "`t`tWrite MBps: $($latest | Where-Object {$_.MetricId -like "*writeAverage*"} | Select-Object -ExpandProperty Value)"
} else {
Write-Host "`t`tNo performance data available."
}
}
}
Disconnect-VIServer -Confirm:$false
What Does the Script Do?
- Connects to the specified vCenter server.
- Iterates through all ESXi hosts and their attached NFS datastores (both NFSv3 and NFSv4.1).
- Collects real-time performance statistics, such as read/write throughput and IO operations, for each NFS datastore.
- Outputs the latest available data for each metric, which helps identify bottlenecks and monitor performance trends over time.
- Disconnects from vCenter after completion.
Sample Test Results
| Host | Datastore | Type | Read MBps | Write MBps |
|---|---|---|---|---|
| esxi01.lab.local | nfs_ds1 | NFSv3 | 96.5 | 78.4 |
| esxi01.lab.local | nfs_ds2 | NFSv4.1 | 101.2 | 89.3 |
| esxi02.lab.local | nfs_ds1 | NFSv3 | 94.8 | 79.1 |
These results provide direct insight into NFS performance differences between protocol versions and highlight potential issues such as network congestion or suboptimal datastore configuration.
Best Practices for NFS in VMware (NFSv3 vs NFSv4)
- NFSv3 Best Practices:
- Use for simplicity if you do not need Kerberos or multipathing.
- Ensure your storage vendor settings are compatible with NFSv3.
- Enable jumbo frames on both ESXi and storage network for better throughput.
- Use a dedicated network for NFS traffic.
- Disable NFSv4.1 locking when using NFSv3 only workloads.
- NFSv4.1 Best Practices:
- Highly recommended for new deployments due to improved security (Kerberos), file locking, and multipathing capabilities.
- Check storage vendor support for NFSv4.1 and ESXi configuration options.
- Configure datastores with multipath I/O if supported; NFSv4.1 is required for this feature in VMware.
- Ensure DNS, time synchronization, and firewall rules are correct, as they are more crucial for NFSv4.1.
- General Tips:
- Keep ESXi hosts, vCenter, and storage firmware updated.
- Monitor performance regularly using scripts or advanced monitoring tools.
- Test failover scenarios using host isolation and datastore disconnects.
NFS Performance Troubleshooting on ESXi
- Check network connectivity: Validate that ESXi hosts can reach the NFS server using consistent ping results and
vmkping. - Analyze performance counters: Use the script above or
esxtopto check for high latency, low throughput, or high packet loss. - Review storage logs: Both on the ESXi and storage server to spot permission, export, or protocol errors.
- Validate NFS version configuration: Make sure mount options and NFS server exports match your intended version (3 or 4.1).
- Check for locking conflicts (NFSv4.1): File locking issues can cause client-side delays or errors.
- Update drivers and firmware: Outdated NIC or HBA drivers can severely impact performance.
Conclusion
Measuring and optimizing NFS performance in a VMware environment is essential for maintaining VM responsiveness and ensuring data integrity. Using scripts like the one provided, administrators can proactively monitor NFS metrics, apply the protocol-specific best practices, and efficiently troubleshoot potential issues for both NFSv3 and NFSv4.1 implementations. Regular monitoring and alignment to best practices will help you get the most out of your storage infrastructure.