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