Difference between revisions of "Performance Tuning"

m (Page reformatting)
m (Added categories)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= Introduction =
 
= Introduction =
  
Users may sometimes encounter performance problems in different situations. In many cases, this results from [[#Settings_that_should_be_avoided.21|misconfiguration based on wrong or outdated information]].
+
In certain situations, users can have performance problems when accessing a Samba server. In most cases, incorrectly set parameters cause the performance problems, such as described in [[#Settings_That_Should_Not_Be_Set|Settings That Should Not Be Set]].
  
This page gives an overview about possible tuning options. But in every case, the administrator has to decide if the changes are necessary!
+
If you are having performance problems using Samba that you cannot solve, subscribe to the [https://lists.samba.org/mailman/listinfo/samba Samba mailing list] and post:
 +
* A description of the problem.
 +
* You complete <code>smb.conf</code> file without any modifications.
 +
* Details about your environment:
 +
:* Operating system and version
 +
:* Samba version
 +
:* Is Samba built by yourself or are you using packages? If using packages, who is the package creator?
 +
:* Type of the installation: Active Directory (AD) domain controller (DC), NT4 primary domain controller (PDC), AD or NT4 domain member, standalone installation.
  
If you're having performance issues using Samba that you can't solve, please subscribe to the [https://lists.samba.org/mailman/listinfo/samba Samba Mailing List]. Post a description of your problem together with environment information and your smb.conf. The community and experienced users will usually help to identify the reasons.
 
  
  
  
  
 +
= SMB Protocol Version =
  
= SMB protocol version =
+
Each new server message block (SMB) version adds new protocol features and improves performance. Additionally, recent Windows operating systems support the latest protocol versions. If a new SMB protocol version is implemented in Samba and considered stable, the default of the <code>server max protocol</code> parameter is set to the latest version. It is recommended that you do not set the <code>server max protocol</code> parameter in your <code>smb.conf</code> file. If the parameter is not set and you are updating Samba to a version that provides a new SMB protocol version, it is automatically available to the clients.
  
Newer versions of the SMB protocol provide feature and performance improvments. It's a good choice to leave the „server max protocol“ at it's default value (remove the parameter from your [global] section). Samba uses the newest SMB dialect that is supported and considered stable.
+
To unset the parameter, remove the <code>server max protocol</code> entry from the <code>[global]</code> section of your <code>smb.conf</code> file.
  
  
Line 19: Line 26:
  
  
= Handling Large Directories =
+
= Directories with a Large Number of Files =
  
Samba implements a solution for sites that have experienced performance degradation, due to the problem of using Samba with applications, that need large numbers of files (100,000 or more) per directory.
+
To improve the performance of shares that are having directories containing more than 100.000 files:
  
To set up an application that needs large numbers of files per directory in a way that does not damage performance unduly, follow these steps:
+
* Rename all files on the share to lowercase.
 +
:{{Imbox
 +
| type = note
 +
| text = All files on the share must be converted to lowercase when using the example. Files using uppercase or both uppercase and lowercase are no longer listed on the share.
 +
}}
  
First, you need to canonicalize all the files in the directory to have one case, upper or lower (lower is recommended). Then set up a new custom share for the application as follows:
+
* Set the following parameters in the share's section:
  
  [bigshare]
+
  case sensitive = true
      path = /srv/samba/manyfilesdir
+
default case = lower
      read only = no
+
preserve case = no
      case sensitive = true
+
short preserve case = no
      default case = lower
 
      preserve case = no
 
      short preserve case = no
 
  
Of course, use your own path and settings, but set the case options to match the case of all the files in your directory. The path should point at the large directory needed for the application. Any new files created in there and in any paths under it will be forced by smbd into lowercase. But smbd will no longer have to scan the directory for names: It knows that if a file does not exist in lowercase, then it doesn't exist at all.
+
* Reload Samba:
  
The secret to this is really in the „case sensitive = true“ line. This tells smbd never to scan for case-insensitive versions of names. So if an application asks for a file called „foo“, and it cannot be found by a simple stat call, then smbd will return „file not found“ immediately without scanning the containing directory for a version of a different case. The other „case“ lines make this work by forcing a consistent case on all files created by smbd.
+
# smbcontrol all reload-config
  
Remember: All files and directories under the path directory must be in lowercase with this share configuration, because smbd will not be able to find any uppercase file-/directorynames with these settings. Also note that this is done on a per-share basis, allowing this parameter to be set only for a share servicing an application with this problematic behavior (using large numbers of entries in a directory) the rest of your smbd shares don't need to be affected.
+
Using these settings, all new files on the share are created using lowercase. Samba no longer has to scan the directory for upper- and lowercase. This improves the performance. For further details about the parameters, see the descriptions in the <code>smb.conf(5)</code> man page.
  
This makes smbd much faster when dealing with large directories.
 
  
  
  
  
 +
= Settings That Should Not Be Set =
  
= Settings that should be avoided! =
+
{{Imbox
 +
| type = important
 +
| text = The Samba team highly-recommends not setting the parameters described in this section without understanding the technical background and knowing the consequences. In most environments, setting these parameters or changing the defaults decreases the Samba network performance.
 +
}}
  
'''Below you find some examples of configuration options that are spread over the internet, which, in most cases, do the opposite of the expected! They are useless or even worse: <u>They may decrease performance!</u>'''
 
  
'''The Samba Team doesn't recommend using these options unless you know what you're doing!'''
 
  
  
 +
== The <code>socket options</code> Parameter ==
  
== socket options ==
+
Modern UNIX operating systems are tuned for high network performance by default. For example, Linux has an auto-tuning mechanism for buffer sizes. When you set the <code>socket options</code> parameter in the <code>smb.conf</code> file, you are overriding these settings. In most cases, setting this parameter decreases the performance.
  
Modern server operating systems are tuned for high network performance in the majority of situations. When you set socket options, you are overriding those settings. Linux in particular has an auto-tuning mechanism for buffer sizes that will be disabled if you specify a socket buffer size. This can potentially cripple your TCP/IP stack!
+
To unset the parameter, remove the <code>socket options</code> entry from the <code>[global]</code> section of your <code>smb.conf</code> file.
  
For the majority of installations, <u>this parameter should never be set!</u>
 
  
  
  
=== IPTOS_LOWDELAY ===
 
  
A lot of configurations use IPTOS_LOWDELAY which is historic. It refers to a time prior to Differentiated Services (DiffServ) when the Type of Service field in the IP header had bit flags indicating the quality of service required.
+
----
 
+
[[Category:Active Directory]]
Today, with the advent of DiffServ, the Differentiated Services Code Point (DSCP) value for the required level of service should be set instead. The appropriate value will vary from network to network depending on the network's QoS policy.
+
[[Category:Domain Members]]
 
+
[[Category:NT4 Domains]]
See RFC 2474 for DiffServ.
 
 
 
To set the DSCP field use the the IP_TOS socket option in legacy IPv4 (if you are still using v4) or the IPV6_TCLASS socket option in IPv6.
 

Latest revision as of 21:49, 26 February 2017

Introduction

In certain situations, users can have performance problems when accessing a Samba server. In most cases, incorrectly set parameters cause the performance problems, such as described in Settings That Should Not Be Set.

If you are having performance problems using Samba that you cannot solve, subscribe to the Samba mailing list and post:

  • A description of the problem.
  • You complete smb.conf file without any modifications.
  • Details about your environment:
  • Operating system and version
  • Samba version
  • Is Samba built by yourself or are you using packages? If using packages, who is the package creator?
  • Type of the installation: Active Directory (AD) domain controller (DC), NT4 primary domain controller (PDC), AD or NT4 domain member, standalone installation.



SMB Protocol Version

Each new server message block (SMB) version adds new protocol features and improves performance. Additionally, recent Windows operating systems support the latest protocol versions. If a new SMB protocol version is implemented in Samba and considered stable, the default of the server max protocol parameter is set to the latest version. It is recommended that you do not set the server max protocol parameter in your smb.conf file. If the parameter is not set and you are updating Samba to a version that provides a new SMB protocol version, it is automatically available to the clients.

To unset the parameter, remove the server max protocol entry from the [global] section of your smb.conf file.



Directories with a Large Number of Files

To improve the performance of shares that are having directories containing more than 100.000 files:

  • Rename all files on the share to lowercase.
  • Set the following parameters in the share's section:
case sensitive = true
default case = lower
preserve case = no
short preserve case = no
  • Reload Samba:
# smbcontrol all reload-config

Using these settings, all new files on the share are created using lowercase. Samba no longer has to scan the directory for upper- and lowercase. This improves the performance. For further details about the parameters, see the descriptions in the smb.conf(5) man page.



Settings That Should Not Be Set



The socket options Parameter

Modern UNIX operating systems are tuned for high network performance by default. For example, Linux has an auto-tuning mechanism for buffer sizes. When you set the socket options parameter in the smb.conf file, you are overriding these settings. In most cases, setting this parameter decreases the performance.

To unset the parameter, remove the socket options entry from the [global] section of your smb.conf file.