{"action":"closed","number":44,"pull_request":{"url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls/44","id":50731257,"html_url":"https://github.com/bangalore-haskell-user-group/functorrent/pull/44","diff_url":"https://github.com/bangalore-haskell-user-group/functorrent/pull/44.diff","patch_url":"https://github.com/bangalore-haskell-user-group/functorrent/pull/44.patch","issue_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues/44","number":44,"state":"closed","locked":false,"title":"Concurrency support for functorrent","user":{"login":"jaseemabid","id":601714,"avatar_url":"https://avatars.githubusercontent.com/u/601714?v=3","gravatar_id":"","url":"https://api.github.com/users/jaseemabid","html_url":"https://github.com/jaseemabid","followers_url":"https://api.github.com/users/jaseemabid/followers","following_url":"https://api.github.com/users/jaseemabid/following{/other_user}","gists_url":"https://api.github.com/users/jaseemabid/gists{/gist_id}","starred_url":"https://api.github.com/users/jaseemabid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaseemabid/subscriptions","organizations_url":"https://api.github.com/users/jaseemabid/orgs","repos_url":"https://api.github.com/users/jaseemabid/repos","events_url":"https://api.github.com/users/jaseemabid/events{/privacy}","received_events_url":"https://api.github.com/users/jaseemabid/received_events","type":"User","site_admin":false},"body":"* Concurrency model, v1\r\n\r\nThis is a channel based approach for managing concurrency in Functorrent.\r\n\r\nThe rational is that keeping state in MVars and polling for them in a loop with\r\na sleep feels very counter intuitive.\r\n\r\nA channel based implementation is very similar to producer consumer model,\r\nmessage passing or Erlang's actor model.\r\n\r\nChannels are typed and can be drained in a blocking manner by a worker thread\r\nwith only a few lines of code. (See [FuncTorrent/Writer.hs](https://github.com/bangalore-haskell-user-group/functorrent/blob/concurrency/src/FuncTorrent/Writer.hs)) A `control thread`\r\n(CT) is spawned per torrent file. CT spawns a writer thread (WT) per file and a\r\npeer thread (PT) per peer. Peers report available blocks to control thread via\r\nthe `availability` channel. Control thread can schedule block downloads taking\r\ninto consideration the state of all active peers. We must be able to do some\r\nsmart scheduling here, like fetching a rare piece first. Requests to fetch\r\nblocks arrive peer threads via the `reader` channel, and a download thread\r\ndrains this channel and downloads a block at a time. Retrieved blocks are\r\nwritten to `writer` channel. Writer drains it to disk.\r\n\r\nA key advantage of the design is that a lot of the modules become stateless and\r\nsafe to be killed at any time. Peer thread is an example. It gets data from a\r\nchannel, writes data to another channel. A PT crash should be perfectly fine.\r\n\r\nA known issue is the inability to close channels at the moment. If the consumer\r\ndies, the producer ideally shouldn't be pushing more work in the same channel.\r\nThis might lead to silent issues.\r\n","created_at":"2015-11-14T20:19:59Z","updated_at":"2015-11-30T10:07:42Z","closed_at":"2015-11-30T10:07:42Z","merged_at":"2015-11-30T10:07:42Z","merge_commit_sha":"4a653b1834cbd0ac77a74ec047ae9d3715036ac3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls/44/commits","review_comments_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls/44/comments","review_comment_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues/44/comments","statuses_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/statuses/a05f5eca019e7930d8ad26b25b583fa020233e80","head":{"label":"bangalore-haskell-user-group:concurrency","ref":"concurrency","sha":"a05f5eca019e7930d8ad26b25b583fa020233e80","user":{"login":"bangalore-haskell-user-group","id":12463682,"avatar_url":"https://avatars.githubusercontent.com/u/12463682?v=3","gravatar_id":"","url":"https://api.github.com/users/bangalore-haskell-user-group","html_url":"https://github.com/bangalore-haskell-user-group","followers_url":"https://api.github.com/users/bangalore-haskell-user-group/followers","following_url":"https://api.github.com/users/bangalore-haskell-user-group/following{/other_user}","gists_url":"https://api.github.com/users/bangalore-haskell-user-group/gists{/gist_id}","starred_url":"https://api.github.com/users/bangalore-haskell-user-group/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bangalore-haskell-user-group/subscriptions","organizations_url":"https://api.github.com/users/bangalore-haskell-user-group/orgs","repos_url":"https://api.github.com/users/bangalore-haskell-user-group/repos","events_url":"https://api.github.com/users/bangalore-haskell-user-group/events{/privacy}","received_events_url":"https://api.github.com/users/bangalore-haskell-user-group/received_events","type":"Organization","site_admin":false},"repo":{"id":30867288,"name":"functorrent","full_name":"bangalore-haskell-user-group/functorrent","owner":{"login":"bangalore-haskell-user-group","id":12463682,"avatar_url":"https://avatars.githubusercontent.com/u/12463682?v=3","gravatar_id":"","url":"https://api.github.com/users/bangalore-haskell-user-group","html_url":"https://github.com/bangalore-haskell-user-group","followers_url":"https://api.github.com/users/bangalore-haskell-user-group/followers","following_url":"https://api.github.com/users/bangalore-haskell-user-group/following{/other_user}","gists_url":"https://api.github.com/users/bangalore-haskell-user-group/gists{/gist_id}","starred_url":"https://api.github.com/users/bangalore-haskell-user-group/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bangalore-haskell-user-group/subscriptions","organizations_url":"https://api.github.com/users/bangalore-haskell-user-group/orgs","repos_url":"https://api.github.com/users/bangalore-haskell-user-group/repos","events_url":"https://api.github.com/users/bangalore-haskell-user-group/events{/privacy}","received_events_url":"https://api.github.com/users/bangalore-haskell-user-group/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bangalore-haskell-user-group/functorrent","description":"A bit torrent client","fork":false,"url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent","forks_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/forks","keys_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/teams","hooks_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/hooks","issue_events_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues/events{/number}","events_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/events","assignees_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/assignees{/user}","branches_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/branches{/branch}","tags_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/tags","blobs_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/refs{/sha}","trees_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/statuses/{sha}","languages_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/languages","stargazers_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/stargazers","contributors_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/contributors","subscribers_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/subscribers","subscription_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/subscription","commits_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/commits{/sha}","git_commits_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/commits{/sha}","comments_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/comments{/number}","issue_comment_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues/comments{/number}","contents_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/contents/{+path}","compare_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/merges","archive_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/downloads","issues_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues{/number}","pulls_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls{/number}","milestones_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/milestones{/number}","notifications_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/labels{/name}","releases_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/releases{/id}","created_at":"2015-02-16T12:27:03Z","updated_at":"2015-11-17T00:37:21Z","pushed_at":"2015-11-30T10:07:42Z","git_url":"git://github.com/bangalore-haskell-user-group/functorrent.git","ssh_url":"git@github.com:bangalore-haskell-user-group/functorrent.git","clone_url":"https://github.com/bangalore-haskell-user-group/functorrent.git","svn_url":"https://github.com/bangalore-haskell-user-group/functorrent","homepage":null,"size":668,"stargazers_count":15,"watchers_count":15,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":10,"forks":10,"open_issues":10,"watchers":15,"default_branch":"master"}},"base":{"label":"bangalore-haskell-user-group:master","ref":"master","sha":"45b6952bb542e4f90a2b24ed186b18d139af28bd","user":{"login":"bangalore-haskell-user-group","id":12463682,"avatar_url":"https://avatars.githubusercontent.com/u/12463682?v=3","gravatar_id":"","url":"https://api.github.com/users/bangalore-haskell-user-group","html_url":"https://github.com/bangalore-haskell-user-group","followers_url":"https://api.github.com/users/bangalore-haskell-user-group/followers","following_url":"https://api.github.com/users/bangalore-haskell-user-group/following{/other_user}","gists_url":"https://api.github.com/users/bangalore-haskell-user-group/gists{/gist_id}","starred_url":"https://api.github.com/users/bangalore-haskell-user-group/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bangalore-haskell-user-group/subscriptions","organizations_url":"https://api.github.com/users/bangalore-haskell-user-group/orgs","repos_url":"https://api.github.com/users/bangalore-haskell-user-group/repos","events_url":"https://api.github.com/users/bangalore-haskell-user-group/events{/privacy}","received_events_url":"https://api.github.com/users/bangalore-haskell-user-group/received_events","type":"Organization","site_admin":false},"repo":{"id":30867288,"name":"functorrent","full_name":"bangalore-haskell-user-group/functorrent","owner":{"login":"bangalore-haskell-user-group","id":12463682,"avatar_url":"https://avatars.githubusercontent.com/u/12463682?v=3","gravatar_id":"","url":"https://api.github.com/users/bangalore-haskell-user-group","html_url":"https://github.com/bangalore-haskell-user-group","followers_url":"https://api.github.com/users/bangalore-haskell-user-group/followers","following_url":"https://api.github.com/users/bangalore-haskell-user-group/following{/other_user}","gists_url":"https://api.github.com/users/bangalore-haskell-user-group/gists{/gist_id}","starred_url":"https://api.github.com/users/bangalore-haskell-user-group/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bangalore-haskell-user-group/subscriptions","organizations_url":"https://api.github.com/users/bangalore-haskell-user-group/orgs","repos_url":"https://api.github.com/users/bangalore-haskell-user-group/repos","events_url":"https://api.github.com/users/bangalore-haskell-user-group/events{/privacy}","received_events_url":"https://api.github.com/users/bangalore-haskell-user-group/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bangalore-haskell-user-group/functorrent","description":"A bit torrent client","fork":false,"url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent","forks_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/forks","keys_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/teams","hooks_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/hooks","issue_events_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues/events{/number}","events_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/events","assignees_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/assignees{/user}","branches_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/branches{/branch}","tags_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/tags","blobs_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/refs{/sha}","trees_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/statuses/{sha}","languages_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/languages","stargazers_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/stargazers","contributors_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/contributors","subscribers_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/subscribers","subscription_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/subscription","commits_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/commits{/sha}","git_commits_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/git/commits{/sha}","comments_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/comments{/number}","issue_comment_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues/comments{/number}","contents_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/contents/{+path}","compare_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/merges","archive_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/downloads","issues_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues{/number}","pulls_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls{/number}","milestones_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/milestones{/number}","notifications_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/labels{/name}","releases_url":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/releases{/id}","created_at":"2015-02-16T12:27:03Z","updated_at":"2015-11-17T00:37:21Z","pushed_at":"2015-11-30T10:07:42Z","git_url":"git://github.com/bangalore-haskell-user-group/functorrent.git","ssh_url":"git@github.com:bangalore-haskell-user-group/functorrent.git","clone_url":"https://github.com/bangalore-haskell-user-group/functorrent.git","svn_url":"https://github.com/bangalore-haskell-user-group/functorrent","homepage":null,"size":668,"stargazers_count":15,"watchers_count":15,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":10,"forks":10,"open_issues":10,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls/44"},"html":{"href":"https://github.com/bangalore-haskell-user-group/functorrent/pull/44"},"issue":{"href":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues/44"},"comments":{"href":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/issues/44/comments"},"review_comments":{"href":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls/44/comments"},"review_comment":{"href":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/pulls/44/commits"},"statuses":{"href":"https://api.github.com/repos/bangalore-haskell-user-group/functorrent/statuses/a05f5eca019e7930d8ad26b25b583fa020233e80"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"jaseemabid","id":601714,"avatar_url":"https://avatars.githubusercontent.com/u/601714?v=3","gravatar_id":"","url":"https://api.github.com/users/jaseemabid","html_url":"https://github.com/jaseemabid","followers_url":"https://api.github.com/users/jaseemabid/followers","following_url":"https://api.github.com/users/jaseemabid/following{/other_user}","gists_url":"https://api.github.com/users/jaseemabid/gists{/gist_id}","starred_url":"https://api.github.com/users/jaseemabid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaseemabid/subscriptions","organizations_url":"https://api.github.com/users/jaseemabid/orgs","repos_url":"https://api.github.com/users/jaseemabid/repos","events_url":"https://api.github.com/users/jaseemabid/events{/privacy}","received_events_url":"https://api.github.com/users/jaseemabid/received_events","type":"User","site_admin":false},"comments":1,"review_comments":0,"commits":14,"additions":466,"deletions":689,"changed_files":18}}