NAS網路芳鄰速度不夠快,有可能可以解決的技術文件
本文僅針對伺服器端使用 Samba Server ( NAS 或 Linux 站設)使用,Windows 系統使用者可略過不看
由於近期公司購買的Qnap NAS主機網芳速度不如預期,比原本伺服端為Windows 7家用進階版還慢,當然有部份也要從硬體去評估,畢竟NAS的CPU及記憶體不如一般PC
底下文件目前僅為記錄使用,還未正式實測,有機會再來分享設定的差別
資料來源:http://ogre.ikratko.com/archives/347
You are probably wondering how to improve your samba's performance when you work with directories with a lot of small files. Here you will find two versions of same solution (expected improvement in performance 20% -- 500%) -- one short (for impatient) and one long with explanations.
[EDIT 2011-02-26] IMPORTANT!!! If you are experiencing slow access to your samba shares when accessing a lot of small files: first and foremost: disable your antivirus software (if any) and try again. 95% of the cases of slow access are caused by antivirus software. If disabling helps -- consult your antivirus program docs to see how to tune it in order to disable just network shares scanning (advanced antivirus programs allow you to add exceptions for given drives or even dirs).
Open your smb.conf and edit so it contains:
In [global]
log level = 0
read raw = yes
write raw = yes
kernel oplocks = yes
max xmit = 65535
dead time = 15
getwd cache = yes
netbios name = somename
Find the line which starts with (or add it if not exist):
socket options
And make it:
socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=17520 SO_SNDBUF=17520 IPTOS_LOWDELAY
You may need to replace "SO_RCVBUF=17520 SO_SNDBUF= 17520 " with "SO_RCVBUF=8192 SO_SNDBUF=8192″ depending on your network card on win box. In long version there is explanation why.
Go to the definition of the share and make sure that you have:
delete readonly = yes
oplocks = yes
Restart samba.
On the windows PC start regedit.
Go to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\
where is the GUID of your network card (there
will be few GUIDs). You can recognize the interface by IPAddress -- if
it contains your IP -- that is the GUID.
Create 2 new keys of type DWORD:
TcpAckFrequency with value 1
and
TcpDelAckTicks with value 0
Restart the windows PC in order changes to take effect and you should have increased performance when working with the samba shares.
Long version:
For years I am using following configuration for web development:
Linux server with Samba, Apache, PHP, Subversion etc.
Windows PC that maps as drive (W:) samba share to /var/www (where all the sites reside). I use TortoiseSVN client to checkout working copy of a site on w:. Then I use Zend Studio + Dreamweaver to edit directly site's files. When I am done, I am committing the changes with TortoiseSVN from the windows box. That worked fine until recently when I bumped into serious performance problems with TortoiseSVN -- simple commit or checkout was taking 2-3-4 minutes instead of 10-20 seconds. I am not sure what exactly caused this because I've changed several things simultaneously -- bought new PC, old PC become a linux server (debian etch), upgraded TortoiseSVN, etc.
The problem is not just with TortoiseSVN -- all operations with directories that contain a lot of subdirs and files (1000+) are vary slow.
After googling past 2-3 days and testing many different solutions I finally found something that really works.
My testing environment is:
Linux server -- Athlon 3400+, 1GB ram, 200GB HDD Hitachi sata2, Debian Etch, ext3 filesystem, samba 3.2.3
Windows PC -- Intel Core 2 Duo E8200, 4GB ram, 250GB HDD Seagate w/16mb, Windows XP SP2
Step 1: There is one good general article on Samba tunning. It will help you to understand the options.
Step 2: This is another article on tuning. Please pay attention on how to find correct mss value. You will need that.
Step 3: Create a benchmark tests and test your current speed. You will need one benchmark for large files and one for multiple small files.
For large files -- find some file that is about of 40GB in size. Copy it from samba share to win pc and back. Record the results.
For small files -- find a directory (on the samba share) with many small files (0-30kb). I've tested with 433 files. Shift-Del on that dir and measure the time between pressing the key and appearance of the window "Are you sure that you want to remove…". In my case it initially was about 20 seconds.
Step 4: Update samba to newer (latest) version
Samba is constantly improving and some bugs that affects performance are fixed in newer releases.
Step 5: Samba Configuration
Open your smb.conf and edit so it contains:
In [global]
log level = 0
read raw = yes
write raw = yes
kernel oplocks = yes
max xmit = 65535
dead time = 15
getwd cache = yes
netbios name = somename
Above options may improve samba performance between 0 and 50%.
Multiply your mss value (found in step 2) by 8. For example -- if your mss is 1460 then you will end up with 11600. This is the buffer size (used in the lines bellow).
Find the line which starts with (or add it if not exist):
socket options
And make it:
socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=buffer_size SO_SNDBUF=bufffer_size IPTOS_LOWDELAY
Above may improve performance with 0-10% (on higher side for large files). Some people suggesting to play with buffer size and to test which one works best for you. My experience shows that there is vary small difference in performance -- less than 2-3%.
In the definition of your share add:
delete readonly = yes
oplocks = yes
"delete readonly" is useful if you use TortoiseSVN and you are constantly receiving errors like "Error bumping revisions post-commit", "Can't move", "Can't merge", etc. Such errors occure if you use version 1.5+ (especially when combined with samba 3.0.22).
"oplocks" improve performance only if they are supported by the kernel (see "kernel oplocks = yes" in [global]). If your linux is not compiled with oplocks support -- this setting will not have effect.
Expected performance improvement: 0 -- 50%.
Step 6: Update network card driver for Windows PC
Drivers often contain bugs that are fixed in later versions. Update your driver and reboot.
Step 7: Configure Windows
Windows is well known for its stupid network settings. This article shows which keys in registry have to be edited/added in order to improve performance (especially when working with small files).
In short:
Go to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\
where is the GUID of your network card (there
may be few GUIDs). You can recognize the interface by IPAddress -- if it
contains your IP -- that is the GUID that you need.
Create 2 new values of type DWORD:
TcpAckFrequency with value 1
and
TcpDelAckTicks with value 0
Expected performance improvement -- 200 -- 400% (for small files).
Additionally you can add/change following key to improve windows TCP performance (information comes from blog of Delian Delchev (article is in bulgarian, so I am posting essence bellow)):
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named TcpWindowSize with value 65535 (make sure it is decimal).
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Afd\Parameters create DWORD value named DefaultReceiveWindow with value 65535 (decimal).
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Afd\Parameters create DWORD value named DefaultSendWindow with value 65535 (decimal).
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named Tcp1323Opts with value 3.
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named EnablePMTUDiscovery with value 1.
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named EnablePMTUBHDetect with value 1.
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named TcpNumConnections with value 10000 (decimal).
I will appreciate any feedback, test results, suggestions.
這兩篇也可以列入參考
https://support.microsoft.com/kb/321169
https://social.technet.microsoft.com/Forums/windowsserver/en-US/46898c7f-92e0-4c99-98d2-18a7458a7d2d/slow-network-write-speeds-via-smb-cifs?forum=winserverfiles
由於近期公司購買的Qnap NAS主機網芳速度不如預期,比原本伺服端為Windows 7家用進階版還慢,當然有部份也要從硬體去評估,畢竟NAS的CPU及記憶體不如一般PC
底下文件目前僅為記錄使用,還未正式實測,有機會再來分享設定的差別
資料來源:http://ogre.ikratko.com/archives/347
You are probably wondering how to improve your samba's performance when you work with directories with a lot of small files. Here you will find two versions of same solution (expected improvement in performance 20% -- 500%) -- one short (for impatient) and one long with explanations.
[EDIT 2011-02-26] IMPORTANT!!! If you are experiencing slow access to your samba shares when accessing a lot of small files: first and foremost: disable your antivirus software (if any) and try again. 95% of the cases of slow access are caused by antivirus software. If disabling helps -- consult your antivirus program docs to see how to tune it in order to disable just network shares scanning (advanced antivirus programs allow you to add exceptions for given drives or even dirs).
Simptoms: Transfers between windows and samba shares are vary slow especially when working with dirs with a lot of small files
Short version:Open your smb.conf and edit so it contains:
In [global]
log level = 0
read raw = yes
write raw = yes
kernel oplocks = yes
max xmit = 65535
dead time = 15
getwd cache = yes
netbios name = somename
Find the line which starts with (or add it if not exist):
socket options
And make it:
socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=17520 SO_SNDBUF=17520 IPTOS_LOWDELAY
You may need to replace "SO_RCVBUF=17520 SO_SNDBUF= 17520 " with "SO_RCVBUF=8192 SO_SNDBUF=8192″ depending on your network card on win box. In long version there is explanation why.
Go to the definition of the share and make sure that you have:
delete readonly = yes
oplocks = yes
Restart samba.
On the windows PC start regedit.
Go to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\
where
Create 2 new keys of type DWORD:
TcpAckFrequency with value 1
and
TcpDelAckTicks with value 0
Restart the windows PC in order changes to take effect and you should have increased performance when working with the samba shares.
Long version:
For years I am using following configuration for web development:
Linux server with Samba, Apache, PHP, Subversion etc.
Windows PC that maps as drive (W:) samba share to /var/www (where all the sites reside). I use TortoiseSVN client to checkout working copy of a site on w:. Then I use Zend Studio + Dreamweaver to edit directly site's files. When I am done, I am committing the changes with TortoiseSVN from the windows box. That worked fine until recently when I bumped into serious performance problems with TortoiseSVN -- simple commit or checkout was taking 2-3-4 minutes instead of 10-20 seconds. I am not sure what exactly caused this because I've changed several things simultaneously -- bought new PC, old PC become a linux server (debian etch), upgraded TortoiseSVN, etc.
The problem is not just with TortoiseSVN -- all operations with directories that contain a lot of subdirs and files (1000+) are vary slow.
After googling past 2-3 days and testing many different solutions I finally found something that really works.
My testing environment is:
Linux server -- Athlon 3400+, 1GB ram, 200GB HDD Hitachi sata2, Debian Etch, ext3 filesystem, samba 3.2.3
Windows PC -- Intel Core 2 Duo E8200, 4GB ram, 250GB HDD Seagate w/16mb, Windows XP SP2
Step 1: There is one good general article on Samba tunning. It will help you to understand the options.
Step 2: This is another article on tuning. Please pay attention on how to find correct mss value. You will need that.
Step 3: Create a benchmark tests and test your current speed. You will need one benchmark for large files and one for multiple small files.
For large files -- find some file that is about of 40GB in size. Copy it from samba share to win pc and back. Record the results.
For small files -- find a directory (on the samba share) with many small files (0-30kb). I've tested with 433 files. Shift-Del on that dir and measure the time between pressing the key and appearance of the window "Are you sure that you want to remove…". In my case it initially was about 20 seconds.
Step 4: Update samba to newer (latest) version
Samba is constantly improving and some bugs that affects performance are fixed in newer releases.
Step 5: Samba Configuration
Open your smb.conf and edit so it contains:
In [global]
log level = 0
read raw = yes
write raw = yes
kernel oplocks = yes
max xmit = 65535
dead time = 15
getwd cache = yes
netbios name = somename
Above options may improve samba performance between 0 and 50%.
Multiply your mss value (found in step 2) by 8. For example -- if your mss is 1460 then you will end up with 11600. This is the buffer size (used in the lines bellow).
Find the line which starts with (or add it if not exist):
socket options
And make it:
socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=buffer_size SO_SNDBUF=bufffer_size IPTOS_LOWDELAY
Above may improve performance with 0-10% (on higher side for large files). Some people suggesting to play with buffer size and to test which one works best for you. My experience shows that there is vary small difference in performance -- less than 2-3%.
In the definition of your share add:
delete readonly = yes
oplocks = yes
"delete readonly" is useful if you use TortoiseSVN and you are constantly receiving errors like "Error bumping revisions post-commit", "Can't move", "Can't merge", etc. Such errors occure if you use version 1.5+ (especially when combined with samba 3.0.22).
"oplocks" improve performance only if they are supported by the kernel (see "kernel oplocks = yes" in [global]). If your linux is not compiled with oplocks support -- this setting will not have effect.
Expected performance improvement: 0 -- 50%.
Step 6: Update network card driver for Windows PC
Drivers often contain bugs that are fixed in later versions. Update your driver and reboot.
Step 7: Configure Windows
Windows is well known for its stupid network settings. This article shows which keys in registry have to be edited/added in order to improve performance (especially when working with small files).
In short:
Go to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\
where
Create 2 new values of type DWORD:
TcpAckFrequency with value 1
and
TcpDelAckTicks with value 0
Expected performance improvement -- 200 -- 400% (for small files).
Additionally you can add/change following key to improve windows TCP performance (information comes from blog of Delian Delchev (article is in bulgarian, so I am posting essence bellow)):
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named TcpWindowSize with value 65535 (make sure it is decimal).
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Afd\Parameters create DWORD value named DefaultReceiveWindow with value 65535 (decimal).
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Afd\Parameters create DWORD value named DefaultSendWindow with value 65535 (decimal).
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named Tcp1323Opts with value 3.
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named EnablePMTUDiscovery with value 1.
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named EnablePMTUBHDetect with value 1.
In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters create DWORD value named TcpNumConnections with value 10000 (decimal).
I will appreciate any feedback, test results, suggestions.
這兩篇也可以列入參考
https://support.microsoft.com/kb/321169
https://social.technet.microsoft.com/Forums/windowsserver/en-US/46898c7f-92e0-4c99-98d2-18a7458a7d2d/slow-network-write-speeds-via-smb-cifs?forum=winserverfiles
留言