{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/12083","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/12083/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/12083/comments","events_url":"https://api.github.com/repos/apache/spark/issues/12083/events","html_url":"https://github.com/apache/spark/pull/12083","id":144848675,"number":12083,"title":"[SPARK-14290][CORE][Network] avoid significant memory copy in netty's transferTo","user":{"login":"liyezhang556520","id":4716022,"avatar_url":"https://avatars.githubusercontent.com/u/4716022?v=3","gravatar_id":"","url":"https://api.github.com/users/liyezhang556520","html_url":"https://github.com/liyezhang556520","followers_url":"https://api.github.com/users/liyezhang556520/followers","following_url":"https://api.github.com/users/liyezhang556520/following{/other_user}","gists_url":"https://api.github.com/users/liyezhang556520/gists{/gist_id}","starred_url":"https://api.github.com/users/liyezhang556520/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liyezhang556520/subscriptions","organizations_url":"https://api.github.com/users/liyezhang556520/orgs","repos_url":"https://api.github.com/users/liyezhang556520/repos","events_url":"https://api.github.com/users/liyezhang556520/events{/privacy}","received_events_url":"https://api.github.com/users/liyezhang556520/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-31T09:58:11Z","updated_at":"2016-03-31T19:20:58Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/12083","html_url":"https://github.com/apache/spark/pull/12083","diff_url":"https://github.com/apache/spark/pull/12083.diff","patch_url":"https://github.com/apache/spark/pull/12083.patch"},"body":"## What changes were proposed in this pull request?\r\nWhen netty transfer data that is not `FileRegion`, data will be in format of `ByteBuf`, If the data is large, there will occur significant performance issue because there is memory copy underlying in `sun.nio.ch.IOUtil.write`, the CPU is 100% used, and network is very low.\r\n\r\nIn this PR, if data size is large, we will split it into small chunks to call `WritableByteChannel.write()`, so that avoid wasting of memory copy. Because the data can't be written within a single write, and it will call `transferTo` multiple times. \r\n\r\n## How was this patch tested?\r\nSpark unit test and manual test.\r\nManual test:\r\nsc.parallelize(Array(1,2,3),3).mapPartitions(a=>Array(new Array[Double](1024 * 1024 * 50)).iterator).reduce((a,b)=> a).length\r\n\r\nFor more details, please refer to [SPARK-14290](https://issues.apache.org/jira/browse/SPARK-14290)\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/204087239","html_url":"https://github.com/apache/spark/pull/12083#issuecomment-204087239","issue_url":"https://api.github.com/repos/apache/spark/issues/12083","id":204087239,"user":{"login":"andrewor14","id":2133137,"avatar_url":"https://avatars.githubusercontent.com/u/2133137?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewor14","html_url":"https://github.com/andrewor14","followers_url":"https://api.github.com/users/andrewor14/followers","following_url":"https://api.github.com/users/andrewor14/following{/other_user}","gists_url":"https://api.github.com/users/andrewor14/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewor14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewor14/subscriptions","organizations_url":"https://api.github.com/users/andrewor14/orgs","repos_url":"https://api.github.com/users/andrewor14/repos","events_url":"https://api.github.com/users/andrewor14/events{/privacy}","received_events_url":"https://api.github.com/users/andrewor14/received_events","type":"User","site_admin":false},"created_at":"2016-03-31T19:20:58Z","updated_at":"2016-03-31T19:20:58Z","body":"@zswxing"}}