{"action":"created","comment":{"url":"https://api.github.com/repos/iron-io/functions/pulls/comments/91782063","pull_request_review_id":12294213,"id":91782063,"diff_hunk":"@@ -0,0 +1,102 @@\n+# Hot containers\n+\n+IronFunctions is built on top of container technologies, for each incoming\n+workload, it spins a new container, feed it with the payload and sends the\n+answer back to the caller. You can expect an average start time of 300ms per\n+container. You may refer to [this blog](https://medium.com/travis-on-docker/the-overhead-of-docker-run-f2f06d47c9f3#.96tj75ugb) post to understand the details better.\n+\n+In the case you need faster start times for your function, you may use a hot\n+container instead.\n+\n+Hot containers are started once and kept alive while there is incoming workload.\n+Thus, it means that once you decide to use a hot container, you must be able to\n+tell the moment it should reading from standard input to start writing to\n+standard output.\n+\n+Currently, IronFunctions implements a HTTP-like protocol to operate hot\n+containers, but instead of communication through a TCP/IP port, it uses standard\n+input/output.\n+\n+## Implementing a hot container\n+\n+In the [examples directory](https://github.com/iron-io/functions/blob/master/examples/hotcontainers/http/func.go), there is one simple implementation of a hot container\n+which we are going to get in the details here.\n+\n+The basic cycle comprises three steps: read standard input up to a previosly\n+known point, process the work, the write the output to stdout with some\n+information about when functions daemon should stop reading from stdout.\n+\n+In the case at hand, we start by plugging stdin to a HTTP request parser:\n+\n+```go\n+r := bufio.NewReader(os.Stdin)\n+req, err := http.ReadRequest(r)\n+\n+// ...\n+} else {\n+\tl, _ := strconv.Atoi(req.Header.Get(\"Content-Length\"))\n+\tp := make([]byte, l)\n+\tr.Read(p)\n+}\n+```\n+\n+Note how `Content-Length` is used to help determinate how far standard input\n+must be read.\n+\n+The next step in the cycle is to do some processing:\n+\n+```go\n+\t//...\n+\tvar buf bytes.Buffer\n+\tfmt.Fprintf(&buf, \"Hello %s\\n\", p)\n+\tfor k, vs := range req.Header {\n+\t\tfmt.Fprintf(&buf, \"ENV: %s %#v\\n\", k, vs)\n+\t}\n+\t//...\n+```\n+\n+And finally, we return the result with a `Content-Length` header, so\n+IronFunctions daemon would know when to stop reading the gotten response.\n+\n+```go\n+res := http.Response{\n+\tProto:      \"HTTP/1.1\",\n+\tProtoMajor: 1,\n+\tProtoMinor: 1,\n+\tStatusCode: 200,\n+\tStatus:     \"OK\",\n+}\n+res.Body = ioutil.NopCloser(&buf)\n+res.ContentLength = int64(buf.Len())\n+res.Write(os.Stdout)\n+```\n+\n+Rinse and repeat for each incoming workload.\n+\n+\n+## Deploying a hot container\n+\n+Once your functions is adapted to be handled as hot container, you must tell\n+IronFunctions daemon that this function is now ready to be reused across\n+requests:\n+\n+```json\n+{\n+\t\"route\":{\n+\t\t\"app_name\": \"myapp\",\n+\t\t\"path\": \"/hot\",\n+\t\t\"image\": \"USERNAME/hchttp\",\n+\t\t\"memory\": 64,\n+\t\t\"type\": \"sync\",\n+\t\t\"config\": null,\n+\t\t\"format\": \"http\",\n+\t\t\"max_concurrency\": \"1\"\n+\t}\n+}\n+```\n+\n+`format` (mandatory) either \"default\" or \"http\". If \"http\", then it is a hot\n+container.\n+\n+`max_concurrency` (optional) - the number of simultaneous hot containers for","path":"docs/hot-containers.md","position":101,"original_position":101,"commit_id":"da3126cadc15c192d7f713c9047088efd16284c2","original_commit_id":"da3126cadc15c192d7f713c9047088efd16284c2","user":{"login":"pedronasser","id":2278084,"avatar_url":"https://avatars.githubusercontent.com/u/2278084?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronasser","html_url":"https://github.com/pedronasser","followers_url":"https://api.github.com/users/pedronasser/followers","following_url":"https://api.github.com/users/pedronasser/following{/other_user}","gists_url":"https://api.github.com/users/pedronasser/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronasser/subscriptions","organizations_url":"https://api.github.com/users/pedronasser/orgs","repos_url":"https://api.github.com/users/pedronasser/repos","events_url":"https://api.github.com/users/pedronasser/events{/privacy}","received_events_url":"https://api.github.com/users/pedronasser/received_events","type":"User","site_admin":false},"body":"Should we inform that default max_concurrency is 1 by default?","created_at":"2016-12-09T19:44:57Z","updated_at":"2016-12-09T19:45:34Z","html_url":"https://github.com/iron-io/functions/pull/411#discussion_r91782063","pull_request_url":"https://api.github.com/repos/iron-io/functions/pulls/411","_links":{"self":{"href":"https://api.github.com/repos/iron-io/functions/pulls/comments/91782063"},"html":{"href":"https://github.com/iron-io/functions/pull/411#discussion_r91782063"},"pull_request":{"href":"https://api.github.com/repos/iron-io/functions/pulls/411"}}},"pull_request":{"url":"https://api.github.com/repos/iron-io/functions/pulls/411","id":97358021,"html_url":"https://github.com/iron-io/functions/pull/411","diff_url":"https://github.com/iron-io/functions/pull/411.diff","patch_url":"https://github.com/iron-io/functions/pull/411.patch","issue_url":"https://api.github.com/repos/iron-io/functions/issues/411","number":411,"state":"open","locked":false,"title":"doc: hot containers","user":{"login":"ccirello","id":138827,"avatar_url":"https://avatars.githubusercontent.com/u/138827?v=3","gravatar_id":"","url":"https://api.github.com/users/ccirello","html_url":"https://github.com/ccirello","followers_url":"https://api.github.com/users/ccirello/followers","following_url":"https://api.github.com/users/ccirello/following{/other_user}","gists_url":"https://api.github.com/users/ccirello/gists{/gist_id}","starred_url":"https://api.github.com/users/ccirello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccirello/subscriptions","organizations_url":"https://api.github.com/users/ccirello/orgs","repos_url":"https://api.github.com/users/ccirello/repos","events_url":"https://api.github.com/users/ccirello/events{/privacy}","received_events_url":"https://api.github.com/users/ccirello/received_events","type":"User","site_admin":false},"body":"Fixes #393 ","created_at":"2016-12-09T18:34:29Z","updated_at":"2016-12-09T19:45:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5be02b9d12d1528a57af91ff0a1a0db3730e7e81","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/iron-io/functions/pulls/411/commits","review_comments_url":"https://api.github.com/repos/iron-io/functions/pulls/411/comments","review_comment_url":"https://api.github.com/repos/iron-io/functions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/iron-io/functions/issues/411/comments","statuses_url":"https://api.github.com/repos/iron-io/functions/statuses/da3126cadc15c192d7f713c9047088efd16284c2","head":{"label":"iron-io:hot-containers-doc","ref":"hot-containers-doc","sha":"da3126cadc15c192d7f713c9047088efd16284c2","user":{"login":"iron-io","id":908818,"avatar_url":"https://avatars.githubusercontent.com/u/908818?v=3","gravatar_id":"","url":"https://api.github.com/users/iron-io","html_url":"https://github.com/iron-io","followers_url":"https://api.github.com/users/iron-io/followers","following_url":"https://api.github.com/users/iron-io/following{/other_user}","gists_url":"https://api.github.com/users/iron-io/gists{/gist_id}","starred_url":"https://api.github.com/users/iron-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iron-io/subscriptions","organizations_url":"https://api.github.com/users/iron-io/orgs","repos_url":"https://api.github.com/users/iron-io/repos","events_url":"https://api.github.com/users/iron-io/events{/privacy}","received_events_url":"https://api.github.com/users/iron-io/received_events","type":"Organization","site_admin":false},"repo":{"id":61755229,"name":"functions","full_name":"iron-io/functions","owner":{"login":"iron-io","id":908818,"avatar_url":"https://avatars.githubusercontent.com/u/908818?v=3","gravatar_id":"","url":"https://api.github.com/users/iron-io","html_url":"https://github.com/iron-io","followers_url":"https://api.github.com/users/iron-io/followers","following_url":"https://api.github.com/users/iron-io/following{/other_user}","gists_url":"https://api.github.com/users/iron-io/gists{/gist_id}","starred_url":"https://api.github.com/users/iron-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iron-io/subscriptions","organizations_url":"https://api.github.com/users/iron-io/orgs","repos_url":"https://api.github.com/users/iron-io/repos","events_url":"https://api.github.com/users/iron-io/events{/privacy}","received_events_url":"https://api.github.com/users/iron-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iron-io/functions","description":"IronFunctions - the serverless microservices platform. ","fork":false,"url":"https://api.github.com/repos/iron-io/functions","forks_url":"https://api.github.com/repos/iron-io/functions/forks","keys_url":"https://api.github.com/repos/iron-io/functions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iron-io/functions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iron-io/functions/teams","hooks_url":"https://api.github.com/repos/iron-io/functions/hooks","issue_events_url":"https://api.github.com/repos/iron-io/functions/issues/events{/number}","events_url":"https://api.github.com/repos/iron-io/functions/events","assignees_url":"https://api.github.com/repos/iron-io/functions/assignees{/user}","branches_url":"https://api.github.com/repos/iron-io/functions/branches{/branch}","tags_url":"https://api.github.com/repos/iron-io/functions/tags","blobs_url":"https://api.github.com/repos/iron-io/functions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iron-io/functions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iron-io/functions/git/refs{/sha}","trees_url":"https://api.github.com/repos/iron-io/functions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iron-io/functions/statuses/{sha}","languages_url":"https://api.github.com/repos/iron-io/functions/languages","stargazers_url":"https://api.github.com/repos/iron-io/functions/stargazers","contributors_url":"https://api.github.com/repos/iron-io/functions/contributors","subscribers_url":"https://api.github.com/repos/iron-io/functions/subscribers","subscription_url":"https://api.github.com/repos/iron-io/functions/subscription","commits_url":"https://api.github.com/repos/iron-io/functions/commits{/sha}","git_commits_url":"https://api.github.com/repos/iron-io/functions/git/commits{/sha}","comments_url":"https://api.github.com/repos/iron-io/functions/comments{/number}","issue_comment_url":"https://api.github.com/repos/iron-io/functions/issues/comments{/number}","contents_url":"https://api.github.com/repos/iron-io/functions/contents/{+path}","compare_url":"https://api.github.com/repos/iron-io/functions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iron-io/functions/merges","archive_url":"https://api.github.com/repos/iron-io/functions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iron-io/functions/downloads","issues_url":"https://api.github.com/repos/iron-io/functions/issues{/number}","pulls_url":"https://api.github.com/repos/iron-io/functions/pulls{/number}","milestones_url":"https://api.github.com/repos/iron-io/functions/milestones{/number}","notifications_url":"https://api.github.com/repos/iron-io/functions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iron-io/functions/labels{/name}","releases_url":"https://api.github.com/repos/iron-io/functions/releases{/id}","deployments_url":"https://api.github.com/repos/iron-io/functions/deployments","created_at":"2016-06-22T22:19:22Z","updated_at":"2016-12-09T18:13:36Z","pushed_at":"2016-12-09T19:35:47Z","git_url":"git://github.com/iron-io/functions.git","ssh_url":"git@github.com:iron-io/functions.git","clone_url":"https://github.com/iron-io/functions.git","svn_url":"https://github.com/iron-io/functions","homepage":"http://iron.io","size":5658,"stargazers_count":1001,"watchers_count":1001,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":48,"mirror_url":null,"open_issues_count":48,"forks":48,"open_issues":48,"watchers":1001,"default_branch":"master"}},"base":{"label":"iron-io:master","ref":"master","sha":"49a7712e6b2caa2926ee50e3100a0c5f938f88c9","user":{"login":"iron-io","id":908818,"avatar_url":"https://avatars.githubusercontent.com/u/908818?v=3","gravatar_id":"","url":"https://api.github.com/users/iron-io","html_url":"https://github.com/iron-io","followers_url":"https://api.github.com/users/iron-io/followers","following_url":"https://api.github.com/users/iron-io/following{/other_user}","gists_url":"https://api.github.com/users/iron-io/gists{/gist_id}","starred_url":"https://api.github.com/users/iron-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iron-io/subscriptions","organizations_url":"https://api.github.com/users/iron-io/orgs","repos_url":"https://api.github.com/users/iron-io/repos","events_url":"https://api.github.com/users/iron-io/events{/privacy}","received_events_url":"https://api.github.com/users/iron-io/received_events","type":"Organization","site_admin":false},"repo":{"id":61755229,"name":"functions","full_name":"iron-io/functions","owner":{"login":"iron-io","id":908818,"avatar_url":"https://avatars.githubusercontent.com/u/908818?v=3","gravatar_id":"","url":"https://api.github.com/users/iron-io","html_url":"https://github.com/iron-io","followers_url":"https://api.github.com/users/iron-io/followers","following_url":"https://api.github.com/users/iron-io/following{/other_user}","gists_url":"https://api.github.com/users/iron-io/gists{/gist_id}","starred_url":"https://api.github.com/users/iron-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iron-io/subscriptions","organizations_url":"https://api.github.com/users/iron-io/orgs","repos_url":"https://api.github.com/users/iron-io/repos","events_url":"https://api.github.com/users/iron-io/events{/privacy}","received_events_url":"https://api.github.com/users/iron-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iron-io/functions","description":"IronFunctions - the serverless microservices platform. ","fork":false,"url":"https://api.github.com/repos/iron-io/functions","forks_url":"https://api.github.com/repos/iron-io/functions/forks","keys_url":"https://api.github.com/repos/iron-io/functions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iron-io/functions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iron-io/functions/teams","hooks_url":"https://api.github.com/repos/iron-io/functions/hooks","issue_events_url":"https://api.github.com/repos/iron-io/functions/issues/events{/number}","events_url":"https://api.github.com/repos/iron-io/functions/events","assignees_url":"https://api.github.com/repos/iron-io/functions/assignees{/user}","branches_url":"https://api.github.com/repos/iron-io/functions/branches{/branch}","tags_url":"https://api.github.com/repos/iron-io/functions/tags","blobs_url":"https://api.github.com/repos/iron-io/functions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iron-io/functions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iron-io/functions/git/refs{/sha}","trees_url":"https://api.github.com/repos/iron-io/functions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iron-io/functions/statuses/{sha}","languages_url":"https://api.github.com/repos/iron-io/functions/languages","stargazers_url":"https://api.github.com/repos/iron-io/functions/stargazers","contributors_url":"https://api.github.com/repos/iron-io/functions/contributors","subscribers_url":"https://api.github.com/repos/iron-io/functions/subscribers","subscription_url":"https://api.github.com/repos/iron-io/functions/subscription","commits_url":"https://api.github.com/repos/iron-io/functions/commits{/sha}","git_commits_url":"https://api.github.com/repos/iron-io/functions/git/commits{/sha}","comments_url":"https://api.github.com/repos/iron-io/functions/comments{/number}","issue_comment_url":"https://api.github.com/repos/iron-io/functions/issues/comments{/number}","contents_url":"https://api.github.com/repos/iron-io/functions/contents/{+path}","compare_url":"https://api.github.com/repos/iron-io/functions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iron-io/functions/merges","archive_url":"https://api.github.com/repos/iron-io/functions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iron-io/functions/downloads","issues_url":"https://api.github.com/repos/iron-io/functions/issues{/number}","pulls_url":"https://api.github.com/repos/iron-io/functions/pulls{/number}","milestones_url":"https://api.github.com/repos/iron-io/functions/milestones{/number}","notifications_url":"https://api.github.com/repos/iron-io/functions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iron-io/functions/labels{/name}","releases_url":"https://api.github.com/repos/iron-io/functions/releases{/id}","deployments_url":"https://api.github.com/repos/iron-io/functions/deployments","created_at":"2016-06-22T22:19:22Z","updated_at":"2016-12-09T18:13:36Z","pushed_at":"2016-12-09T19:35:47Z","git_url":"git://github.com/iron-io/functions.git","ssh_url":"git@github.com:iron-io/functions.git","clone_url":"https://github.com/iron-io/functions.git","svn_url":"https://github.com/iron-io/functions","homepage":"http://iron.io","size":5658,"stargazers_count":1001,"watchers_count":1001,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":48,"mirror_url":null,"open_issues_count":48,"forks":48,"open_issues":48,"watchers":1001,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/iron-io/functions/pulls/411"},"html":{"href":"https://github.com/iron-io/functions/pull/411"},"issue":{"href":"https://api.github.com/repos/iron-io/functions/issues/411"},"comments":{"href":"https://api.github.com/repos/iron-io/functions/issues/411/comments"},"review_comments":{"href":"https://api.github.com/repos/iron-io/functions/pulls/411/comments"},"review_comment":{"href":"https://api.github.com/repos/iron-io/functions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/iron-io/functions/pulls/411/commits"},"statuses":{"href":"https://api.github.com/repos/iron-io/functions/statuses/da3126cadc15c192d7f713c9047088efd16284c2"}}}}
{"actor":{"display_login":"pedronasser"}}