Samba + Windows XP performance tunning (especially for slow operations with a lot of small files)

Публикувано / posted 2008-09-26 в категория / in category: Web development
  

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\<Interface GUID>

where <Interface GUID> 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\<Interface GUID>

where <Interface GUID> 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.


11 Responses to “Samba + Windows XP performance tunning (especially for slow operations with a lot of small files)”

  1. BOK says:

    Thanks! I tried setting most of these parameters.
    At least my performance went up from less than 1% network-usage to 5-6%.
    In the end I still think WinXP sucks though, needing all this…

  2. Огнян says:

    Frankly, network usage is not something that means much… Speed of copy and read operations is the primary concern and I had to benchmark with different tests to be sure what is working and what is not working.
    For me setting TcpAckFrequency and TcpDelAckTicks improved performance with about of 400%.
    I don't know if slow performance is WinXP's fault or Samba's fault -- once I had WinXP SP1 with old Samba server both without any optimizations and they worked lightening fast. I am still struggling to achieve same speed.

  3. corteplaneta says:

    Adding TcpAckFrequency & TcpDelAckTicks did improve my performance GREATLY. Before, I had to wait around ~5-10 seconds when using mplayer on a file (mounted through an SMB share). Now, the cache is instantly being filled up, though Amarok is still having difficulty playing without a delay. Thanks for the tips!

  4. Josh says:

    I run into oddities using Samba/Apache/Windows. Here\'s my basic approach:

    -- Linux Server running Apache and Samba
    -- Web dev files on linux server, served to HTTP by apache
    -- Edit web dev files in windows via mounted samba share

    I don\'t have general speed problems. Rather, what happens is when I change a file and save it, then reload the local web page, I experience a delay of about 15 seconds before the page renders. This only occurs when I change a file, not between page reloads with no file changes. I also do not get this behavior if I change the file directly on Linux using vi or the like, so my assumption is that this is a samba issue that\'s somehow delaying apache\'s access to the files if they\'ve just been written.

    Ideas?

  5. Огнян says:

    @Josh
    Did you try to edit your files with different windows program (I suspect that your current program is not releasing locks immediately after save). Just for the sake of test -- try something simple as Notepad to change and save a file. If the problem persist -- yes it looks like samba-win problem.
    Also try to stop your antivirus software and test again. I had similar problems with Norton antivirus a while ago…

  6. Josh says:

    Seems like it\'s a locking issue… I am getting excellent performance for this type of use scenario on this samba share with oplocks = no now.

  7. This post gave us a major Brainstorm session of all the possibilities we can utilize on our blog.

  8. Hi thank you for pointing to my webpage.
    Recently one person pointed me that \

  9. Огнян says:

    I thank you too for the good and helpful article!

  10. Andrew says:

    We use a Microsoft Access 2000 / VBA database application (running on Windows XP machines) to run our business. The data is on a fast (core I7 / 6GB memory) Ubuntu 9.04 Linux server, running on gigabit Ethernet network.

    Using a slow report as a reference (pulls a lot of data together):
    * Before your suggested changes: 32-seconds to display
    * After making changes you suggested: 7-seconds to display

    These changes affect copying of small files. It did not affect the copy time of a large (527MB) file either to or from the Linux server / Windows XP machine. IPERF showed identical results before & after.

    I found making the changes listed in: http://emergesync.com/resources/tips-for-samba-and-windows-xp/ also improved performance.

    I was on the verge of abandoning SAMBA till I saw your article & tried your suggestions. Thank you very much for your help !!!

  11. Jan says:

    This helped me a lot. After figuring out a lot of samba / nfs / vmware shit, I ditched NFS, use SAMBA for internal file sharing between fileserver and webserver, use samba also for my webdevelopers to connect of course.
    Subversion small file caused it to run verrry slow but with the changes made, it changed from +/- 200kb/s to 450kb/s

    Still, not too fast but a double increase in speeld. Which is nice.

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Внимание: Моля, въведете само ПЪРВИТЕ ТРИ цифри от картинката
Important: Please enter just the first three digits from the image