This is the ubiqx binary tree and linked list library.
[Samba.git] / docs / textdocs / Speed.txt
blobcb086a97112cb38234baccbc777b6b4bceec6ed2
1 Contributor:    Andrew Tridgell
2 Date:           January 1995
3 Status:         Current
5 Subject:        Samba performance issues
6 ============================================================================
8 This file tries to outline the ways to improve the speed of a Samba server.
10 COMPARISONS
11 -----------
13 The Samba server uses TCP to talk to the client. Thus if you are
14 trying to see if it performs well you should really compare it to
15 programs that use the same protocol. The most readily available
16 programs for file transfer that use TCP are ftp or another TCP based
17 SMB server.
19 If you want to test against something like a NT or WfWg server then
20 you will have to disable all but TCP on either the client or
21 server. Otherwise you may well be using a totally different protocol
22 (such as Netbeui) and comparisons may not be valid.
24 Generally you should find that Samba performs similarly to ftp at raw
25 transfer speed. It should perform quite a bit faster than NFS,
26 although this very much depends on your system.
28 Several people have done comparisons between Samba and Novell, NFS or
29 WinNT. In some cases Samba performed the best, in others the worst. I
30 suspect the biggest factor is not Samba vs some other system but the
31 hardware and drivers used on the various systems. Given similar
32 hardware Samba should certainly be competitive in speed with other
33 systems.
36 OPLOCKS
37 -------
39 Oplocks are the way that SMB clients get permission from a server to
40 locally cache file operations. If a server grants an oplock
41 (opportunistic lock) then the client is free to assume that it is the
42 only one accessing the file and it will agressively cache file
43 data. With some oplock types the client may even cache file open/close
44 operations. This can give enormous performance benefits.
46 With the release of Samba 1.9.18 we now correctly support opportunistic 
47 locks. This is turned on by default, and can be turned off on a share-
48 by-share basis by setting the parameter :
50 oplocks = False
52 We recommend that you leave oplocks on however, as current benchmark
53 tests with NetBench seem to give approximately a 30% improvement in
54 speed with them on. This is on average however, and the actual 
55 improvement seen can be orders of magnitude greater, depending on
56 what the client redirector is doing.
58 Previous to Samba 1.9.18 there was a 'fake oplocks' option. This
59 option has been left in the code for backwards compatibility reasons
60 but it's use is now deprecated. A short summary of what the old
61 code did follows.
63 Old 'fake oplocks' option - deprecated.
64 ---------------------------------------
66 Samba can also fake oplocks, by granting a oplock whenever a client 
67 asks for one. This is controlled using the smb.conf option "fake 
68 oplocks". If you set "fake oplocks = yes" then you are telling the 
69 client that it may agressively cache the file data for all opens.
71 Enabling 'fake oplocks' on all read-only shares or shares that you know
72 will only be accessed from one client at a time you will see a big
73 performance improvement on many operations. If you enable this option
74 on shares where multiple clients may be accessing the files read-write
75 at the same time you can get data corruption.
77 SOCKET OPTIONS
78 --------------
80 There are a number of socket options that can greatly affect the
81 performance of a TCP based server like Samba.
83 The socket options that Samba uses are settable both on the command
84 line with the -O option, or in the smb.conf file.
86 The "socket options" section of the smb.conf manual page describes how
87 to set these and gives recommendations.
89 Getting the socket options right can make a big difference to your
90 performance, but getting them wrong can degrade it by just as
91 much. The correct settings are very dependent on your local network.
93 The socket option TCP_NODELAY is the one that seems to make the
94 biggest single difference for most networks. Many people report that
95 adding "socket options = TCP_NODELAY" doubles the read performance of
96 a Samba drive. The best explanation I have seen for this is that the
97 Microsoft TCP/IP stack is slow in sending tcp ACKs.
100 READ SIZE
101 ---------
103 The option "read size" affects the overlap of disk reads/writes with
104 network reads/writes. If the amount of data being transferred in
105 several of the SMB commands (currently SMBwrite, SMBwriteX and
106 SMBreadbraw) is larger than this value then the server begins writing
107 the data before it has received the whole packet from the network, or
108 in the case of SMBreadbraw, it begins writing to the network before
109 all the data has been read from disk.
111 This overlapping works best when the speeds of disk and network access
112 are similar, having very little effect when the speed of one is much
113 greater than the other.
115 The default value is 16384, but very little experimentation has been
116 done yet to determine the optimal value, and it is likely that the best
117 value will vary greatly between systems anyway. A value over 65536 is
118 pointless and will cause you to allocate memory unnecessarily.
121 MAX XMIT
122 --------
124 At startup the client and server negotiate a "maximum transmit" size,
125 which limits the size of nearly all SMB commands. You can set the
126 maximum size that Samba will negotiate using the "max xmit = " option
127 in smb.conf. Note that this is the maximum size of SMB request that 
128 Samba will accept, but not the maximum size that the *client* will accept.
129 The client maximum receive size is sent to Samba by the client and Samba
130 honours this limit.
132 It defaults to 65536 bytes (the maximum), but it is possible that some
133 clients may perform better with a smaller transmit unit. Trying values
134 of less than 2048 is likely to cause severe problems.
136 In most cases the default is the best option.
139 LOCKING
140 -------
142 By default Samba does not implement strict locking on each read/write
143 call (although it did in previous versions). If you enable strict
144 locking (using "strict locking = yes") then you may find that you
145 suffer a severe performance hit on some systems.
147 The performance hit will probably be greater on NFS mounted
148 filesystems, but could be quite high even on local disks.
151 SHARE MODES
152 -----------
154 Some people find that opening files is very slow. This is often
155 because of the "share modes" code needed to fully implement the dos
156 share modes stuff. You can disable this code using "share modes =
157 no". This will gain you a lot in opening and closing files but will
158 mean that (in some cases) the system won't force a second user of a
159 file to open the file read-only if the first has it open
160 read-write. For many applications that do their own locking this
161 doesn't matter, but for some it may. Most Windows applications
162 depend heavily on "share modes" working correctly and it is
163 recommended that the Samba share mode support be left at the
164 default of "on".
166 The share mode code in Samba has been re-written in the 1.9.17
167 release following tests with the Ziff-Davis NetBench PC Benchmarking
168 tool. It is now believed that Samba 1.9.17 implements share modes
169 similarly to Windows NT.
171 NOTE: In the most recent versions of Samba there is an option to use
172 shared memory via mmap() to implement the share modes. This makes
173 things much faster. See the Makefile for how to enable this.
176 LOG LEVEL
177 ---------
179 If you set the log level (also known as "debug level") higher than 2
180 then you may suffer a large drop in performance. This is because the
181 server flushes the log file after each operation, which can be very
182 expensive. 
185 WIDE LINKS
186 ----------
188 The "wide links" option is now enabled by default, but if you disable
189 it (for better security) then you may suffer a performance hit in
190 resolving filenames. The performance loss is lessened if you have
191 "getwd cache = yes", which is now the default.
194 READ RAW
195 --------
197 The "read raw" operation is designed to be an optimised, low-latency
198 file read operation. A server may choose to not support it,
199 however. and Samba makes support for "read raw" optional, with it
200 being enabled by default.
202 In some cases clients don't handle "read raw" very well and actually
203 get lower performance using it than they get using the conventional
204 read operations. 
206 So you might like to try "read raw = no" and see what happens on your
207 network. It might lower, raise or not affect your performance. Only
208 testing can really tell.
211 WRITE RAW
212 ---------
214 The "write raw" operation is designed to be an optimised, low-latency
215 file write operation. A server may choose to not support it,
216 however. and Samba makes support for "write raw" optional, with it
217 being enabled by default.
219 Some machines may find "write raw" slower than normal write, in which
220 case you may wish to change this option.
222 READ PREDICTION
223 ---------------
225 Samba can do read prediction on some of the SMB commands. Read
226 prediction means that Samba reads some extra data on the last file it
227 read while waiting for the next SMB command to arrive. It can then
228 respond more quickly when the next read request arrives.
230 This is disabled by default. You can enable it by using "read
231 prediction = yes".
233 Note that read prediction is only used on files that were opened read
234 only.
236 Read prediction should particularly help for those silly clients (such
237 as "Write" under NT) which do lots of very small reads on a file.
239 Samba will not read ahead more data than the amount specified in the
240 "read size" option. It always reads ahead on 1k block boundaries.
243 MEMORY MAPPING
244 --------------
246 Samba supports reading files via memory mapping them. One some
247 machines this can give a large boost to performance, on others it
248 makes not difference at all, and on some it may reduce performance.
250 To enable you you have to recompile Samba with the -DUSE_MMAP option
251 on the FLAGS line of the Makefile.
253 Note that memory mapping is only used on files opened read only, and
254 is not used by the "read raw" operation. Thus you may find memory
255 mapping is more effective if you disable "read raw" using "read raw =
256 no".
259 SLOW CLIENTS
260 ------------
262 One person has reported that setting the protocol to COREPLUS rather
263 than LANMAN2 gave a dramatic speed improvement (from 10k/s to 150k/s).
265 I suspect that his PC's (386sx16 based) were asking for more data than
266 they could chew. I suspect a similar speed could be had by setting
267 "read raw = no" and "max xmit = 2048", instead of changing the
268 protocol. Lowering the "read size" might also help.
271 SLOW LOGINS
272 -----------
274 Slow logins are almost always due to the password checking time. Using
275 the lowest practical "password level" will improve things a lot. You
276 could also enable the "UFC crypt" option in the Makefile.
278 CLIENT TUNING
279 -------------
281 Often a speed problem can be traced to the client. The client (for
282 example Windows for Workgroups) can often be tuned for better TCP
283 performance.
285 See your client docs for details. In particular, I have heard rumours
286 that the WfWg options TCPWINDOWSIZE and TCPSEGMENTSIZE can have a
287 large impact on performance.
289 Also note that some people have found that setting DefaultRcvWindow in
290 the [MSTCP] section of the SYSTEM.INI file under WfWg to 3072 gives a
291 big improvement. I don't know why.
293 My own experience wth DefaultRcvWindow is that I get much better
294 performance with a large value (16384 or larger). Other people have
295 reported that anything over 3072 slows things down enourmously. One
296 person even reported a speed drop of a factor of 30 when he went from
297 3072 to 8192. I don't know why.
299 It probably depends a lot on your hardware, and the type of unix box
300 you have at the other end of the link.
303 MY RESULTS
304 ----------
306 Some people want to see real numbers in a document like this, so here
307 they are. I have a 486sx33 client running WfWg 3.11 with the 3.11b
308 tcp/ip stack. It has a slow IDE drive and 20Mb of ram. It has a SMC
309 Elite-16 ISA bus ethernet card. The only WfWg tuning I've done is to
310 set DefaultRcvWindow in the [MSTCP] section of system.ini to 16384. My
311 server is a 486dx3-66 running Linux. It also has 20Mb of ram and a SMC
312 Elite-16 card. You can see my server config in the examples/tridge/
313 subdirectory of the distribution.
315 I get 490k/s on reading a 8Mb file with copy.
316 I get 441k/s writing the same file to the samba server.
318 Of course, there's a lot more to benchmarks than 2 raw throughput
319 figures, but it gives you a ballpark figure.
321 I've also tested Win95 and WinNT, and found WinNT gave me the best
322 speed as a samba client. The fastest client of all (for me) is
323 smbclient running on another linux box. Maybe I'll add those results
324 here someday ...
327 COMMENTS
328 --------
330 If you've read this far then please give me some feedback! Which of
331 the above suggestions worked for you?
333 Mail the samba mailing list or samba-bugs@samba.anu.edu.au