java io上传速度慢_SMB 文件传输速度缓慢

SMB 文件传输速度缓慢Slow SMB files transfer speed

12/25/2019

本文内容

本文提供了通过 SMB 实现慢速文件传输速度的建议的故障排除过程。This article provides suggested troubleshooting procedures for slow file transfer speeds through SMB.

大型文件传输速度缓慢Large file transfer is slow

如果观察到大文件传输缓慢,请考虑以下步骤:If you observe slow transfers of large files, consider the following steps:

对于未缓冲的 IO (xcopy/j或robocopy/j),请尝试文件复制命令。Try the file copy command for unbuffered IO (xcopy /J or robocopy /J).

测试存储速度。Test the storage speed. 这是因为文件复制速度受存储速度的限制。This is because file copy speeds are limited by storage speed.

文件副本有时会快速启动,然后速度会减慢。File copies sometimes start fast and then slow down. 按照以下准则验证此情况:Follow these guidelines to verify this situation:

这种情况通常发生在初始副本被缓存或缓冲的情况下(在内存中或在 RAID 控制器的内存缓存中),并且缓存会耗尽。这会强制将数据直接写入磁盘(写入)。This usually occurs when the initial copy is cached or buffered (either in memory or in the RAID controller's memory cache) and the cache runs out. This forces data to be written directly to disk (write-through). 这是一个速度较慢的进程。This is a slower process.

使用存储性能监视器计数器来确定随着时间的推移,存储性能是否会下降。Use storage performance monitor counters to determine whether storage performance degrades over time.

使用 RAMMap (SysInternals)可确定内存中 "映射的文件" 的使用是否因可用的内存消耗而停止增长。Use RAMMap (SysInternals) to determine whether "Mapped File" usage in memory stops growing because of free memory exhaustion.

查找跟踪中的数据包丢失情况。Look for packet loss in the trace. 这可能会导致 TCP 拥塞提供程序受到限制。This can cause throttling by the TCP congestion provider.

对于 SMBv3 和更高版本,请确保 SMB 多通道已启用且正常工作。For SMBv3 and later versions, make sure that SMB Multichannel is enabled and working.

在 SMB 客户端上,在 SMB 中启用大型 MTU 并禁用带宽限制。On the SMB client, enable large MTU in SMB, and disable bandwidth throttling. 为此,请运行以下命令:To do this, run the following command:

Set-SmbClientConfiguration -EnableBandwidthThrottling 0 -EnableLargeMtu 1

小文件传输速度缓慢Small file transfer is slow

如果有多个文件,最常见的情况是通过 SMB 进行小文件的慢速传输。Slow transfer of small files through SMB occurs most commonly if there are many files. 这是预期的行为。This is an expected behavior.

在文件传输过程中,创建文件会导致高协议开销和较高的文件系统开销。During file transfer, file creation causes both high protocol overhead and high file system overhead. 对于大型文件传输,这些成本仅出现一次。For large file transfers, these costs occur only one time. 当传输大量小文件时,成本是重复的,导致传输速度缓慢。When a large number of small files are transferred, the cost is repetitive and causes slow transfers.

下面是有关此问题的技术详细信息:The following are technical details about this problem:

SMB 调用 create 命令来请求创建文件。SMB calls a create command to request that the file be created. 某些代码将检查该文件是否存在,然后创建该文件。Some code will check whether the file exists, and then create the file. 或 create 命令的某些变体将创建实际文件。Or some variation of the create command creates the actual file.

每个 create 命令都会在文件系统上生成活动。Each create command generates activity on the file system.

写入数据后,文件将关闭。After the data is written, the file is closed.

一段时间后,该过程将受到网络延迟和 SMB 服务器延迟的影响。All some time, the process suffers from network latency and SMB server latency. 这是因为 SMB 请求首先转换为文件系统命令,然后转换为实际的文件系统延迟以完成操作。This is because the SMB request is first translated to a file system command and then to the actual file system latency to complete the operation.

如果任何防病毒程序正在运行,则传输的速度将更慢。If any antivirus program is running, the transfer slows down even more. 这是因为数据通常是通过数据包嗅探器一次扫描的,第二次将数据写入磁盘。This is because the data is typically scanned one time by the packet sniffer and a second time when it is written to disk. 在某些情况下,这些操作是重复的。In some scenarios, these actions are repeated thousands of time. 你可能会发现小于 1 MB/秒的速度。You potentially observe speeds of less than 1 MB/s.

打开 Office 文档速度缓慢Opening Office documents is slow

此问题通常发生在 WAN 连接上。This problem generally occurs on a WAN connection. 这种情况很常见,通常是由 Office 应用程序(特别是 Microsoft Excel)访问和读取数据的方式引起的。This is common and typically is caused by the manner in which Office apps (Microsoft Excel, in particular) access and read data.

建议确保办公室和 SMB 的二进制文件是最新的,然后通过在 SMB 服务器上禁用租约来进行测试。We recommend that you make sure that the Office and SMB binaries are up-to-date, and then test by having leasing disabled on the SMB server. 为此,请执行以下步骤:To do this, follow these steps:

在 Windows 8 和 Windows Server 2012 或更高版本的 Windows 中运行以下 PowerShell 命令:Run the following PowerShell command in Windows 8 and Windows Server 2012 or later versions of Windows:

Set-SmbServerConfiguration -EnableLeasing $false

或者,在提升的命令提示符窗口中运行以下命令:Or, run the following command in an elevated Command Prompt window:

REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters /v DisableLeasing /t REG\_DWORD /d 1 /f

备注

设置此注册表项后,不再授予 SMB2 租约,但 oplock 仍可用。After you set this registry key, SMB2 leases are no longer granted, but oplocks are still available. 此设置主要用于故障排除。This setting is used primarily for troubleshooting.

重新启动文件服务器或重新启动服务器服务。Restart the file server or restart the Server service. 若要重新启动该服务,请运行以下命令:To restart the service, run the following commands:

NET STOP SERVER

NET START SERVER

若要避免此问题,还可以将文件复制到本地文件服务器。To avoid this issue, you can also replicate the file to a local file server.


版权声明:本文为weixin_39619893原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。