{"action":"created","issue":{"url":"https://api.github.com/repos/rogerwang/node-webkit/issues/2899","labels_url":"https://api.github.com/repos/rogerwang/node-webkit/issues/2899/labels{/name}","comments_url":"https://api.github.com/repos/rogerwang/node-webkit/issues/2899/comments","events_url":"https://api.github.com/repos/rogerwang/node-webkit/issues/2899/events","html_url":"https://github.com/rogerwang/node-webkit/issues/2899","id":53396145,"number":2899,"title":"Streaming Response and WritingFile via fileStream, UTILIZES 100% cpu in Mac Maverics/Yosemite","user":{"login":"kamesh-a","id":3531949,"avatar_url":"https://avatars.githubusercontent.com/u/3531949?v=3","gravatar_id":"","url":"https://api.github.com/users/kamesh-a","html_url":"https://github.com/kamesh-a","followers_url":"https://api.github.com/users/kamesh-a/followers","following_url":"https://api.github.com/users/kamesh-a/following{/other_user}","gists_url":"https://api.github.com/users/kamesh-a/gists{/gist_id}","starred_url":"https://api.github.com/users/kamesh-a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kamesh-a/subscriptions","organizations_url":"https://api.github.com/users/kamesh-a/orgs","repos_url":"https://api.github.com/users/kamesh-a/repos","events_url":"https://api.github.com/users/kamesh-a/events{/privacy}","received_events_url":"https://api.github.com/users/kamesh-a/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"rogerwang","id":165401,"avatar_url":"https://avatars.githubusercontent.com/u/165401?v=3","gravatar_id":"","url":"https://api.github.com/users/rogerwang","html_url":"https://github.com/rogerwang","followers_url":"https://api.github.com/users/rogerwang/followers","following_url":"https://api.github.com/users/rogerwang/following{/other_user}","gists_url":"https://api.github.com/users/rogerwang/gists{/gist_id}","starred_url":"https://api.github.com/users/rogerwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rogerwang/subscriptions","organizations_url":"https://api.github.com/users/rogerwang/orgs","repos_url":"https://api.github.com/users/rogerwang/repos","events_url":"https://api.github.com/users/rogerwang/events{/privacy}","received_events_url":"https://api.github.com/users/rogerwang/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2015-01-05T13:33:57Z","updated_at":"2015-01-07T14:34:39Z","closed_at":null,"body":"Hello,\r\nWe wrote a sample file download snippet, while creating request  and piping the response to file stream, cpu utilization in MAC goes beyond 100%, Once file download is completed, node-webkit cpu usage rate reduces down to normal state.\r\n\r\nWe have tried in Windows 8, high cpu usage is not happening. \r\n\r\nConfig Info :\r\nMac: Testing in both Maverics and yosemite\r\nEngine used : 0.10.6, 0.11.x that includes latest 0.11.5 Build.\r\n\r\ncode snippet:\r\n```\r\nvar http = require('http');\r\nvar fs = require('fs');\r\nvar path = require('path');\r\n\r\nfunction download(url, callback) {\r\n\r\n    var dest;\r\n\r\n    if(/darwin/.test(process.platform))\r\n        dest = path.join(process.env.HOME,'Downloads',path.basename(url));\r\n    else if(/^win/.test(process.platform))\r\n        dest = path.join( process.env.HOMEDRIVE, process.env.HOMEPATH,'Downloads',path.basename(url));\r\n    else{\r\n        console.warn('Platform is not Win/Mac');\r\n        return;\r\n    }\r\n\r\n    var file = fs.createWriteStream(dest);\r\n\r\n    var request = http.get(url, function(response) {\r\n        \r\n        response.pipe(file);\r\n\r\n        var len = parseInt(response.headers['content-length'] || response.headers['x-goog-stored-content-length'], 10);\r\n        var total = len / 1048576;\r\n        var cur = 0;\r\n        \r\n        response.on(\"data\", function(chunk) {\r\n            cur += chunk.length;\r\n            console.log(\"Downloading \" + (100.0 * cur / len).toFixed(2) + \"% \" + (cur / 1048576).toFixed(2) + \" mb\\r\" + \" Total size: \" + total.toFixed(2) + \" mb\")\r\n        });\r\n\r\n        file.on('finish', function() {\r\n            file.close(); // close() is async, call callback after close completes.\r\n            if (callback)\r\n                callback('success');\r\n        });\r\n\r\n        file.on('error', function(err) {\r\n            fs.unlink(dest); // Delete the file async. (But we don't check the result)\r\n            if (callback)\r\n                callback(err.message);\r\n        });\r\n    });\r\n}\r\n\r\ndownload('http://dl.node-webkit.org/v0.11.5/node-webkit-v0.11.5-osx-ia32.zip',function({console.error(arguments)});\r\n\r\n```\r\n\r\n![cpu_112_percentage_node_webkit](https://cloud.githubusercontent.com/assets/3531949/5613610/068fa21c-950d-11e4-92b5-2a8c9646a9e3.png)\r\n\r\nPlease let us know if any way we can assist.\r\n\r\n\r\n<bountysource-plugin>\r\n\r\n---\r\nWant to back this issue? **[Place a bounty on it!](https://www.bountysource.com/issues/7495855-streaming-response-and-writingfile-via-filestream-utilizes-100-cpu-in-mac-maverics-yosemite?utm_campaign=plugin&utm_content=tracker%2F51989&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F51989&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/rogerwang/node-webkit/issues/comments/69029208","html_url":"https://github.com/rogerwang/node-webkit/issues/2899#issuecomment-69029208","issue_url":"https://api.github.com/repos/rogerwang/node-webkit/issues/2899","id":69029208,"user":{"login":"iwege","id":504272,"avatar_url":"https://avatars.githubusercontent.com/u/504272?v=3","gravatar_id":"","url":"https://api.github.com/users/iwege","html_url":"https://github.com/iwege","followers_url":"https://api.github.com/users/iwege/followers","following_url":"https://api.github.com/users/iwege/following{/other_user}","gists_url":"https://api.github.com/users/iwege/gists{/gist_id}","starred_url":"https://api.github.com/users/iwege/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iwege/subscriptions","organizations_url":"https://api.github.com/users/iwege/orgs","repos_url":"https://api.github.com/users/iwege/repos","events_url":"https://api.github.com/users/iwege/events{/privacy}","received_events_url":"https://api.github.com/users/iwege/received_events","type":"User","site_admin":false},"created_at":"2015-01-07T14:34:39Z","updated_at":"2015-01-07T14:34:39Z","body":"I have run this testcase with  two files ( 900mb, 68mb).\r\nTest Environment:\r\nnw       : 0.11.5 ia32\r\nOS X   :  10.10.1\r\nCPU    : 2.2 GHz Intel Core i7\r\nMemory: 16 GB 1600 MHz DDR3\r\nBandwidth: 3 - 4mbps\r\n\r\nmy result:\r\n900mb 5 times keeps 30% ~ 34% cpu usage.\r\n68mb 2/5 reached 90%, usually 25%.\r\n\r\nAnd I test this code with node 0.11.14, the cpu usage is only 4% ~ 8%."}}