1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5 >Samba performance issues</TITLE
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.77"><LINK
10 TITLE="SAMBA Project Documentation"
11 HREF="samba-howto-collection.html"><LINK
13 TITLE="Quick Cross Subnet Browsing / Cross Workgroup Browsing guide"
14 HREF="browsing-quick.html"><LINK
16 TITLE="HOWTO Access Samba source code via CVS"
17 HREF="cvs-access.html"></HEAD
28 SUMMARY="Header navigation table"
37 >SAMBA Project Documentation</TH
45 HREF="browsing-quick.html"
59 HREF="cvs-access.html"
74 >Chapter 17. Samba performance issues</H1
82 >17.1. Comparisons</H1
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
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
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
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
121 >17.2.1. Overview</H2
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
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
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
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
157 >17.2.2. Level2 Oplocks</H2
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
166 >level2 oplocks = true</B
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
181 >17.2.3. Old 'fake oplocks' option - deprecated</H2
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
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
202 >17.3. Socket options</H1
204 >There are a number of socket options that can greatly affect the
205 performance of a TCP based server like Samba.</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
210 >The "socket options" section of the smb.conf manual page describes how
211 to set these and gives recommendations.</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
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
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
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
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
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
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
270 >In most cases the default is the best option.</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
286 >The performance hit will probably be greater on NFS mounted
287 filesystems, but could be quite high even on local disks.</P
296 >17.7. Share modes</H1
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
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
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
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
340 >17.9. Wide lines</H1
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
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
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
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
376 >17.11. Write raw</H1
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
383 >Some machines may find "write raw" slower than normal write, in which
384 case you may wish to change this option.</P
393 >17.12. Read prediction</H1
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
400 >This is disabled by default. You can enable it by using "read
401 prediction = yes".</P
403 >Note that read prediction is only used on files that were opened read
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
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
419 >17.13. Memory mapping</H1
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
425 >To enable you you have to recompile Samba with the -DUSE_MMAP option
426 on the FLAGS line of the Makefile.</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 =
440 >17.14. Slow Clients</H1
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
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
457 >17.15. Slow Logins</H1
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
470 >17.16. Client tuning</H1
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
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
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
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
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
493 >Paul Cochrane has done some testing on client side tuning and come
494 to the following conclusions:</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
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
517 >MTUAutoDiscover Disable</P
521 >MTUBlackHoleDetect Disable</P
525 >Time To Live Enabled</P
529 >Time To Live - HOPS 32</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
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
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
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
555 >The updates mentioned in 1 and 2 brought up the transfer rates from
556 just over 100kB/s in some clients.</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
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
574 >17.17. My Results</H1
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
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
588 >Of course, there's a lot more to benchmarks than 2 raw throughput
589 figures, but it gives you a ballpark figure.</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
602 SUMMARY="Footer navigation table"
613 HREF="browsing-quick.html"
622 HREF="samba-howto-collection.html"
631 HREF="cvs-access.html"
641 >Quick Cross Subnet Browsing / Cross Workgroup Browsing guide</TD
651 >HOWTO Access Samba source code via CVS</TD