Added check for something already binding to port 139 to TEST 3
[samba.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 LOG LEVEL
117 ---------
118
119 If you set the log level (also known as "debug level") higher than 2
120 then you may suffer a large drop in performance. This is because the
121 server flushes the log file after each operation, which can be very
122 expensive. 
123
124
125 WIDE LINKS
126 ----------
127
128 The "wide links" option is now enabled by default, but if you disable
129 it (for better security) then you may suffer a performance hit in
130 resolving filenames. The performance loss is lessened if you have
131 "getwd cache = yes", which is now the default.
132
133
134 READ RAW
135 --------
136
137 The "read raw" operation is designed to be an optimised, low-latency
138 file read operation. A server may choose to not support it,
139 however. and Samba makes support for "read raw" optional, with it
140 being enabled by default.
141
142 In some cases clients don't handle "read raw" very well and actually
143 get lower performance using it than they get using the conventional
144 read operations. 
145
146 So you might like to try "read raw = no" and see what happens on your
147 network. It might lower, raise or not affect your performance. Only
148 testing can really tell.
149
150
151 WRITE RAW
152 ---------
153
154 The "write raw" operation is designed to be an optimised, low-latency
155 file write operation. A server may choose to not support it,
156 however. and Samba makes support for "write raw" optional, with it
157 being enabled by default.
158
159 Some machines may find "write raw" slower than normal write, in which
160 case you may wish to change this option.
161
162 READ PREDICTION
163 ---------------
164
165 Samba can do read prediction on some of the SMB commands. Read
166 prediction means that Samba reads some extra data on the last file it
167 read while waiting for the next SMB command to arrive. It can then
168 respond more quickly when the next read request arrives.
169
170 This is disabled by default. You can enable it by using "read
171 prediction = yes".
172
173 Note that read prediction is only used on files that were opened read
174 only.
175
176 Read prediction should particularly help for those silly clients (such
177 as "Write" under NT) which do lots of very small reads on a file.
178
179 Samba will not read ahead more data than the amount specified in the
180 "read size" option. It always reads ahead on 1k block boundaries.
181
182
183 MEMORY MAPPING
184 --------------
185
186 Samba supports reading files via memory mapping them. One some
187 machines this can give a large boost to performance, on others it
188 makes not difference at all, and on some it may reduce performance.
189
190 To enable you you have to recompile Samba with the -DUSE_MMAP=1 option
191 on the FLAGS line of the Makefile.
192
193 Note that memory mapping is only used on files opened read only, and
194 is not used by the "read raw" operation. Thus you may find memory
195 mapping is more effective if you disable "read raw" using "read raw =
196 no".
197
198
199 SLOW CLIENTS
200 ------------
201
202 One person has reported that setting the protocol to COREPLUS rather
203 than LANMAN2 gave a dramatic speed improvement (from 10k/s to 150k/s).
204
205 I suspect that his PC's (386sx16 based) were asking for more data than
206 they could chew. I suspect a similar speed could be had by setting
207 "read raw = no" and "max xmit = 2048", instead of changing the
208 protocol. Lowering the "read size" might also help.
209
210
211 SLOW LOGINS
212 -----------
213
214 Slow logins are almost always due to the password checking time. Using
215 the lowest practical "password level" will improve things a lot. You
216 could also enable the "UFC crypt" option in the Makefile.
217
218 CLIENT TUNING
219 -------------
220
221 Often a speed problem can be traced to the client. The client (for
222 example Windows for Workgroups) can often be tuned for better TCP
223 performance.
224
225 See your client docs for details. In particular, I have heard rumours
226 that the WfWg options TCPWINDOWSIZE and TCPSEGMENTSIZE can have a
227 large impact on performance.
228
229 Also note that some people have found that setting DefaultRcvWindow in
230 the [MSTCP] section of the SYSTEM.INI file under WfWg to 3072 gives a
231 big improvement. I don't know why.
232
233 My own experience wth DefaultRcvWindow is that I get much better
234 performance with a large value (16384 or larger). Other people have
235 reported that anything over 3072 slows things down enourmously. One
236 person even reported a speed drop of a factor of 30 when he went from
237 3072 to 8192. I don't know why.
238
239 It probably depends a lot on your hardware, and the type of unix box
240 you have at the other end of the link.
241
242 MY RESULTS
243 ----------
244
245 Some people want to see real numbers in a document like this, so here
246 they are. I have a 486sx33 client running WfWg 3.11 with the 3.11b
247 tcp/ip stack. It has a slow IDE drive and 20Mb of ram. It has a SMC
248 Elite-16 ISA bus ethernet card. The only WfWg tuning I've done is to
249 set DefaultRcvWindow in the [MSTCP] section of system.ini to 16384. My
250 server is a 486dx3-66 running Linux. It also has 20Mb of ram and a SMC
251 Elite-16 card. You can see my server config in the examples/tridge/
252 subdirectory of the distribution.
253
254 I get 490k/s on reading a 8Mb file with copy.
255 I get 441k/s writing the same file to the samba server.
256
257 Of course, there's a lot more to benchmarks than 2 raw throughput
258 figures, but it gives you a ballpark figure.
259
260 I've also tested Win95 and WinNT, and found WinNT gave me the best
261 speed as a samba client. The fastest client of all (for me) is
262 smbclient running on another linux box. Maybe I'll add those results
263 here someday ...
264
265
266 COMMENTS
267 --------
268
269 If you've read this far then please give me some feedback! Which of
270 the above suggestions worked for you?
271
272 Mail the samba mailing list or samba-bugs@anu.edu.au