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