Add all the source files from the old CVS tree,
[tprouty/samba.git] / docs / howto / Speed.xml
1 <chapter id="speed">
2
3 <chapterinfo>
4         <author>
5                 <firstname>Paul</firstname><surname>Cochrane</surname>
6                 <affiliation>
7                         <orgname>Dundee Limb Fitting Centre</orgname>
8                         <address><email>paulc@dth.scot.nhs.uk</email></address>
9                 </affiliation>
10         </author>
11         &author.jelmer;
12         &author.jht;
13 </chapterinfo>
14
15 <title>Samba Performance Tuning</title>
16
17 <sect1>
18 <title>Comparisons</title>
19
20 <para>
21 The Samba server uses TCP to talk to the client. Thus if you are
22 trying to see if it performs well, you should really compare it to
23 programs that use the same protocol. The most readily available
24 programs for file transfer that use TCP are ftp or another TCP-based
25 SMB server.
26 </para>
27
28 <para>
29 If you want to test against something like an NT or Windows for Workgroups server, then
30 you will have to disable all but TCP on either the client or
31 server. Otherwise, you may well be using a totally different protocol
32 (such as NetBEUI) and comparisons may not be valid.
33 </para>
34
35 <para>
36 Generally, you should find that Samba performs similarly to ftp at raw
37 transfer speed. It should perform quite a bit faster than NFS,
38 although this depends on your system.
39 </para>
40
41 <para>
42 Several people have done comparisons between Samba and Novell, NFS or
43 Windows NT. In some cases Samba performed the best, in others the worst. I
44 suspect the biggest factor is not Samba versus some other system, but the
45 hardware and drivers used on the various systems. Given similar
46 hardware, Samba should certainly be competitive in speed with other
47 systems.
48 </para>
49
50 </sect1>
51
52 <sect1>
53 <title>Socket Options</title>
54
55 <para>
56 There are a number of socket options that can greatly affect the
57 performance of a TCP-based server like Samba.
58 </para>
59
60 <para>
61 The socket options that Samba uses are settable both on the command
62 line with the <option>-O</option> option, or in the &smb.conf; file.
63 </para>
64
65 <para>
66 The <smbconfoption><name>socket options</name></smbconfoption> section of the &smb.conf; manual page describes how
67 to set these and gives recommendations.
68 </para>
69
70 <para>
71 Getting the socket options correct can make a big difference to your
72 performance, but getting them wrong can degrade it by just as
73 much. The correct settings are very dependent on your local network.
74 </para>
75
76 <para>
77 The socket option TCP_NODELAY is the one that seems to make the biggest single difference
78 for most networks. Many people report that adding
79 <?latex \linebreak ?><smbconfoption><name>socket options</name><value>TCP_NODELAY</value></smbconfoption>
80 doubles the read performance of a Samba drive. The best explanation I have seen for
81 this is that the Microsoft TCP/IP stack is slow in sending TCP ACKs.
82 </para>
83
84 <para>
85 There have been reports that setting <parameter>socket options = SO_RCVBUF=8192</parameter> in smb.conf
86 can seriously degrade Samba performance on the loopback adaptor (IP Address 127.0.0.1). It is strongly
87 recommended that before specifying any settings for <parameter>socket options</parameter> the effect
88 first be quantitatively measured on the server being configured.
89 </para>
90
91 </sect1>
92
93 <sect1>
94 <title>Read Size</title>
95
96 <para>
97 The option <smbconfoption><name>read size</name></smbconfoption> affects the overlap of disk
98 reads/writes with network reads/writes. If the amount of data being
99 transferred in several of the SMB commands (currently SMBwrite, SMBwriteX and
100 SMBreadbraw) is larger than this value, then the server begins writing
101 the data before it has received the whole packet from the network, or
102 in the case of SMBreadbraw, it begins writing to the network before
103 all the data has been read from disk.
104 </para>
105
106 <para>
107 This overlapping works best when the speeds of disk and network access
108 are similar, having little effect when the speed of one is much
109 greater than the other.
110 </para>
111
112 <para>
113 The default value is 16384, but little experimentation has been
114 done as yet to determine the optimal value, and it is likely that the best
115 value will vary greatly between systems anyway. A value over 65536 is
116 pointless and will cause you to allocate memory unnecessarily.
117 </para>
118
119 </sect1>
120
121 <sect1>
122 <title>Max Xmit</title>
123
124 <para>
125         At startup the client and server negotiate a <parameter>maximum transmit</parameter> size,
126 which limits the size of nearly all SMB commands. You can set the
127 maximum size that Samba will negotiate using the <smbconfoption><name>max xmit</name></smbconfoption> option
128 in &smb.conf;. Note that this is the maximum size of SMB requests that 
129 Samba will accept, but not the maximum size that the client will accept.
130 The client maximum receive size is sent to Samba by the client and Samba
131 honors this limit.
132 </para>
133
134 <para>
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 In most cases the default is the best option.
139 </para>
140
141 </sect1>
142
143 <sect1>
144 <title>Log Level</title>
145
146 <para>
147 If you set the log level (also known as <smbconfoption><name>debug level</name></smbconfoption>) higher than 2
148 then you may suffer a large drop in performance. This is because the
149 server flushes the log file after each operation, which can be quite
150 expensive. 
151 </para>
152 </sect1>
153
154 <sect1>
155 <title>Read Raw</title>
156
157 <para>
158 The <smbconfoption><name>read raw</name></smbconfoption> operation is designed to be an optimized, low-latency
159 file read operation. A server may choose to not support it,
160 however, and Samba makes support for <smbconfoption><name>read raw</name></smbconfoption> optional, with it
161 being enabled by default.
162 </para>
163
164 <para>
165 In some cases clients do not handle <smbconfoption><name>read raw</name></smbconfoption> very well and actually
166 get lower performance using it than they get using the conventional
167 read operations. 
168 </para>
169
170 <para>
171 So you might like to try <smbconfoption><name>read raw</name><value>no</value></smbconfoption> and see what happens on your
172 network. It might lower, raise or not effect your performance. Only
173 testing can really tell.
174 </para>
175
176 </sect1>
177
178 <sect1>
179 <title>Write Raw</title>
180
181 <para>
182 The <smbconfoption><name>write raw</name></smbconfoption> operation is designed to be an optimized, low-latency
183 file write operation. A server may choose to not support it, however, and Samba makes support for
184 <smbconfoption><name>write raw</name></smbconfoption> optional, with it being enabled by default.
185 </para>
186
187 <para>
188 Some machines may find <smbconfoption><name>write raw</name></smbconfoption> slower than normal write, in which
189 case you may wish to change this option.
190 </para>
191
192 </sect1>
193
194 <sect1>
195 <title>Slow Logins</title>
196
197 <para>
198 Slow logins are almost always due to the password checking time. Using
199 the lowest practical <smbconfoption><name>password level</name></smbconfoption> will improve things. 
200 </para>
201
202 </sect1>
203
204 <sect1>
205 <title>Client Tuning</title>
206
207 <para>
208 Often a speed problem can be traced to the client. The client (for
209 example Windows for Workgroups) can often be tuned for better TCP
210 performance. Check the sections on the various clients in 
211 <link linkend="Other-Clients">Samba and Other CIFS Clients</link>.
212 </para>
213
214 </sect1>
215
216 <sect1>
217 <title>Samba Performance Problem Due to Changing Linux Kernel</title>
218
219 <para>
220 A user wrote the following to the mailing list:
221 </para>
222
223 <para>
224 I am running Gentoo on my server and Samba 2.2.8a. Recently
225 I changed kernel version from <filename>linux-2.4.19-gentoo-r10</filename> to
226 <filename>linux-2.4.20-wolk4.0s</filename>. And now I have a performance issue with Samba. 
227 Many of you will probably say,  <quote>Move to vanilla sources!</quote>
228 Well, I tried that and it didn't work. I have a 100mb LAN and two computers (Linux and
229 Windows 2000). The Linux server shares directories with DivX files, the client
230 (Windows 2000) plays them via LAN. Before when I was running the 2.4.19 kernel
231 everything was fine, but now movies freeze and stop. I tried moving
232 files between the server and Windows and it is terribly slow.
233 </para>
234
235 <para>
236 The answer he was given is:
237 </para>
238
239 <para>
240 Grab the mii-tool and check the duplex settings on the NIC.
241 My guess is that it is a link layer issue, not an application
242 layer problem. Also run ifconfig and verify that the framing
243 error, collisions, and so on, look normal for ethernet.
244 </para>
245
246 </sect1>
247
248 <sect1>
249 <title>Corrupt tdb Files</title>
250
251 <para>
252 Our Samba PDC server has been hosting three TB of data to our 500+ users
253 [Windows NT/XP]  for the last three years using Samba without a problem.
254 Today all shares went very slow. Also the main smbd kept
255 spawning new processes so we had 1600+ running smbd's (normally we avg. 250).
256 It crashed the SUN E3500 cluster twice. After a lot of searching, I
257 decided to <command>rm /var/locks/*.tdb</command>. Happy again.
258 </para>
259
260 <para>
261 <emphasis>Question:</emphasis> Is there any method of keeping the *.tdb files in top condition or
262 how can I detect early corruption?
263 </para>
264
265 <para>
266 <emphasis>Answer:</emphasis> Yes, run <command>tdbbackup</command> each time after stopping nmbd and before starting nmbd.
267 </para>
268
269 <para>
270 <emphasis>Question:</emphasis> What I also would like to mention is that the service latency seems
271 a lot lower than before the locks cleanup. Any ideas on keeping it top notch?
272 </para>
273
274 <para>
275 <emphasis>Answer:</emphasis> Yes. Same answer as for previous question!
276 </para>
277
278 </sect1>
279
280 <sect1>
281 <title>Samba Performance is Very Slow</title>
282
283 <para>
284 A site reported experiencing very baffling symptoms with MYOB Premier opening and
285 accessing it's data-files. Some  operations on the file would take between 40 and
286 45 seconds.
287 </para>
288
289 <para>
290 It turned out that the printer monitor program running on the windows
291 clients was causing the problems. From the logs, we saw activity coming
292 through with pauses of about 1 second.
293 </para>
294
295 <para>
296 Stopping the monitor software resulted in the networks access at normal
297 (quick) speed. Restarting the program caused the speed to slow down
298 again. The printer was a cannon lbp810 and the relevant task was
299 something like CAPON (not sure on spelling). The monitor software
300 displayed a printing now dialog on the client during printing.
301 </para>
302
303 <para>
304 We discovered this by starting with a clean install of windows and
305 trying the app at every step of the installation of other software
306 process (had to do this many times).
307 </para>
308
309 <para>
310 Moral of the story, check everything (other software included)!
311 </para>
312
313 </sect1>
314
315 </chapter>