{"action":"closed","issue":{"url":"https://api.github.com/repos/net-ssh/net-ssh/issues/113","labels_url":"https://api.github.com/repos/net-ssh/net-ssh/issues/113/labels{/name}","comments_url":"https://api.github.com/repos/net-ssh/net-ssh/issues/113/comments","events_url":"https://api.github.com/repos/net-ssh/net-ssh/issues/113/events","html_url":"https://github.com/net-ssh/net-ssh/issues/113","id":17503388,"number":113,"title":"PacketStream#next_packet(:nonblock)  is not able to sustain data arrival rate is more than one packet","user":{"login":"huy","id":18898,"avatar_url":"https://avatars.githubusercontent.com/u/18898?v=3","gravatar_id":"","url":"https://api.github.com/users/huy","html_url":"https://github.com/huy","followers_url":"https://api.github.com/users/huy/followers","following_url":"https://api.github.com/users/huy/following{/other_user}","gists_url":"https://api.github.com/users/huy/gists{/gist_id}","starred_url":"https://api.github.com/users/huy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huy/subscriptions","organizations_url":"https://api.github.com/users/huy/orgs","repos_url":"https://api.github.com/users/huy/repos","events_url":"https://api.github.com/users/huy/events{/privacy}","received_events_url":"https://api.github.com/users/huy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2013-08-01T12:00:27Z","updated_at":"2015-02-12T09:32:32Z","closed_at":"2015-02-12T09:32:32Z","body":"The current code first read all available data from socket into an internal buffer then pull out data from the buffer equivalent one packet so if data arrives at rate higher than size of one packet, it never been consumed, worse process spend most of time extend buffer and copy data into exhausting cpu and memory . \r\n\r\nThe code should be probably modified like that \r\n\r\n    def next_packet(mode=:nonblock)\r\n      case mode\r\n      when :nonblock then\r\n        packet = poll_next_packet # pull out and return a packet if there is any\r\n        return packet if packet\r\n\r\n        fill if available_for_read? # if not fill a buffer and try again, give up if there is still no data in the buffer\r\n        poll_next_packet\r\n\r\n"}}