{"action":"created","comment":{"url":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/comments/185333936","pull_request_review_id":116699080,"id":185333936,"diff_hunk":"@@ -0,0 +1,66 @@\n+package utils\n+\n+import (\n+\t\"context\"\n+\t\"math/rand\"\n+\t\"testing\"\n+\t\"time\"\n+)\n+\n+const (\n+\tTheBestNumber = 28\n+)\n+\n+func TestTickerHappyCase(t *testing.T) {\n+\tctx, _ := context.WithTimeout(context.Background(), 1000 * time.Millisecond)\n+\tmTicker := JitteredTicker(ctx, 10*time.Millisecond, 100*time.Millisecond)\n+\n+\ttimes := 0\n+\tfor {\n+\t\t_, ok := <-mTicker\n+\t\ttimes++\n+\t\tif !ok {\n+\t\t\tbreak\n+\t\t}\n+\t}\n+\n+\tif 10 > times || times > 100  {\n+\t\tt.Error(\"Should tick at least 10 but less than 100 times: \", times)\n+\t}\n+}\n+\n+func TestRandomDuration(t *testing.T) {\n+\t// The best randomness is deterministic\n+\trand.Seed(TheBestNumber)\n+\n+\tstart := 10 * time.Second\n+\tend := 20 * time.Second\n+\n+\tfor i := 0; i < 10000; i++ {\n+\t\tc := randomDuration(start, end)\n+\t\tif c < start || end < c {","path":"agent/utils/ticker_test.go","position":41,"original_position":41,"commit_id":"44efb08188f793b35d573ec57f6df4851acb190e","original_commit_id":"44efb08188f793b35d573ec57f6df4851acb190e","user":{"login":"richardpen","id":17835576,"avatar_url":"https://avatars2.githubusercontent.com/u/17835576?v=4","gravatar_id":"","url":"https://api.github.com/users/richardpen","html_url":"https://github.com/richardpen","followers_url":"https://api.github.com/users/richardpen/followers","following_url":"https://api.github.com/users/richardpen/following{/other_user}","gists_url":"https://api.github.com/users/richardpen/gists{/gist_id}","starred_url":"https://api.github.com/users/richardpen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardpen/subscriptions","organizations_url":"https://api.github.com/users/richardpen/orgs","repos_url":"https://api.github.com/users/richardpen/repos","events_url":"https://api.github.com/users/richardpen/events{/privacy}","received_events_url":"https://api.github.com/users/richardpen/received_events","type":"User","site_admin":false},"body":"nit: can you change it to `c <start || c > end`?","created_at":"2018-05-01T21:05:04Z","updated_at":"2018-05-01T21:10:27Z","html_url":"https://github.com/aws/amazon-ecs-agent/pull/1372#discussion_r185333936","pull_request_url":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/1372","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/comments/185333936"},"html":{"href":"https://github.com/aws/amazon-ecs-agent/pull/1372#discussion_r185333936"},"pull_request":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/1372"}}},"pull_request":{"url":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/1372","id":185120274,"html_url":"https://github.com/aws/amazon-ecs-agent/pull/1372","diff_url":"https://github.com/aws/amazon-ecs-agent/pull/1372.diff","patch_url":"https://github.com/aws/amazon-ecs-agent/pull/1372.patch","issue_url":"https://api.github.com/repos/aws/amazon-ecs-agent/issues/1372","number":1372,"state":"open","locked":false,"title":"Adding more randomness to the state change batches timer","user":{"login":"petderek","id":1487156,"avatar_url":"https://avatars3.githubusercontent.com/u/1487156?v=4","gravatar_id":"","url":"https://api.github.com/users/petderek","html_url":"https://github.com/petderek","followers_url":"https://api.github.com/users/petderek/followers","following_url":"https://api.github.com/users/petderek/following{/other_user}","gists_url":"https://api.github.com/users/petderek/gists{/gist_id}","starred_url":"https://api.github.com/users/petderek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petderek/subscriptions","organizations_url":"https://api.github.com/users/petderek/orgs","repos_url":"https://api.github.com/users/petderek/repos","events_url":"https://api.github.com/users/petderek/events{/privacy}","received_events_url":"https://api.github.com/users/petderek/received_events","type":"User","site_admin":false},"body":"\r\n<!--\r\nPlease make sure you've read and understood our contributing guidelines;\r\nhttps://github.com/aws/amazon-ecs-agent/blob/master/CONTRIBUTING.md\r\n\r\nPlease provide the following information:\r\n-->\r\n\r\n### Summary\r\n<!-- What does this pull request do? -->\r\nCurrently, we call the SubmitTaskStateChange API every 20 seconds. If a large\r\nnumber of agents all start at the same time within a cluster, this\r\nsynchronization can cause a cluster to hit throttle limits. This can slow\r\nthe cluster scale up process.\r\n\r\nBy introducing jitter into the timer, we can further distribute the API calls\r\nand make the throttling less likely.\r\n\r\n### Implementation details\r\n<!-- How are the changes implemented? -->\r\nThis is implemented by changing the static 20 second ticker to tick randomly between 10 and 30 seconds.\r\n\r\n\r\n### Testing\r\n<!-- How was this tested? -->\r\n<!--\r\nNote for external contributors:\r\n`make test` and `make run-integ-tests` can run in a Linux development\r\nenvironment like your laptop.  `go test -timeout=25s ./agent/...` and\r\n`.\\scripts\\run-integ.tests.ps1` can run in a Windows development environment\r\nlike your laptop.  Please ensure unit and integration tests pass (on at least\r\none platform) before opening the pull request.  `make run-functional-tests` and\r\n`.\\scripts\\run-functional-tests.ps1` must be run on an EC2 instance with an\r\ninstance profile allowing it access to AWS resources.  Running\r\n`make run-functional-tests` and `.\\scripts\\run-functional-tests.ps1` may incur\r\ncharges to your AWS account; if you're unable or unwilling to run these tests\r\nin your own account, we can run the tests and provide test results.\r\n-->\r\n- [ ] Builds on Linux (`make release`)\r\n- [ ] Builds on Windows (`go build -out amazon-ecs-agent.exe ./agent`)\r\n- [ ] Unit tests on Linux (`make test`) pass\r\n- [ ] Unit tests on Windows (`go test -timeout=25s ./agent/...`) pass\r\n- [ ] Integration tests on Linux (`make run-integ-tests`) pass\r\n- [ ] Integration tests on Windows (`.\\scripts\\run-integ-tests.ps1`) pass\r\n- [ ] Functional tests on Linux (`make run-functional-tests`) pass\r\n- [ ] Functional tests on Windows (`.\\scripts\\run-functional-tests.ps1`) pass\r\n\r\nNew tests cover the changes: <!-- yes|no -->\r\n\r\n### Description for the changelog\r\n<!--\r\nWrite a short (one line) summary that describes the changes in this\r\npull request for inclusion in the changelog.\r\nYou can see our changelog entry style here:\r\nhttps://github.com/aws/amazon-ecs-agent/commit/c9aefebc2b3007f09468f651f6308136bd7b384f\r\n-->\r\nEnhancement - Improving SubmitTaskStateChange performance in large clusters\r\n\r\n### Licensing\r\n\r\nBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.\r\n","created_at":"2018-05-01T04:58:25Z","updated_at":"2018-05-01T21:10:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c640f276a5d2edc5f65099dc48697a052c27a248","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/1372/commits","review_comments_url":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/1372/comments","review_comment_url":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aws/amazon-ecs-agent/issues/1372/comments","statuses_url":"https://api.github.com/repos/aws/amazon-ecs-agent/statuses/44efb08188f793b35d573ec57f6df4851acb190e","head":{"label":"petderek:ticker","ref":"ticker","sha":"44efb08188f793b35d573ec57f6df4851acb190e","user":{"login":"petderek","id":1487156,"avatar_url":"https://avatars3.githubusercontent.com/u/1487156?v=4","gravatar_id":"","url":"https://api.github.com/users/petderek","html_url":"https://github.com/petderek","followers_url":"https://api.github.com/users/petderek/followers","following_url":"https://api.github.com/users/petderek/following{/other_user}","gists_url":"https://api.github.com/users/petderek/gists{/gist_id}","starred_url":"https://api.github.com/users/petderek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petderek/subscriptions","organizations_url":"https://api.github.com/users/petderek/orgs","repos_url":"https://api.github.com/users/petderek/repos","events_url":"https://api.github.com/users/petderek/events{/privacy}","received_events_url":"https://api.github.com/users/petderek/received_events","type":"User","site_admin":false},"repo":{"id":76498663,"name":"amazon-ecs-agent","full_name":"petderek/amazon-ecs-agent","owner":{"login":"petderek","id":1487156,"avatar_url":"https://avatars3.githubusercontent.com/u/1487156?v=4","gravatar_id":"","url":"https://api.github.com/users/petderek","html_url":"https://github.com/petderek","followers_url":"https://api.github.com/users/petderek/followers","following_url":"https://api.github.com/users/petderek/following{/other_user}","gists_url":"https://api.github.com/users/petderek/gists{/gist_id}","starred_url":"https://api.github.com/users/petderek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petderek/subscriptions","organizations_url":"https://api.github.com/users/petderek/orgs","repos_url":"https://api.github.com/users/petderek/repos","events_url":"https://api.github.com/users/petderek/events{/privacy}","received_events_url":"https://api.github.com/users/petderek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/petderek/amazon-ecs-agent","description":"Amazon EC2 Container Service Agent","fork":true,"url":"https://api.github.com/repos/petderek/amazon-ecs-agent","forks_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/forks","keys_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/teams","hooks_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/hooks","issue_events_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/issues/events{/number}","events_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/events","assignees_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/assignees{/user}","branches_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/branches{/branch}","tags_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/tags","blobs_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/languages","stargazers_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/stargazers","contributors_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/contributors","subscribers_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/subscribers","subscription_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/subscription","commits_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/contents/{+path}","compare_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/merges","archive_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/downloads","issues_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/issues{/number}","pulls_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/labels{/name}","releases_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/releases{/id}","deployments_url":"https://api.github.com/repos/petderek/amazon-ecs-agent/deployments","created_at":"2016-12-14T21:31:01Z","updated_at":"2016-12-14T21:31:03Z","pushed_at":"2018-04-28T03:32:17Z","git_url":"git://github.com/petderek/amazon-ecs-agent.git","ssh_url":"git@github.com:petderek/amazon-ecs-agent.git","clone_url":"https://github.com/petderek/amazon-ecs-agent.git","svn_url":"https://github.com/petderek/amazon-ecs-agent","homepage":"http://aws.amazon.com/ecs/","size":29940,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"aws:dev","ref":"dev","sha":"ff311e067767b406bb1c8813c02658398f302f2c","user":{"login":"aws","id":2232217,"avatar_url":"https://avatars3.githubusercontent.com/u/2232217?v=4","gravatar_id":"","url":"https://api.github.com/users/aws","html_url":"https://github.com/aws","followers_url":"https://api.github.com/users/aws/followers","following_url":"https://api.github.com/users/aws/following{/other_user}","gists_url":"https://api.github.com/users/aws/gists{/gist_id}","starred_url":"https://api.github.com/users/aws/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aws/subscriptions","organizations_url":"https://api.github.com/users/aws/orgs","repos_url":"https://api.github.com/users/aws/repos","events_url":"https://api.github.com/users/aws/events{/privacy}","received_events_url":"https://api.github.com/users/aws/received_events","type":"Organization","site_admin":false},"repo":{"id":27551774,"name":"amazon-ecs-agent","full_name":"aws/amazon-ecs-agent","owner":{"login":"aws","id":2232217,"avatar_url":"https://avatars3.githubusercontent.com/u/2232217?v=4","gravatar_id":"","url":"https://api.github.com/users/aws","html_url":"https://github.com/aws","followers_url":"https://api.github.com/users/aws/followers","following_url":"https://api.github.com/users/aws/following{/other_user}","gists_url":"https://api.github.com/users/aws/gists{/gist_id}","starred_url":"https://api.github.com/users/aws/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aws/subscriptions","organizations_url":"https://api.github.com/users/aws/orgs","repos_url":"https://api.github.com/users/aws/repos","events_url":"https://api.github.com/users/aws/events{/privacy}","received_events_url":"https://api.github.com/users/aws/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aws/amazon-ecs-agent","description":"Amazon Elastic Container Service Agent","fork":false,"url":"https://api.github.com/repos/aws/amazon-ecs-agent","forks_url":"https://api.github.com/repos/aws/amazon-ecs-agent/forks","keys_url":"https://api.github.com/repos/aws/amazon-ecs-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aws/amazon-ecs-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aws/amazon-ecs-agent/teams","hooks_url":"https://api.github.com/repos/aws/amazon-ecs-agent/hooks","issue_events_url":"https://api.github.com/repos/aws/amazon-ecs-agent/issues/events{/number}","events_url":"https://api.github.com/repos/aws/amazon-ecs-agent/events","assignees_url":"https://api.github.com/repos/aws/amazon-ecs-agent/assignees{/user}","branches_url":"https://api.github.com/repos/aws/amazon-ecs-agent/branches{/branch}","tags_url":"https://api.github.com/repos/aws/amazon-ecs-agent/tags","blobs_url":"https://api.github.com/repos/aws/amazon-ecs-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aws/amazon-ecs-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aws/amazon-ecs-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/aws/amazon-ecs-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aws/amazon-ecs-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/aws/amazon-ecs-agent/languages","stargazers_url":"https://api.github.com/repos/aws/amazon-ecs-agent/stargazers","contributors_url":"https://api.github.com/repos/aws/amazon-ecs-agent/contributors","subscribers_url":"https://api.github.com/repos/aws/amazon-ecs-agent/subscribers","subscription_url":"https://api.github.com/repos/aws/amazon-ecs-agent/subscription","commits_url":"https://api.github.com/repos/aws/amazon-ecs-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/aws/amazon-ecs-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/aws/amazon-ecs-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/aws/amazon-ecs-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/aws/amazon-ecs-agent/contents/{+path}","compare_url":"https://api.github.com/repos/aws/amazon-ecs-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aws/amazon-ecs-agent/merges","archive_url":"https://api.github.com/repos/aws/amazon-ecs-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aws/amazon-ecs-agent/downloads","issues_url":"https://api.github.com/repos/aws/amazon-ecs-agent/issues{/number}","pulls_url":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/aws/amazon-ecs-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/aws/amazon-ecs-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aws/amazon-ecs-agent/labels{/name}","releases_url":"https://api.github.com/repos/aws/amazon-ecs-agent/releases{/id}","deployments_url":"https://api.github.com/repos/aws/amazon-ecs-agent/deployments","created_at":"2014-12-04T17:31:49Z","updated_at":"2018-04-30T17:47:09Z","pushed_at":"2018-05-01T19:41:17Z","git_url":"git://github.com/aws/amazon-ecs-agent.git","ssh_url":"git@github.com:aws/amazon-ecs-agent.git","clone_url":"https://github.com/aws/amazon-ecs-agent.git","svn_url":"https://github.com/aws/amazon-ecs-agent","homepage":"http://aws.amazon.com/ecs/","size":30236,"stargazers_count":1218,"watchers_count":1218,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":324,"mirror_url":null,"archived":false,"open_issues_count":104,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":324,"open_issues":104,"watchers":1218,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/1372"},"html":{"href":"https://github.com/aws/amazon-ecs-agent/pull/1372"},"issue":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/issues/1372"},"comments":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/issues/1372/comments"},"review_comments":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/1372/comments"},"review_comment":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/pulls/1372/commits"},"statuses":{"href":"https://api.github.com/repos/aws/amazon-ecs-agent/statuses/44efb08188f793b35d573ec57f6df4851acb190e"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"richardpen"}}