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