Difference between revisions of "Make Samba Go Faster"

From Amahi Wiki
Jump to: navigation, search
m
Line 1: Line 1:
 
{{MessageBox|
 
{{MessageBox|
backgroundcolor = red|
+
backgroundcolor = #faa|
 
image =Warning.png|
 
image =Warning.png|
 
heading =WARNING|
 
heading =WARNING|

Revision as of 00:19, 13 July 2012

Warning.png WARNING
This is recommended only for advanced users, proceed with caution.



Background

Amahi makes heavy use of Samba. Samba is what handles shared folders and allow you to connect to your Amahi and browse your folders from Windows etc. Greyhole also uses Samba and it's logs to handle file operations.

After installing a wired gigabit network in my house, due to the WIFI being bogged down by 14 wireless clients, I tested the performance in the network. I got around 500-600MBit/sec in read speeds and about 600-700MBit/sec in write speeds. But when I tried against the Amahi server I found that I only got 56MBit/sec in read speeds.

After looking at the samba configuration file I saw that Async IO (AIO) was not enabled by Amahi. What AIO does is that it let's Samba handle several file operations asynchronously. This can, at the expense of some CPU cycles, increase the performance quite a lot.

I increased the read speed to 500-600MBit/sec by enabling AIO and saw Samba using around 1-4% CPU on a Intel E2200.

Enable AIO

To enable AIO an you can add the following to the global section of your /etc/samba/smb.conf file

Text
​socket options=SO_RCVBUF=131072 SO_SNDBUF=131072 TCP_NODELAY min receivefile size = 16384 use sendfile = true aio read size = 16384 aio write size = 16384 aio write behind = true <--- NOTE!!!: Only use with extreme caution. Read explanation bellow​

This is only an example but you can tweak all the options to fit your environment and needs. Bellow are an explination of the options used above. More information can be found at http://www.samba.org

Options Explained

min receivefile size

This option changes the behavior of Samba when processing SMBwriteX calls. Any incoming SMBwriteX call on a non-signed SMB/CIFS connection greater than this value will not be processed in the normal way but will be passed to any underlying kernel recvfile or splice system call (if there is no such call Samba will emulate in user space). This allows zero-copy writes directly from network socket buffers into the filesystem buffer cache, if available. It may improve performance but user testing is recommended. If set to zero Samba processes SMBwriteX calls in the normal way. To enable POSIX large write support (SMB/CIFS writes up to 16Mb) this option must be nonzero. The maximum value is 128k. Values greater than 128k will be silently set to 128k.

   Note this option will have NO EFFECT if set on a SMB signed connection.
   The default is zero, which disables this option

use sendfile

If this parameter is yes, and the sendfile() system call is supported by the underlying operating system, then some SMB read calls (mainly ReadAndX and ReadRaw) will use the more efficient sendfile system call for files that are exclusively oplocked. This may make more efficient use of the system CPU's and cause Samba to be faster. Samba automatically turns this off for clients that use protocol levels lower than NT LM 0.12 and when it detects a client is Windows 9x (using sendfile from Linux will cause these clients to fail).

socket options

This option allows you to set socket options to be used when talking with the client.

Socket options are controls on the networking layer of the operating systems which allow the connection to be tuned.

This option will typically be used to tune your Samba server for optimal performance for your local network. There is no way that Samba can know what the optimal parameters are for your net, so you must experiment and choose them yourself. We strongly suggest you read the appropriate documentation for your operating system first (perhaps man setsockopt will help).

You may find that on some systems Samba will say "Unknown socket option" when you supply an option. This means you either incorrectly typed it or you need to add an include file to includes.h for your OS. If the latter is the case please send the patch to samba-technical@samba.org.

Any of the supported socket options may be combined in any way you like, as long as your OS allows it.

This is the list of socket options currently settable using this option:

  • SO_KEEPALIVE
  • SO_REUSEADDR
  • SO_BROADCAST
  • TCP_NODELAY
  • IPTOS_LOWDELAY
  • IPTOS_THROUGHPUT
  • SO_SNDBUF *
  • SO_RCVBUF *
  • SO_SNDLOWAT *
  • SO_RCVLOWAT *

Those marked with a '*' take an integer argument. The others can optionally take a 1 or 0 argument to enable or disable the option, by default they will be enabled if you don't specify 1 or 0.

To specify an argument use the syntax SOME_OPTION = VALUE for example SO_SNDBUF = 8192. Note that you must not have any spaces before or after the = sign.

If you are on a local network then a sensible option might be:

Text
​socket options = IPTOS_LOWDELAY​

If you have a local network then you could try:

Text
​socket options = IPTOS_LOWDELAY TCP_NODELAY​

If you are on a wide area network then perhaps try setting IPTOS_THROUGHPUT.

Note that several of the options may cause your Samba server to fail completely. Use these options with caution!

aio read size

Samba will read from file asynchronously when size of request is bigger than this value. Note that it happens only for non-chained and non-chaining reads and when not using write cache.

aio write size

Samba will write to file asynchronously when size of request is bigger than this value. Note that it happens only for non-chained and non-chaining reads and when not using write cache.

aio write behind

Samba will not wait until write requests are finished before returning the result to the client for files listed in this parameter. Instead, Samba will immediately return that the write request has been finished successfully, no matter if the operation will succeed or not. This might speed up clients without aio support, but is really dangerous, because data could be lost and files could be damaged.

Things to Note

It can not be under stressed. Bad options can be very BAD. It can corrupt your data and make you very sad. Use extreme caution if experimenting with the options!

If you add a new share in Amahi or change the settings of an existing one, Amahi will overwrite the /etc/samba/smb.conf file with the new configuration and thus removing your changes. A place to enable AIO in the settings section of Amahi has been suggested at http://bugs.amahi.org/issues/show/861