{"action":"created","issue":{"url":"https://api.github.com/repos/mcollina/mosca/issues/479","repository_url":"https://api.github.com/repos/mcollina/mosca","labels_url":"https://api.github.com/repos/mcollina/mosca/issues/479/labels{/name}","comments_url":"https://api.github.com/repos/mcollina/mosca/issues/479/comments","events_url":"https://api.github.com/repos/mcollina/mosca/issues/479/events","html_url":"https://github.com/mcollina/mosca/issues/479","id":155765330,"number":479,"title":"Potential memory leak","user":{"login":"anhldbk","id":3270746,"avatar_url":"https://avatars.githubusercontent.com/u/3270746?v=3","gravatar_id":"","url":"https://api.github.com/users/anhldbk","html_url":"https://github.com/anhldbk","followers_url":"https://api.github.com/users/anhldbk/followers","following_url":"https://api.github.com/users/anhldbk/following{/other_user}","gists_url":"https://api.github.com/users/anhldbk/gists{/gist_id}","starred_url":"https://api.github.com/users/anhldbk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anhldbk/subscriptions","organizations_url":"https://api.github.com/users/anhldbk/orgs","repos_url":"https://api.github.com/users/anhldbk/repos","events_url":"https://api.github.com/users/anhldbk/events{/privacy}","received_events_url":"https://api.github.com/users/anhldbk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-19T15:26:15Z","updated_at":"2016-05-20T00:38:23Z","closed_at":null,"body":"Thank all you guys for this great package.\r\n\r\nI'm performing some kind of stress testing on `Mosca`. The scenario is pretty simple. A client just sends many message to `Mosca`, and I will measure how `Mosca` utilizes CPU cores, memory...\r\n\r\nThe code is below:\r\n\r\n**Server**\r\n```javascript\r\nvar mosca = require('mosca');\r\nvar settings = {\r\n  port: 1884,\r\n  backend: {\r\n    type: 'redis',\r\n    redis: require('redis'),\r\n    db: 12,\r\n    port: 6379,\r\n    host: \"localhost\"\r\n  }\r\n};\r\nvar server = new mosca.Server(settings);\r\n\r\nserver.on('ready', function(){\r\n  console.log('Mosca server is up and running');  \r\n});\r\n```\r\n\r\n**Client**\r\n```javascript\r\nvar mqtt    = require('mqtt');\r\nvar endpoint = mqtt.connect({ host: 'localhost', port: 1884 });\r\n\r\nendpoint.on('connect', function () {\r\n  endpoint.subscribe('/topic');\r\n\r\n  setTimeout(function(){\r\n    var count = 0;\r\n    while(count++ < 100000000){\r\n      endpoint.publish('/topic', 'tada'+count);\r\n    }\r\n  }, 1000);\r\n});\r\n\r\nendpoint.on('message', function (topic, message) {\r\n  console.log(message.toString());\r\n});\r\n```\r\n\r\nThere are several things worth to mention:\r\n+ The server's memory usage gradually increases\r\n+ If I terminate the client, the memory usage above stays the same\r\n\r\nSometimes, I've got some nasty exceptions:\r\n**Server**\r\n![screenshot from 2016-05-19 22-21-45](https://cloud.githubusercontent.com/assets/3270746/15399118/9e15d786-1e10-11e6-84d3-250027d68369.png)\r\n\r\n**Client**\r\n![screenshot from 2016-05-19 22-21-32](https://cloud.githubusercontent.com/assets/3270746/15399121/a10af08e-1e10-11e6-9ecb-9f5894ae9f1c.png)\r\n\r\nWould you pls tell me what wrong is?"},"comment":{"url":"https://api.github.com/repos/mcollina/mosca/issues/comments/220489311","html_url":"https://github.com/mcollina/mosca/issues/479#issuecomment-220489311","issue_url":"https://api.github.com/repos/mcollina/mosca/issues/479","id":220489311,"user":{"login":"anhldbk","id":3270746,"avatar_url":"https://avatars.githubusercontent.com/u/3270746?v=3","gravatar_id":"","url":"https://api.github.com/users/anhldbk","html_url":"https://github.com/anhldbk","followers_url":"https://api.github.com/users/anhldbk/followers","following_url":"https://api.github.com/users/anhldbk/following{/other_user}","gists_url":"https://api.github.com/users/anhldbk/gists{/gist_id}","starred_url":"https://api.github.com/users/anhldbk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anhldbk/subscriptions","organizations_url":"https://api.github.com/users/anhldbk/orgs","repos_url":"https://api.github.com/users/anhldbk/repos","events_url":"https://api.github.com/users/anhldbk/events{/privacy}","received_events_url":"https://api.github.com/users/anhldbk/received_events","type":"User","site_admin":false},"created_at":"2016-05-20T00:38:23Z","updated_at":"2016-05-20T00:38:23Z","body":"@mcollina So you recommend me to modify the client to be like:\r\n\r\n```javascript\r\nendpoint.on('connect', function () {\r\n  console.log('connected');\r\n  endpoint.subscribe('/topic');\r\n\r\n  setTimeout(function(){\r\n      var count = 0;\r\n      var fn = function(){\r\n          endpoint.publish('/topic', 'tada'+ count, callback=function(){\r\n            console.log(count)\r\n            count += 1\r\n            fn()\r\n          })\r\n      }\r\n      fn()\r\n  }, 1000);\r\n});\r\n```\r\nBtw, I'm using `redis` v3.2 and my `package.json` has `redis\": \"^2.6.0-2\"`"}}
{"actor":{"display_login":"anhldbk"}}