These utilities are not in HEAD
[kai/samba.git] / docs / htmldocs / speed.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Samba performance issues</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.77"><LINK
9 REL="HOME"
10 TITLE="SAMBA Project Documentation"
11 HREF="samba-howto-collection.html"><LINK
12 REL="PREVIOUS"
13 TITLE="Quick Cross Subnet Browsing / Cross Workgroup Browsing guide"
14 HREF="browsing-quick.html"><LINK
15 REL="NEXT"
16 TITLE="HOWTO Access Samba source code via CVS"
17 HREF="cvs-access.html"></HEAD
18 ><BODY
19 CLASS="CHAPTER"
20 BGCOLOR="#FFFFFF"
21 TEXT="#000000"
22 LINK="#0000FF"
23 VLINK="#840084"
24 ALINK="#0000FF"
25 ><DIV
26 CLASS="NAVHEADER"
27 ><TABLE
28 SUMMARY="Header navigation table"
29 WIDTH="100%"
30 BORDER="0"
31 CELLPADDING="0"
32 CELLSPACING="0"
33 ><TR
34 ><TH
35 COLSPAN="3"
36 ALIGN="center"
37 >SAMBA Project Documentation</TH
38 ></TR
39 ><TR
40 ><TD
41 WIDTH="10%"
42 ALIGN="left"
43 VALIGN="bottom"
44 ><A
45 HREF="browsing-quick.html"
46 ACCESSKEY="P"
47 >Prev</A
48 ></TD
49 ><TD
50 WIDTH="80%"
51 ALIGN="center"
52 VALIGN="bottom"
53 ></TD
54 ><TD
55 WIDTH="10%"
56 ALIGN="right"
57 VALIGN="bottom"
58 ><A
59 HREF="cvs-access.html"
60 ACCESSKEY="N"
61 >Next</A
62 ></TD
63 ></TR
64 ></TABLE
65 ><HR
66 ALIGN="LEFT"
67 WIDTH="100%"></DIV
68 ><DIV
69 CLASS="CHAPTER"
70 ><H1
71 ><A
72 NAME="SPEED"
73 ></A
74 >Chapter 17. Samba performance issues</H1
75 ><DIV
76 CLASS="SECT1"
77 ><H1
78 CLASS="SECT1"
79 ><A
80 NAME="AEN2742"
81 ></A
82 >17.1. Comparisons</H1
83 ><P
84 >The Samba server uses TCP to talk to the client. Thus if you are
85 trying to see if it performs well you should really compare it to
86 programs that use the same protocol. The most readily available
87 programs for file transfer that use TCP are ftp or another TCP based
88 SMB server.</P
89 ><P
90 >If you want to test against something like a NT or WfWg server then
91 you will have to disable all but TCP on either the client or
92 server. Otherwise you may well be using a totally different protocol
93 (such as Netbeui) and comparisons may not be valid.</P
94 ><P
95 >Generally you should find that Samba performs similarly to ftp at raw
96 transfer speed. It should perform quite a bit faster than NFS,
97 although this very much depends on your system.</P
98 ><P
99 >Several people have done comparisons between Samba and Novell, NFS or
100 WinNT. In some cases Samba performed the best, in others the worst. I
101 suspect the biggest factor is not Samba vs some other system but the
102 hardware and drivers used on the various systems. Given similar
103 hardware Samba should certainly be competitive in speed with other
104 systems.</P
105 ></DIV
106 ><DIV
107 CLASS="SECT1"
108 ><H1
109 CLASS="SECT1"
110 ><A
111 NAME="AEN2748"
112 ></A
113 >17.2. Oplocks</H1
114 ><DIV
115 CLASS="SECT2"
116 ><H2
117 CLASS="SECT2"
118 ><A
119 NAME="AEN2750"
120 ></A
121 >17.2.1. Overview</H2
122 ><P
123 >Oplocks are the way that SMB clients get permission from a server to
124 locally cache file operations. If a server grants an oplock
125 (opportunistic lock) then the client is free to assume that it is the
126 only one accessing the file and it will agressively cache file
127 data. With some oplock types the client may even cache file open/close
128 operations. This can give enormous performance benefits.</P
129 ><P
130 >With the release of Samba 1.9.18 we now correctly support opportunistic 
131 locks. This is turned on by default, and can be turned off on a share-
132 by-share basis by setting the parameter :</P
133 ><P
134 ><B
135 CLASS="COMMAND"
136 >oplocks = False</B
137 ></P
138 ><P
139 >We recommend that you leave oplocks on however, as current benchmark
140 tests with NetBench seem to give approximately a 30% improvement in
141 speed with them on. This is on average however, and the actual 
142 improvement seen can be orders of magnitude greater, depending on
143 what the client redirector is doing.</P
144 ><P
145 >Previous to Samba 1.9.18 there was a 'fake oplocks' option. This
146 option has been left in the code for backwards compatibility reasons
147 but it's use is now deprecated. A short summary of what the old
148 code did follows.</P
149 ></DIV
150 ><DIV
151 CLASS="SECT2"
152 ><H2
153 CLASS="SECT2"
154 ><A
155 NAME="AEN2758"
156 ></A
157 >17.2.2. Level2 Oplocks</H2
158 ><P
159 >With Samba 2.0.5 a new capability - level2 (read only) oplocks is
160 supported (although the option is off by default - see the smb.conf
161 man page for details). Turning on level2 oplocks (on a share-by-share basis)
162 by setting the parameter :</P
163 ><P
164 ><B
165 CLASS="COMMAND"
166 >level2 oplocks = true</B
167 ></P
168 ><P
169 >should speed concurrent access to files that are not commonly written
170 to, such as application serving shares (ie. shares that contain common
171 .EXE files - such as a Microsoft Office share) as it allows clients to
172 read-ahread cache copies of these files.</P
173 ></DIV
174 ><DIV
175 CLASS="SECT2"
176 ><H2
177 CLASS="SECT2"
178 ><A
179 NAME="AEN2764"
180 ></A
181 >17.2.3. Old 'fake oplocks' option - deprecated</H2
182 ><P
183 >Samba can also fake oplocks, by granting a oplock whenever a client 
184 asks for one. This is controlled using the smb.conf option "fake 
185 oplocks". If you set "fake oplocks = yes" then you are telling the 
186 client that it may agressively cache the file data for all opens.</P
187 ><P
188 >Enabling 'fake oplocks' on all read-only shares or shares that you know
189 will only be accessed from one client at a time you will see a big
190 performance improvement on many operations. If you enable this option
191 on shares where multiple clients may be accessing the files read-write
192 at the same time you can get data corruption.</P
193 ></DIV
194 ></DIV
195 ><DIV
196 CLASS="SECT1"
197 ><H1
198 CLASS="SECT1"
199 ><A
200 NAME="AEN2768"
201 ></A
202 >17.3. Socket options</H1
203 ><P
204 >There are a number of socket options that can greatly affect the
205 performance of a TCP based server like Samba.</P
206 ><P
207 >The socket options that Samba uses are settable both on the command
208 line with the -O option, or in the smb.conf file.</P
209 ><P
210 >The "socket options" section of the smb.conf manual page describes how
211 to set these and gives recommendations.</P
212 ><P
213 >Getting the socket options right can make a big difference to your
214 performance, but getting them wrong can degrade it by just as
215 much. The correct settings are very dependent on your local network.</P
216 ><P
217 >The socket option TCP_NODELAY is the one that seems to make the
218 biggest single difference for most networks. Many people report that
219 adding "socket options = TCP_NODELAY" doubles the read performance of
220 a Samba drive. The best explanation I have seen for this is that the
221 Microsoft TCP/IP stack is slow in sending tcp ACKs.</P
222 ></DIV
223 ><DIV
224 CLASS="SECT1"
225 ><H1
226 CLASS="SECT1"
227 ><A
228 NAME="AEN2775"
229 ></A
230 >17.4. Read size</H1
231 ><P
232 >The option "read size" affects the overlap of disk reads/writes with
233 network reads/writes. If the amount of data being transferred in
234 several of the SMB commands (currently SMBwrite, SMBwriteX and
235 SMBreadbraw) is larger than this value then the server begins writing
236 the data before it has received the whole packet from the network, or
237 in the case of SMBreadbraw, it begins writing to the network before
238 all the data has been read from disk.</P
239 ><P
240 >This overlapping works best when the speeds of disk and network access
241 are similar, having very little effect when the speed of one is much
242 greater than the other.</P
243 ><P
244 >The default value is 16384, but very little experimentation has been
245 done yet to determine the optimal value, and it is likely that the best
246 value will vary greatly between systems anyway. A value over 65536 is
247 pointless and will cause you to allocate memory unnecessarily.</P
248 ></DIV
249 ><DIV
250 CLASS="SECT1"
251 ><H1
252 CLASS="SECT1"
253 ><A
254 NAME="AEN2780"
255 ></A
256 >17.5. Max xmit</H1
257 ><P
258 >At startup the client and server negotiate a "maximum transmit" size,
259 which limits the size of nearly all SMB commands. You can set the
260 maximum size that Samba will negotiate using the "max xmit = " option
261 in smb.conf. Note that this is the maximum size of SMB request that 
262 Samba will accept, but not the maximum size that the *client* will accept.
263 The client maximum receive size is sent to Samba by the client and Samba
264 honours this limit.</P
265 ><P
266 >It defaults to 65536 bytes (the maximum), but it is possible that some
267 clients may perform better with a smaller transmit unit. Trying values
268 of less than 2048 is likely to cause severe problems.</P
269 ><P
270 >In most cases the default is the best option.</P
271 ></DIV
272 ><DIV
273 CLASS="SECT1"
274 ><H1
275 CLASS="SECT1"
276 ><A
277 NAME="AEN2785"
278 ></A
279 >17.6. Locking</H1
280 ><P
281 >By default Samba does not implement strict locking on each read/write
282 call (although it did in previous versions). If you enable strict
283 locking (using "strict locking = yes") then you may find that you
284 suffer a severe performance hit on some systems.</P
285 ><P
286 >The performance hit will probably be greater on NFS mounted
287 filesystems, but could be quite high even on local disks.</P
288 ></DIV
289 ><DIV
290 CLASS="SECT1"
291 ><H1
292 CLASS="SECT1"
293 ><A
294 NAME="AEN2789"
295 ></A
296 >17.7. Share modes</H1
297 ><P
298 >Some people find that opening files is very slow. This is often
299 because of the "share modes" code needed to fully implement the dos
300 share modes stuff. You can disable this code using "share modes =
301 no". This will gain you a lot in opening and closing files but will
302 mean that (in some cases) the system won't force a second user of a
303 file to open the file read-only if the first has it open
304 read-write. For many applications that do their own locking this
305 doesn't matter, but for some it may. Most Windows applications
306 depend heavily on "share modes" working correctly and it is
307 recommended that the Samba share mode support be left at the
308 default of "on".</P
309 ><P
310 >The share mode code in Samba has been re-written in the 1.9.17
311 release following tests with the Ziff-Davis NetBench PC Benchmarking
312 tool. It is now believed that Samba 1.9.17 implements share modes
313 similarly to Windows NT.</P
314 ><P
315 >NOTE: In the most recent versions of Samba there is an option to use
316 shared memory via mmap() to implement the share modes. This makes
317 things much faster. See the Makefile for how to enable this.</P
318 ></DIV
319 ><DIV
320 CLASS="SECT1"
321 ><H1
322 CLASS="SECT1"
323 ><A
324 NAME="AEN2794"
325 ></A
326 >17.8. Log level</H1
327 ><P
328 >If you set the log level (also known as "debug level") higher than 2
329 then you may suffer a large drop in performance. This is because the
330 server flushes the log file after each operation, which can be very
331 expensive. </P
332 ></DIV
333 ><DIV
334 CLASS="SECT1"
335 ><H1
336 CLASS="SECT1"
337 ><A
338 NAME="AEN2797"
339 ></A
340 >17.9. Wide lines</H1
341 ><P
342 >The "wide links" option is now enabled by default, but if you disable
343 it (for better security) then you may suffer a performance hit in
344 resolving filenames. The performance loss is lessened if you have
345 "getwd cache = yes", which is now the default.</P
346 ></DIV
347 ><DIV
348 CLASS="SECT1"
349 ><H1
350 CLASS="SECT1"
351 ><A
352 NAME="AEN2800"
353 ></A
354 >17.10. Read raw</H1
355 ><P
356 >The "read raw" operation is designed to be an optimised, low-latency
357 file read operation. A server may choose to not support it,
358 however. and Samba makes support for "read raw" optional, with it
359 being enabled by default.</P
360 ><P
361 >In some cases clients don't handle "read raw" very well and actually
362 get lower performance using it than they get using the conventional
363 read operations. </P
364 ><P
365 >So you might like to try "read raw = no" and see what happens on your
366 network. It might lower, raise or not affect your performance. Only
367 testing can really tell.</P
368 ></DIV
369 ><DIV
370 CLASS="SECT1"
371 ><H1
372 CLASS="SECT1"
373 ><A
374 NAME="AEN2805"
375 ></A
376 >17.11. Write raw</H1
377 ><P
378 >The "write raw" operation is designed to be an optimised, low-latency
379 file write operation. A server may choose to not support it,
380 however. and Samba makes support for "write raw" optional, with it
381 being enabled by default.</P
382 ><P
383 >Some machines may find "write raw" slower than normal write, in which
384 case you may wish to change this option.</P
385 ></DIV
386 ><DIV
387 CLASS="SECT1"
388 ><H1
389 CLASS="SECT1"
390 ><A
391 NAME="AEN2809"
392 ></A
393 >17.12. Read prediction</H1
394 ><P
395 >Samba can do read prediction on some of the SMB commands. Read
396 prediction means that Samba reads some extra data on the last file it
397 read while waiting for the next SMB command to arrive. It can then
398 respond more quickly when the next read request arrives.</P
399 ><P
400 >This is disabled by default. You can enable it by using "read
401 prediction = yes".</P
402 ><P
403 >Note that read prediction is only used on files that were opened read
404 only.</P
405 ><P
406 >Read prediction should particularly help for those silly clients (such
407 as "Write" under NT) which do lots of very small reads on a file.</P
408 ><P
409 >Samba will not read ahead more data than the amount specified in the
410 "read size" option. It always reads ahead on 1k block boundaries.</P
411 ></DIV
412 ><DIV
413 CLASS="SECT1"
414 ><H1
415 CLASS="SECT1"
416 ><A
417 NAME="AEN2816"
418 ></A
419 >17.13. Memory mapping</H1
420 ><P
421 >Samba supports reading files via memory mapping them. One some
422 machines this can give a large boost to performance, on others it
423 makes not difference at all, and on some it may reduce performance.</P
424 ><P
425 >To enable you you have to recompile Samba with the -DUSE_MMAP option
426 on the FLAGS line of the Makefile.</P
427 ><P
428 >Note that memory mapping is only used on files opened read only, and
429 is not used by the "read raw" operation. Thus you may find memory
430 mapping is more effective if you disable "read raw" using "read raw =
431 no".</P
432 ></DIV
433 ><DIV
434 CLASS="SECT1"
435 ><H1
436 CLASS="SECT1"
437 ><A
438 NAME="AEN2821"
439 ></A
440 >17.14. Slow Clients</H1
441 ><P
442 >One person has reported that setting the protocol to COREPLUS rather
443 than LANMAN2 gave a dramatic speed improvement (from 10k/s to 150k/s).</P
444 ><P
445 >I suspect that his PC's (386sx16 based) were asking for more data than
446 they could chew. I suspect a similar speed could be had by setting
447 "read raw = no" and "max xmit = 2048", instead of changing the
448 protocol. Lowering the "read size" might also help.</P
449 ></DIV
450 ><DIV
451 CLASS="SECT1"
452 ><H1
453 CLASS="SECT1"
454 ><A
455 NAME="AEN2825"
456 ></A
457 >17.15. Slow Logins</H1
458 ><P
459 >Slow logins are almost always due to the password checking time. Using
460 the lowest practical "password level" will improve things a lot. You
461 could also enable the "UFC crypt" option in the Makefile.</P
462 ></DIV
463 ><DIV
464 CLASS="SECT1"
465 ><H1
466 CLASS="SECT1"
467 ><A
468 NAME="AEN2828"
469 ></A
470 >17.16. Client tuning</H1
471 ><P
472 >Often a speed problem can be traced to the client. The client (for
473 example Windows for Workgroups) can often be tuned for better TCP
474 performance.</P
475 ><P
476 >See your client docs for details. In particular, I have heard rumours
477 that the WfWg options TCPWINDOWSIZE and TCPSEGMENTSIZE can have a
478 large impact on performance.</P
479 ><P
480 >Also note that some people have found that setting DefaultRcvWindow in
481 the [MSTCP] section of the SYSTEM.INI file under WfWg to 3072 gives a
482 big improvement. I don't know why.</P
483 ><P
484 >My own experience wth DefaultRcvWindow is that I get much better
485 performance with a large value (16384 or larger). Other people have
486 reported that anything over 3072 slows things down enourmously. One
487 person even reported a speed drop of a factor of 30 when he went from
488 3072 to 8192. I don't know why.</P
489 ><P
490 >It probably depends a lot on your hardware, and the type of unix box
491 you have at the other end of the link.</P
492 ><P
493 >Paul Cochrane has done some testing on client side tuning and come 
494 to the following conclusions:</P
495 ><P
496 >Install the W2setup.exe file from www.microsoft.com. This is an 
497 update for the winsock stack and utilities which improve performance.</P
498 ><P
499 >Configure the win95 TCPIP registry settings to give better 
500 perfomance. I use a program called MTUSPEED.exe which I got off the 
501 net. There are various other utilities of this type freely available. 
502 The setting which give the best performance for me are:</P
503 ><P
504 ></P
505 ><OL
506 TYPE="1"
507 ><LI
508 ><P
509 >MaxMTU                  Remove</P
510 ></LI
511 ><LI
512 ><P
513 >RWIN                    Remove</P
514 ></LI
515 ><LI
516 ><P
517 >MTUAutoDiscover         Disable</P
518 ></LI
519 ><LI
520 ><P
521 >MTUBlackHoleDetect      Disable</P
522 ></LI
523 ><LI
524 ><P
525 >Time To Live            Enabled</P
526 ></LI
527 ><LI
528 ><P
529 >Time To Live - HOPS     32</P
530 ></LI
531 ><LI
532 ><P
533 >NDI Cache Size          0</P
534 ></LI
535 ></OL
536 ><P
537 >I tried virtually all of the items mentioned in the document and 
538 the only one which made a difference to me was the socket options. It 
539 turned out I was better off without any!!!!!</P
540 ><P
541 >In terms of overall speed of transfer, between various win95 clients 
542 and a DX2-66 20MB server with a crappy NE2000 compatible and old IDE 
543 drive (Kernel 2.0.30). The transfer rate was reasonable for 10 baseT.</P
544 ><P
545 >FIXME
546 The figures are:          Put              Get 
547 P166 client 3Com card:    420-440kB/s      500-520kB/s
548 P100 client 3Com card:    390-410kB/s      490-510kB/s
549 DX4-75 client NE2000:     370-380kB/s      330-350kB/s</P
550 ><P
551 >I based these test on transfer two files a 4.5MB text file and a 15MB 
552 textfile. The results arn't bad considering the hardware Samba is 
553 running on. It's a crap machine!!!!</P
554 ><P
555 >The updates mentioned in 1 and 2 brought up the transfer rates from 
556 just over 100kB/s in some clients.</P
557 ><P
558 >A new client is a P333 connected via a 100MB/s card and hub. The 
559 transfer rates from this were good: 450-500kB/s on put and 600+kB/s 
560 on get.</P
561 ><P
562 >Looking at standard FTP throughput, Samba is a bit slower (100kB/s 
563 upwards). I suppose there is more going on in the samba protocol, but 
564 if it could get up to the rate of FTP the perfomance would be quite 
565 staggering.</P
566 ></DIV
567 ><DIV
568 CLASS="SECT1"
569 ><H1
570 CLASS="SECT1"
571 ><A
572 NAME="AEN2860"
573 ></A
574 >17.17. My Results</H1
575 ><P
576 >Some people want to see real numbers in a document like this, so here
577 they are. I have a 486sx33 client running WfWg 3.11 with the 3.11b
578 tcp/ip stack. It has a slow IDE drive and 20Mb of ram. It has a SMC
579 Elite-16 ISA bus ethernet card. The only WfWg tuning I've done is to
580 set DefaultRcvWindow in the [MSTCP] section of system.ini to 16384. My
581 server is a 486dx3-66 running Linux. It also has 20Mb of ram and a SMC
582 Elite-16 card. You can see my server config in the examples/tridge/
583 subdirectory of the distribution.</P
584 ><P
585 >I get 490k/s on reading a 8Mb file with copy.
586 I get 441k/s writing the same file to the samba server.</P
587 ><P
588 >Of course, there's a lot more to benchmarks than 2 raw throughput
589 figures, but it gives you a ballpark figure.</P
590 ><P
591 >I've also tested Win95 and WinNT, and found WinNT gave me the best
592 speed as a samba client. The fastest client of all (for me) is
593 smbclient running on another linux box. Maybe I'll add those results
594 here someday ...</P
595 ></DIV
596 ></DIV
597 ><DIV
598 CLASS="NAVFOOTER"
599 ><HR
600 ALIGN="LEFT"
601 WIDTH="100%"><TABLE
602 SUMMARY="Footer navigation table"
603 WIDTH="100%"
604 BORDER="0"
605 CELLPADDING="0"
606 CELLSPACING="0"
607 ><TR
608 ><TD
609 WIDTH="33%"
610 ALIGN="left"
611 VALIGN="top"
612 ><A
613 HREF="browsing-quick.html"
614 ACCESSKEY="P"
615 >Prev</A
616 ></TD
617 ><TD
618 WIDTH="34%"
619 ALIGN="center"
620 VALIGN="top"
621 ><A
622 HREF="samba-howto-collection.html"
623 ACCESSKEY="H"
624 >Home</A
625 ></TD
626 ><TD
627 WIDTH="33%"
628 ALIGN="right"
629 VALIGN="top"
630 ><A
631 HREF="cvs-access.html"
632 ACCESSKEY="N"
633 >Next</A
634 ></TD
635 ></TR
636 ><TR
637 ><TD
638 WIDTH="33%"
639 ALIGN="left"
640 VALIGN="top"
641 >Quick Cross Subnet Browsing / Cross Workgroup Browsing guide</TD
642 ><TD
643 WIDTH="34%"
644 ALIGN="center"
645 VALIGN="top"
646 >&nbsp;</TD
647 ><TD
648 WIDTH="33%"
649 ALIGN="right"
650 VALIGN="top"
651 >HOWTO Access Samba source code via CVS</TD
652 ></TR
653 ></TABLE
654 ></DIV
655 ></BODY
656 ></HTML
657 >