{"id":3318,"date":"2013-10-08T14:00:54","date_gmt":"2013-10-08T19:00:54","guid":{"rendered":"http:\/\/icesquare.com\/wordpress\/?p=3318"},"modified":"2014-07-06T18:35:56","modified_gmt":"2014-07-06T23:35:56","slug":"how-to-improve-rsync-performance","status":"publish","type":"post","link":"https:\/\/icesquare.com\/wordpress\/how-to-improve-rsync-performance\/","title":{"rendered":"How to Improve rsync Performance"},"content":{"rendered":"<p>I need to transfer 10TB of data from one machine to another machine. Those 10TB of files are living in a large RAID which span across 7 different disks. The target machine has another large RAID which span across 12 different disks. It is not easy to copying those files locally. Therefore, I decide to copy the files over the LAN.<\/p>\n<p>There are four options popping up in my head: <strong>scp<\/strong>, <strong>rsync<\/strong>, <strong>rsyncd (rsync as daemon)<\/strong> and <strong>netcat<\/strong>.<\/p>\n<div style=\"margin-bottom:80px;\"><\/div>\n<h2>scp<\/h2>\n<p>scp is handy, easy to use but comes with two disadvantages: slow and not fault-tolerant. Since scp comes with the highest security, all data are encrypted before the transfer. It will slow down the overall performance because of the extra encryption stuffs (which makes the data larger), and extra computational resource (which uses more CPU). If the transfer is interrupted, there is no easy way to resume the process other than transferring everything again. Here are some example commands:<\/p>\n<pre>\r\n#Source machine\r\n#Typical speed is about 20 to 30MB\/s\r\nscp -r \/data target_machine:\/data\r\n\r\n#Or you can enable the compression on the fly\r\n#Depending on the type of your data, if your data is already compressed, you may see no or negative speed improvement\r\nscp -rC \/data target_machine:\/data\r\n<\/pre>\n<h2>rsync<\/h2>\n<p>rsync is similar to scp. It comes with the encryption (via SSH) such that the data is safe. It also allows you to transfer the newer files only. This will reduce the amount of data being transferred. However, it comes with few disadvantages: long decision time, encryption (which increase the size of overhead) and extra computational resource(e.g., data comparison, encryption and decryption etc). For example, if I use rsync to transfer 10TB of files from one machine to another machine (where the directory on the target machine is blank), it can easily take 5 hours to determine which files will need to be transferred before the actual data transfer is initialized.<\/p>\n<pre>\r\n#Run on the target machine\r\nrsync -avzr -e ssh --delete-after source_machine:\/data\/ \/data\/\r\n\r\n#Use a less secure encryption algorithm to speed up the process\r\nrsync -avzr --rsh=\"ssh -c blowfish\" --delete-after source_machine:\/data\/ \/data\/\r\n\r\n#Use an even less secure algorithm to get the top speed\r\nrsync -avzr --rsh=\"ssh -c arcfour\" --delete-after source_machine:\/data\/ \/data\/\r\n\r\n#By default, rsync compares the files using checksum, file size and modification date.\r\n#Reduce the decision process by skipping the hash check\r\nrsync -avzr --rsh=\"ssh -c arcfour\" --delete-after --whole-file source_machine:\/data\/ \/data\/\r\n<\/pre>\n<p>Anyway, no matter what you do, the top speed of rsync in a consumer-grade gigabit network is around 45MB\/s. On average, the speed is around 25-35MB\/s. Keep in mind that this number does not include the decision time, which can be few hours.<\/p>\n<h2>rsyncd (rsync as a daemon)<\/h2>\n<p>Thanks for the comment of our reader. I got a chance to investigate the rsync as a daemon. Basically, the idea of running rsync as a daemon is similar to rsync. On the server, we run rsync as a service\/daemon. We specify which directory we want to &#8220;export&#8221; to the clients (e.g., \/usr\/ports). When the files get changed on the server, it records the changes so that the when the clients talk to the server, the decision time will be faster. Here is how to set up rsync server on FreeBSD<\/p>\n<pre>\r\nsudo nano \/usr\/local\/etc\/rsyncd.conf\r\n<\/pre>\n<p>And this is my configuration file:<\/p>\n<pre>\r\npid file = \/var\/run\/rsyncd.pid\r\n\r\n#Notice that I use derrick here instead of other systems users, such as nobody\r\n#That's because nobody does not have permission to access the path, i.e., \/data\/\r\n#Either you make the source directory available to \"nobody\", or you change the daemon user.\r\nuid = derrick\r\ngid = derrick\r\nuse chroot = no\r\nmax connections = 4\r\nsyslog facility = local5\r\npid file = \/var\/run\/rsyncd.pid\r\n\r\n[mydata]\r\n   path = \/data\/\r\n   comment = data\r\n<\/pre>\n<pre>\r\nDon't forget to include the following in \/etc\/rc.conf, so that the service will be started automatically.\r\n\r\nrsyncd_enable=\"YES\"\r\n<\/pre>\n<pre>\r\n#Let's start the rsync service:\r\n\r\nsudo \/usr\/local\/etc\/rc.d\/rsyncd start\r\n\r\n<\/pre>\n<p>To pull the files from the server to the clients, run the following:<\/p>\n<pre>\r\nrsync -av myserver::mydata \/data\/\r\n\r\n#Or you can enable compression\r\nrsync -avz myserver::mydata \/data\/\r\n<\/pre>\n<p>To my surprise, it works much better than running rsync alone. Here are some data I collected during transferring 10TB files from ZFS to ZFS:<\/p>\n<p>Bandwidth measured on the client machine: 70MB\/s<\/p>\n<p>zpool IO speed on the client side: 75MB\/s<\/p>\n<p>P.S. Initially, the speed was about 45-60MB\/s, after I tweak my Zpool, I can get the top speed to 75-80MB\/s. Please check out <a href=\"\/wordpress\/how-to-improve-zfs-performance\/\">here<\/a> for references.<\/p>\n<p>I notice that the decision time is much faster than running rsync alone. Also the process is much more stable, with zero interruption, i.e., <\/p>\n<pre>\r\nrsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at io.c(521) [receiver=3.1.0]\r\nrsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [generator=3.1.0]\r\nrsync: [receiver] write error: Broken pipe (32)\r\n<\/pre>\n<h2>NetCat<\/h2>\n<p>NetCat is similar to cat, except that it works at the network level. I decide to use netcat for the initial transfer. If it is interrupted, I will let rsync to kick in the process. Netcat does not encrypt the data, so the overhead is very small. If you transfer the file within a local network and you don&#8217;t care about the security, netcat is a perfect choice.<\/p>\n<p>There is only one disadvantage of using netcat. It can only handle one file at a time. It doesn&#8217;t mean you need to run netcat for every single file. Instead, we can tar the file before feeding to netcat, and untar the file at the receiving end. As long as we do not compress the files, we can keep the CPU usage small.\n<\/p>\n<pre>\r\n#Open two terminals, one for the source and another one for the target machine.\r\n\r\n#On the target machine:\r\n#Go to the directory, e.g., \r\ncd \/data\r\n\r\n#Run the following:\r\nnc -l 9999| tar xvfp -\r\n\r\n#On the source machine:\r\n#Go to the directory, e.g.,\r\ncd \/data\r\n\r\n#Pick a port number that is not being used, e.g., 9999\r\ntar -cf - . | nc target_machine 9999\r\n<\/pre>\n<p>Unlike rsync, the process will start right the way, and the maximum speed is around 45 to 60MB\/s in a gigabit network.<\/p>\n<h2>Conclusion<\/h2>\n<style>\n.tableHeader{\n   border:1px dashed #666; padding:5px; font-weight:bold; font-size:15px;\n}\n.tableContent{\n   border:1px dashed #666; padding:10px; font-weight:bold; font-size:13px;\n}\n<\/style>\n<table style=\"border:1px dashed #666; padding:5px; margin:10px;\">\n<tr>\n<td class=\"tableHeader\">Candidates<\/td>\n<td class=\"tableHeader\">Top Speed (w\/o compression)<\/td>\n<td class=\"tableHeader\">Top Speed (w\/ compression)<\/td>\n<td class=\"tableHeader\">Resume<\/td>\n<td class=\"tableHeader\">Stability<\/td>\n<td class=\"tableHeader\">Instant Start?<\/td>\n<\/tr>\n<tr>\n<td class=\"tableContent\">scp<\/td>\n<td class=\"tableContent\">40MB\/s<\/td>\n<td class=\"tableContent\">25MB\/s<\/td>\n<td class=\"tableContent\">No<\/td>\n<td class=\"tableContent\">Low<\/td>\n<td class=\"tableContent\">Instant<\/td>\n<\/tr>\n<tr>\n<td class=\"tableContent\">rsync<\/td>\n<td class=\"tableContent\">25MB\/s<\/td>\n<td class=\"tableContent\">50MB\/s<\/td>\n<td class=\"tableContent\">Yes<\/td>\n<td class=\"tableContent\">Medium<\/td>\n<td class=\"tableContent\">Long Preparation<\/td>\n<\/tr>\n<tr>\n<td class=\"tableContent\">rsyncd<\/td>\n<td class=\"tableContent\">30MB\/s<\/td>\n<td class=\"tableContent\">70MB\/s<\/td>\n<td class=\"tableContent\">Yes<\/td>\n<td class=\"tableContent\">High<\/td>\n<td class=\"tableContent\">Short Preparation<\/td>\n<\/tr>\n<tr>\n<td class=\"tableContent\">netcat<\/td>\n<td class=\"tableContent\">60MB\/s (tar w\/o -z)<\/td>\n<td class=\"tableContent\">40MB\/s (tar w\/ -z)<\/td>\n<td class=\"tableContent\">No<\/td>\n<td class=\"tableContent\">Very High<\/td>\n<td class=\"tableContent\">Instant<\/td>\n<\/tr>\n<\/table>\n<p>&#8211;Derrick<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I need to transfer 10TB of data from one machine to another machine. Those 10TB of files are living in a large RAID which span across 7 different disks. The <a class=\"more-link\" href=\"https:\/\/icesquare.com\/wordpress\/how-to-improve-rsync-performance\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":3476,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7,144,6],"tags":[171,48,160,159],"class_list":["post-3318","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-freebsd","category-sever-problem","category-technology","tag-freebsd","tag-linux","tag-nc","tag-netcat"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p1sqzr-Rw","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3438,"url":"https:\/\/icesquare.com\/wordpress\/zfs-performance-boostimprovement-how-i-push-the-io-speed-to-126mbps\/","url_meta":{"origin":3318,"position":0},"title":"ZFS Performance Boost\/Improvement: How I push the I\/O speed to 126MBps","author":"Derrick","date":"January 25, 2014","format":false,"excerpt":"This article is part of my main ZFS tutorial: How to improve ZFS performance. That article covers everything you need. If you already have the basic knowledge, or you just want to know how I push the I\/O speed to 120+ MBps, you can skip that article and read this\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/icesquare.com\/wordpress\/wp-content\/uploads\/2014\/02\/speedometer.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/icesquare.com\/wordpress\/wp-content\/uploads\/2014\/02\/speedometer.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/icesquare.com\/wordpress\/wp-content\/uploads\/2014\/02\/speedometer.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/icesquare.com\/wordpress\/wp-content\/uploads\/2014\/02\/speedometer.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/icesquare.com\/wordpress\/wp-content\/uploads\/2014\/02\/speedometer.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":3447,"url":"https:\/\/icesquare.com\/wordpress\/zfs-compression-lz4-vs-lzjb\/","url_meta":{"origin":3318,"position":1},"title":"ZFS Compression: lz4 VS lzjb","author":"Derrick","date":"January 26, 2014","format":false,"excerpt":"ZFS offers a new compression method in the latest version: lz4. It claims to be better than lzjb. Since lzjb is pretty good already, I am curious to find out how good will lz4 be comparing to lzjb. According to my tests, lz4 is performing better than lzjb in terms\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1214,"url":"https:\/\/icesquare.com\/wordpress\/building-a-super-large-and-reliable-file-server-with-mixed-size-of-harddisks\/","url_meta":{"origin":3318,"position":2},"title":"Building a Super Large and Reliable File Server with Mixed Size of Harddisks","author":"Derrick","date":"January 17, 2011","format":false,"excerpt":"In this article, I am going to show you how to build a super large, ultra reliable, expandable file server with mixed size of hard drives. Here is my criteria: Large Storage Capacity. At this moment, the largest hard drive is 2TB. I am looking for at least 10TB. Great\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"\/wordpress\/wp-content\/uploads\/2011\/01\/zfs_logo-150x150.jpg","width":350,"height":200},"classes":[]},{"id":3736,"url":"https:\/\/icesquare.com\/wordpress\/this-rsync-lacks-old-style-compress-due-to-its-external-zlib-try-zz\/","url_meta":{"origin":3318,"position":3},"title":"This rsync lacks old-style &#8211;compress due to its external zlib.  Try -zz.","author":"Derrick","date":"September 15, 2014","format":false,"excerpt":"When I tried to run rsync (3.1.1) on my FreeBSD box today, the following message caught my attention: #rsync -avzr --rsh=\"ssh -c arcfour\" --delete --compress-level=9 sourcemachine:\/source\/ \/target\/ This rsync lacks old-style --compress due to its external zlib. Try -zz. Continuing without compression. Basically, rsync suggests that you should use the\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3551,"url":"https:\/\/icesquare.com\/wordpress\/how-to-expand-zfs\/","url_meta":{"origin":3318,"position":4},"title":"How to Expand ZFS","author":"Derrick","date":"June 23, 2014","format":false,"excerpt":"Today I am going to share my story with you on how to expand my ZFS storage. I have a giant ZFS pool, which consists of 8x2TB (RAIDZ2) and 4x1.5TB (RAIDZ1), with a total of 15TB usable spaces. Since I am running out of space, I decide to upgrade the\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1380,"url":"https:\/\/icesquare.com\/wordpress\/how-to-improve-zfs-performance\/","url_meta":{"origin":3318,"position":5},"title":"How to Improve ZFS performance","author":"Derrick","date":"August 24, 2014","format":false,"excerpt":"First Edition: March 14, 2010 Last Edited: January 10, 2026 \u00a0 In this tutorial, I will show you how to improve the performance of your ZFS using the affordable consumer-grade hardware (e.g., Gigabit network card, standard SATA non-SSD hard drives, consumer-grade motherboard etc.). Many people found a problem on their\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/icesquare.com\/wordpress\/wp-content\/uploads\/2011\/01\/zfs_logo.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_featured_media_url":"https:\/\/icesquare.com\/wordpress\/wp-content\/uploads\/2014\/02\/speedometer.jpg","_links":{"self":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/3318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3318"}],"version-history":[{"count":24,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/3318\/revisions"}],"predecessor-version":[{"id":3649,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/3318\/revisions\/3649"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/media\/3476"}],"wp:attachment":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}