1 This file tries to outline the ways to improve the speed of a Samba server.
10 The Samba server uses TCP to talk to the client. Thus if you are
11 trying to see if it performs well you should really compare it to
12 programs that use the same protocol. The most readily available
13 programs for file transfer that use TCP are ftp or another TCP based
16 If you want to test against something like a NT or WfWg server then
17 you will have to disable all but TCP on either the client or
18 server. Otherwise you may well be using a totally different protocol
19 (such as Netbeui) and comparisons may not be valid.
21 Generally you should find that Samba performs similarly to ftp at raw
22 transfer speed. It should perform quite a bit faster than NFS,
23 although this very much depends on your system.
25 Several people have done comparisons between Samba and Novell, NFS or
26 WinNT. In some cases Samba performed the best, in others the worst. I
27 suspect the biggest factor is not Samba vs some other system but the
28 hardware and drivers used on the various systems. Given similar
29 hardware Samba should certainly be competitive in speed with other
36 Oplocks are the way that SMB clients get permission from a server to
37 locally cache file operations. If a server grants an oplock
38 (opportunistic lock) then the client is free to assume that it is the
39 only one accessing the file and it will agressively cache file
40 data. With some oplock types the client may even cache file open/close
41 operations. This can give enormous performance benefits.
43 Samba does not support opportunistic locks because they are very
44 difficult to do under Unix. Samba can fake them, however, by granting
45 a oplock whenever a client asks for one. This is controlled using the
46 smb.conf option "fake oplocks". If you set "fake oplocks = yes" then
47 you are telling the client that it may agressively cache the file
50 By enabling this option on all read-only shares or shares that you know
51 will only be accessed from one client at a time you will see a big
52 performance improvement on many operations. If you enable this option
53 on shares where multiple clients may be accessing the files read-write
54 at the same time you can get data corruption. Use this option
57 This option is disabled by default.
62 There are a number of socket options that can greatly affect the
63 performance of a TCP based server like Samba.
65 The socket options that Samba uses are settable both on the command
66 line with the -O option, or in the smb.conf file.
68 The "socket options" section of the smb.conf manual page describes how
69 to set these and gives recommendations.
71 Getting the socket options right can make a big difference to your
72 performance, but getting them wrong can degrade it by just as
73 much. The correct settings are very dependent on your local network.
75 The socket option TCP_NODELAY is the one that seems to make the
76 biggest single difference for most networks. Many people report that
77 adding "socket options = TCP_NODELAY" doubles the read performance of
78 a Samba drive. The best explanation I have seen for this is that the
79 Microsoft TCP/IP stack is slow in sending tcp ACKs.
85 The option "read size" affects the overlap of disk reads/writes with
86 network reads/writes. If the amount of data being transferred in
87 several of the SMB commands (currently SMBwrite, SMBwriteX and
88 SMBreadbraw) is larger than this value then the server begins writing
89 the data before it has received the whole packet from the network, or
90 in the case of SMBreadbraw, it begins writing to the network before
91 all the data has been read from disk.
93 This overlapping works best when the speeds of disk and network access
94 are similar, having very little effect when the speed of one is much
95 greater than the other.
97 The default value is 16384, but very little experimentation has been
98 done yet to determine the optimal value, and it is likely that the best
99 value will vary greatly between systems anyway. A value over 65536 is
100 pointless and will cause you to allocate memory unnecessarily.
106 At startup the client and server negotiate a "maximum transmit" size,
107 which limits the size of nearly all SMB commands. You can set the
108 maximum size that Samba will negotiate using the "max xmit = " option
111 It defaults to 65536 bytes (the maximum), but it is possible that some
112 clients may perform better with a smaller transmit unit. Trying values
113 of less than 2048 is likely to cause severe problems.
115 In most cases the default is the best option.
121 By default Samba does not implement strict locking on each read/write
122 call (although it did in previous versions). If you enable strict
123 locking (using "strict locking = yes") then you may find that you
124 suffer a severe performance hit on some systems.
126 The performance hit will probably be greater on NFS mounted
127 filesystems, but could be quite high even on local disks.
133 Some people find that opening files is very slow. This is often
134 because of the "share modes" code needed to fully implement the dos
135 share modes stuff. You can disable this code using "share modes =
136 no". This will gain you a lot in opening and closing files but will
137 mean that (in some cases) the system won't force a second user of a
138 file to open the file read-only if the first has it open
139 read-write. For many applications that do their own locking this
140 doesn't matter, but for some it may.
142 NOTE: In the most recent versions of Samba there is an option to use
143 shared memory via mmap() to implement the share modes. This makes
144 things much faster. See the Makefile for how to enable this.
149 If you set the log level (also known as "debug level") higher than 2
150 then you may suffer a large drop in performance. This is because the
151 server flushes the log file after each operation, which can be very
158 The "wide links" option is now enabled by default, but if you disable
159 it (for better security) then you may suffer a performance hit in
160 resolving filenames. The performance loss is lessened if you have
161 "getwd cache = yes", which is now the default.
167 The "read raw" operation is designed to be an optimised, low-latency
168 file read operation. A server may choose to not support it,
169 however. and Samba makes support for "read raw" optional, with it
170 being enabled by default.
172 In some cases clients don't handle "read raw" very well and actually
173 get lower performance using it than they get using the conventional
176 So you might like to try "read raw = no" and see what happens on your
177 network. It might lower, raise or not affect your performance. Only
178 testing can really tell.
184 The "write raw" operation is designed to be an optimised, low-latency
185 file write operation. A server may choose to not support it,
186 however. and Samba makes support for "write raw" optional, with it
187 being enabled by default.
189 Some machines may find "write raw" slower than normal write, in which
190 case you may wish to change this option.
195 Samba can do read prediction on some of the SMB commands. Read
196 prediction means that Samba reads some extra data on the last file it
197 read while waiting for the next SMB command to arrive. It can then
198 respond more quickly when the next read request arrives.
200 This is disabled by default. You can enable it by using "read
203 Note that read prediction is only used on files that were opened read
206 Read prediction should particularly help for those silly clients (such
207 as "Write" under NT) which do lots of very small reads on a file.
209 Samba will not read ahead more data than the amount specified in the
210 "read size" option. It always reads ahead on 1k block boundaries.
216 Samba supports reading files via memory mapping them. One some
217 machines this can give a large boost to performance, on others it
218 makes not difference at all, and on some it may reduce performance.
220 To enable you you have to recompile Samba with the -DUSE_MMAP=1 option
221 on the FLAGS line of the Makefile.
223 Note that memory mapping is only used on files opened read only, and
224 is not used by the "read raw" operation. Thus you may find memory
225 mapping is more effective if you disable "read raw" using "read raw =
232 One person has reported that setting the protocol to COREPLUS rather
233 than LANMAN2 gave a dramatic speed improvement (from 10k/s to 150k/s).
235 I suspect that his PC's (386sx16 based) were asking for more data than
236 they could chew. I suspect a similar speed could be had by setting
237 "read raw = no" and "max xmit = 2048", instead of changing the
238 protocol. Lowering the "read size" might also help.
244 Slow logins are almost always due to the password checking time. Using
245 the lowest practical "password level" will improve things a lot. You
246 could also enable the "UFC crypt" option in the Makefile.
251 Often a speed problem can be traced to the client. The client (for
252 example Windows for Workgroups) can often be tuned for better TCP
255 See your client docs for details. In particular, I have heard rumours
256 that the WfWg options TCPWINDOWSIZE and TCPSEGMENTSIZE can have a
257 large impact on performance.
259 Also note that some people have found that setting DefaultRcvWindow in
260 the [MSTCP] section of the SYSTEM.INI file under WfWg to 3072 gives a
261 big improvement. I don't know why.
263 My own experience wth DefaultRcvWindow is that I get much better
264 performance with a large value (16384 or larger). Other people have
265 reported that anything over 3072 slows things down enourmously. One
266 person even reported a speed drop of a factor of 30 when he went from
267 3072 to 8192. I don't know why.
269 It probably depends a lot on your hardware, and the type of unix box
270 you have at the other end of the link.
275 Some people want to see real numbers in a document like this, so here
276 they are. I have a 486sx33 client running WfWg 3.11 with the 3.11b
277 tcp/ip stack. It has a slow IDE drive and 20Mb of ram. It has a SMC
278 Elite-16 ISA bus ethernet card. The only WfWg tuning I've done is to
279 set DefaultRcvWindow in the [MSTCP] section of system.ini to 16384. My
280 server is a 486dx3-66 running Linux. It also has 20Mb of ram and a SMC
281 Elite-16 card. You can see my server config in the examples/tridge/
282 subdirectory of the distribution.
284 I get 490k/s on reading a 8Mb file with copy.
285 I get 441k/s writing the same file to the samba server.
287 Of course, there's a lot more to benchmarks than 2 raw throughput
288 figures, but it gives you a ballpark figure.
290 I've also tested Win95 and WinNT, and found WinNT gave me the best
291 speed as a samba client. The fastest client of all (for me) is
292 smbclient running on another linux box. Maybe I'll add those results
299 If you've read this far then please give me some feedback! Which of
300 the above suggestions worked for you?
302 Mail the samba mailing list or samba-bugs@samba.anu.edu.au