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