{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/comments/38420217","id":38420217,"diff_hunk":"@@ -23,25 +23,52 @@ pidfile=\"/var/run/${servicename}.pid\"\n respawn_pidfile=\"/var/run/respawn-${servicename}.pid\"\n cgroup_root=\"/sys/fs/cgroup\"\n cgroup_path=\"daemons/netperf\"\n+cgroup_subpaths=\"daemons daemons/netperf\"\n+declare -a cgroup_groups\n \n . /lib/lsb/init-functions\n \n+cgroup_has_variable() {\n+  ! cgget -r $1 / 2>&1 |\n+    fgrep -e 'No such file or directory' -e 'cannot find controller' > /dev/null\n+}\n+\n # Ubuntu Trusty removes cgconfig for configuring CGroups but does not\n # furnish a replacement. cgroup-lite only provides the CGroups filesystem.\n # Build our configuration directly on that filesystem.  This might break\n # when Debian and/or Ubuntu do provide a replacement.\n configure_cgroup() {\n-  local cpu=$cgroup_root/cpu/$cgroup_path\n-  local mem=$cgroup_root/memory/$cgroup_path\n-  mkdir -p $cpu || log_daemon_msg \"Failed to create cgroup $cpu\"\n-  # TODO(arielshaqed): If Debian doesn't have cgroup memory controller, only\n-  # do this when $cgroup_root/memory is loaded.\n-  mkdir -p $mem || log_daemon_msg \"Failed to create cgroup $mem\"\n-  echo 1000000 > $cpu/cpu.cfs_period_us\n-  echo 15000 > $cpu/cpu.cfs_quota_us\n-  echo 180m > $mem/memory.limit_in_bytes\n-  # memsw.limit_in_bytes does not exist in Ubuntu Trusty (14.04)\n-  echo 0 > $mem/memory.oom_control\n+  cgroup_groups[0]=cpu\n+  cgcreate -g cpu:$cgroup_path\n+  \n+  (\n+    cgroup_has_variable cpu.cfs_period_us &&\n+    cgset -r cpu.cfs_period_us=1000000 $cgroup_path &&\n+    cgset -r cpu.cfs_quota_us=15000 $cgroup_path\n+  ) || (\n+    # E.g. Debian does not support quota and period, use cpu.shares","path":"contrib/netperf/init.d-collectd-td-deb","position":38,"original_position":38,"commit_id":"3533313d3dbf5bf75fa696722312e2a272b602e6","original_commit_id":"3533313d3dbf5bf75fa696722312e2a272b602e6","user":{"login":"arielshaqed","id":7802932,"avatar_url":"https://avatars.githubusercontent.com/u/7802932?v=3","gravatar_id":"","url":"https://api.github.com/users/arielshaqed","html_url":"https://github.com/arielshaqed","followers_url":"https://api.github.com/users/arielshaqed/followers","following_url":"https://api.github.com/users/arielshaqed/following{/other_user}","gists_url":"https://api.github.com/users/arielshaqed/gists{/gist_id}","starred_url":"https://api.github.com/users/arielshaqed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielshaqed/subscriptions","organizations_url":"https://api.github.com/users/arielshaqed/orgs","repos_url":"https://api.github.com/users/arielshaqed/repos","events_url":"https://api.github.com/users/arielshaqed/events{/privacy}","received_events_url":"https://api.github.com/users/arielshaqed/received_events","type":"User","site_admin":false},"body":"Actually it's quite important! We first try to use CFS control over CPU usage, which does what we want. But Debian doesn't come with CFS scheduler out of the box (AFAICT) so that doesn't work. The `||` switches us to the alternative, which sets `cpu.shares` on the cgroup.","created_at":"2015-09-01T13:51:36Z","updated_at":"2015-09-01T13:51:36Z","html_url":"https://github.com/GoogleCloudPlatform/collectd-netperf/pull/10#discussion_r38420217","pull_request_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/comments/38420217"},"html":{"href":"https://github.com/GoogleCloudPlatform/collectd-netperf/pull/10#discussion_r38420217"},"pull_request":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/10","id":43860881,"html_url":"https://github.com/GoogleCloudPlatform/collectd-netperf/pull/10","diff_url":"https://github.com/GoogleCloudPlatform/collectd-netperf/pull/10.diff","patch_url":"https://github.com/GoogleCloudPlatform/collectd-netperf/pull/10.patch","issue_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues/10","number":10,"state":"closed","locked":false,"title":"Debian packaging: cgroups","user":{"login":"arielshaqed","id":7802932,"avatar_url":"https://avatars.githubusercontent.com/u/7802932?v=3","gravatar_id":"","url":"https://api.github.com/users/arielshaqed","html_url":"https://github.com/arielshaqed","followers_url":"https://api.github.com/users/arielshaqed/followers","following_url":"https://api.github.com/users/arielshaqed/following{/other_user}","gists_url":"https://api.github.com/users/arielshaqed/gists{/gist_id}","starred_url":"https://api.github.com/users/arielshaqed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielshaqed/subscriptions","organizations_url":"https://api.github.com/users/arielshaqed/orgs","repos_url":"https://api.github.com/users/arielshaqed/repos","events_url":"https://api.github.com/users/arielshaqed/events{/privacy}","received_events_url":"https://api.github.com/users/arielshaqed/received_events","type":"User","site_admin":false},"body":"This makes Debian and Ubuntu packaging work with CGroups. On Debian 7 we only limit CPU by setting cpu.shares, which is quite weak. But it's the best we can do. If CFS is available, we use that, and if there's a memory controller we add that in too.","created_at":"2015-09-01T10:40:36Z","updated_at":"2015-09-01T13:51:36Z","closed_at":"2015-09-01T13:40:19Z","merged_at":"2015-09-01T13:40:19Z","merge_commit_sha":"a494edf49d25859d672c5958d21101ec843d7890","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/10/commits","review_comments_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/10/comments","review_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues/10/comments","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/statuses/3533313d3dbf5bf75fa696722312e2a272b602e6","head":{"label":"GoogleCloudPlatform:ariels-debian-pkg","ref":"ariels-debian-pkg","sha":"3533313d3dbf5bf75fa696722312e2a272b602e6","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":38563469,"name":"collectd-netperf","full_name":"GoogleCloudPlatform/collectd-netperf","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/collectd-netperf","description":null,"fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/releases{/id}","created_at":"2015-07-05T09:20:31Z","updated_at":"2015-08-05T18:35:06Z","pushed_at":"2015-09-01T13:49:41Z","git_url":"git://github.com/GoogleCloudPlatform/collectd-netperf.git","ssh_url":"git@github.com:GoogleCloudPlatform/collectd-netperf.git","clone_url":"https://github.com/GoogleCloudPlatform/collectd-netperf.git","svn_url":"https://github.com/GoogleCloudPlatform/collectd-netperf","homepage":null,"size":11376,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"netperf-master"}},"base":{"label":"GoogleCloudPlatform:netperf-master","ref":"netperf-master","sha":"d52d0ac9b69e6d75ba64e736df96ab11bb1a4101","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":38563469,"name":"collectd-netperf","full_name":"GoogleCloudPlatform/collectd-netperf","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/collectd-netperf","description":null,"fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/releases{/id}","created_at":"2015-07-05T09:20:31Z","updated_at":"2015-08-05T18:35:06Z","pushed_at":"2015-09-01T13:49:41Z","git_url":"git://github.com/GoogleCloudPlatform/collectd-netperf.git","ssh_url":"git@github.com:GoogleCloudPlatform/collectd-netperf.git","clone_url":"https://github.com/GoogleCloudPlatform/collectd-netperf.git","svn_url":"https://github.com/GoogleCloudPlatform/collectd-netperf","homepage":null,"size":11376,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"netperf-master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/10"},"html":{"href":"https://github.com/GoogleCloudPlatform/collectd-netperf/pull/10"},"issue":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues/10"},"comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleCloudPlatform/collectd-netperf/statuses/3533313d3dbf5bf75fa696722312e2a272b602e6"}}}}