{"action":"created","comment":{"url":"https://api.github.com/repos/netty/netty/pulls/comments/96590841","pull_request_review_id":17175881,"id":96590841,"diff_hunk":"@@ -0,0 +1,74 @@\n+/*\n+ * Copyright 2017 The Netty Project\n+ *\n+ * The Netty Project licenses this file to you under the Apache License,\n+ * version 2.0 (the \"License\"); you may not use this file except in compliance\n+ * with the License. You may obtain a copy of the License at:\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+ * License for the specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package io.netty.util;\n+\n+import io.netty.util.internal.SystemPropertyUtil;\n+\n+import java.util.concurrent.atomic.AtomicInteger;\n+\n+/**\n+ * A utility class for wrapping calls to {@link Runtime}.\n+ */\n+public final class NettyRuntime {\n+\n+    private static final AtomicInteger availableProcessors = new AtomicInteger();\n+\n+    /**\n+     * No public constructor to prevent instances from being created.\n+     */\n+    private NettyRuntime() {\n+    }\n+\n+    /**\n+     * Set the number of available processors.\n+     *\n+     * @param availableProcessors the number of available processors\n+     * @throws IllegalArgumentException if the specified number of available processors is non-positive\n+     * @throws IllegalStateException    if the number of available processors is already configured\n+     */\n+    public static void setAvailableProcessors(final int availableProcessors) {\n+        if (availableProcessors <= 0) {\n+            throw new IllegalArgumentException(\n+                    \"availableProcessors must be positive but was [\" + availableProcessors + \"]\");\n+        }\n+        if (!NettyRuntime.availableProcessors.compareAndSet(0, availableProcessors)) {\n+            throw new IllegalStateException(\n+                    \"availableProcessors is already set to [\" + NettyRuntime.availableProcessors.get() + \"], \" +\n+                            \"rejecting [\" + availableProcessors + \"]\");\n+        }\n+    }\n+\n+    /**\n+     * Get the configured number of available processors. The default is {@link Runtime#availableProcessors()}. This\n+     * can be overridden by setting the system property \"io.netty.availableProcessors\" or by invoking\n+     * {@link #setAvailableProcessors(int)} before any calls to {@link #availableProcessors()}.\n+     *\n+     * @return the configured number of available processors\n+     */\n+    @SuppressForbidden(reason = \"to obtain default number of available processors\")\n+    public static int availableProcessors() {\n+        if (NettyRuntime.availableProcessors.get() == 0) {\n+            final int availableProcessors =\n+                    SystemPropertyUtil.getInt(\n+                            \"io.netty.availableProcessors\",\n+                            Runtime.getRuntime().availableProcessors());\n+            setAvailableProcessors(availableProcessors);","path":"common/src/main/java/io/netty/util/NettyRuntime.java","position":69,"original_position":69,"commit_id":"2692dc06fd1b0dca697388be013d12944644b930","original_commit_id":"2692dc06fd1b0dca697388be013d12944644b930","user":{"login":"jasontedor","id":4744941,"avatar_url":"https://avatars.githubusercontent.com/u/4744941?v=3","gravatar_id":"","url":"https://api.github.com/users/jasontedor","html_url":"https://github.com/jasontedor","followers_url":"https://api.github.com/users/jasontedor/followers","following_url":"https://api.github.com/users/jasontedor/following{/other_user}","gists_url":"https://api.github.com/users/jasontedor/gists{/gist_id}","starred_url":"https://api.github.com/users/jasontedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasontedor/subscriptions","organizations_url":"https://api.github.com/users/jasontedor/orgs","repos_url":"https://api.github.com/users/jasontedor/repos","events_url":"https://api.github.com/users/jasontedor/events{/privacy}","received_events_url":"https://api.github.com/users/jasontedor/received_events","type":"User","site_admin":false},"body":"Yes, that's what I mean by two gets racing. You're not missing anything, but I'm not sure if it's actually a problem.","created_at":"2017-01-18T09:12:28Z","updated_at":"2017-01-18T09:12:28Z","html_url":"https://github.com/netty/netty/pull/6224#discussion_r96590841","pull_request_url":"https://api.github.com/repos/netty/netty/pulls/6224","_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/comments/96590841"},"html":{"href":"https://github.com/netty/netty/pull/6224#discussion_r96590841"},"pull_request":{"href":"https://api.github.com/repos/netty/netty/pulls/6224"}}},"pull_request":{"url":"https://api.github.com/repos/netty/netty/pulls/6224","id":101748904,"html_url":"https://github.com/netty/netty/pull/6224","diff_url":"https://github.com/netty/netty/pull/6224.diff","patch_url":"https://github.com/netty/netty/pull/6224.patch","issue_url":"https://api.github.com/repos/netty/netty/issues/6224","number":6224,"state":"open","locked":false,"title":"Enable configuring available processors","user":{"login":"jasontedor","id":4744941,"avatar_url":"https://avatars.githubusercontent.com/u/4744941?v=3","gravatar_id":"","url":"https://api.github.com/users/jasontedor","html_url":"https://github.com/jasontedor","followers_url":"https://api.github.com/users/jasontedor/followers","following_url":"https://api.github.com/users/jasontedor/following{/other_user}","gists_url":"https://api.github.com/users/jasontedor/gists{/gist_id}","starred_url":"https://api.github.com/users/jasontedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasontedor/subscriptions","organizations_url":"https://api.github.com/users/jasontedor/orgs","repos_url":"https://api.github.com/users/jasontedor/repos","events_url":"https://api.github.com/users/jasontedor/events{/privacy}","received_events_url":"https://api.github.com/users/jasontedor/received_events","type":"User","site_admin":false},"body":"Motivation:\r\n\r\nIn cases when an application is running in a container or is otherwise constrained to the number of processors that it is using, the JVM invocation Runtime#availableProcessors will not return the constrained value but rather the number of processors available to the virtual machine. Netty uses this number in sizing various resources. Additionally, some applications will constrain the number of threads that they are using independenly of the number of processors available on the system. Thus, applications should have a way to globally configure the number of processors.\r\n\r\nModifications:\r\n\r\nRather than invoking Runtime#availableProcessors, Netty should rely on a method that enables configuration when the JVM is started or by the application. This commit exposes a new class NettyRuntime for enabling such configuraiton. This value can only be set once. Its default value is Runtime#availableProcessors so that there is no visible change to existing applications, but enables configuring either a system property or configuring during application startup (e.g., based on settings used to configure the application).\r\n\r\nAdditionally, we introduce the usage of forbidden-apis to prevent future uses of Runtime#availableProcessors from creeping. Future work should enable the bundled signatures and clean up uses of deprecated and other forbidden methods.\r\n\r\nResult:\r\n\r\nNetty can be configured to not use the underlying number of processors, but rather the constrained number of processors.\r\n","created_at":"2017-01-16T19:49:43Z","updated_at":"2017-01-18T09:12:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4297fd6650a71bcec8bfa6d79e21ece69ea8a1a5","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/netty/netty/pulls/6224/commits","review_comments_url":"https://api.github.com/repos/netty/netty/pulls/6224/comments","review_comment_url":"https://api.github.com/repos/netty/netty/pulls/comments{/number}","comments_url":"https://api.github.com/repos/netty/netty/issues/6224/comments","statuses_url":"https://api.github.com/repos/netty/netty/statuses/2692dc06fd1b0dca697388be013d12944644b930","head":{"label":"jasontedor:available-processors","ref":"available-processors","sha":"2692dc06fd1b0dca697388be013d12944644b930","user":{"login":"jasontedor","id":4744941,"avatar_url":"https://avatars.githubusercontent.com/u/4744941?v=3","gravatar_id":"","url":"https://api.github.com/users/jasontedor","html_url":"https://github.com/jasontedor","followers_url":"https://api.github.com/users/jasontedor/followers","following_url":"https://api.github.com/users/jasontedor/following{/other_user}","gists_url":"https://api.github.com/users/jasontedor/gists{/gist_id}","starred_url":"https://api.github.com/users/jasontedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasontedor/subscriptions","organizations_url":"https://api.github.com/users/jasontedor/orgs","repos_url":"https://api.github.com/users/jasontedor/repos","events_url":"https://api.github.com/users/jasontedor/events{/privacy}","received_events_url":"https://api.github.com/users/jasontedor/received_events","type":"User","site_admin":false},"repo":{"id":62667953,"name":"netty","full_name":"jasontedor/netty","owner":{"login":"jasontedor","id":4744941,"avatar_url":"https://avatars.githubusercontent.com/u/4744941?v=3","gravatar_id":"","url":"https://api.github.com/users/jasontedor","html_url":"https://github.com/jasontedor","followers_url":"https://api.github.com/users/jasontedor/followers","following_url":"https://api.github.com/users/jasontedor/following{/other_user}","gists_url":"https://api.github.com/users/jasontedor/gists{/gist_id}","starred_url":"https://api.github.com/users/jasontedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasontedor/subscriptions","organizations_url":"https://api.github.com/users/jasontedor/orgs","repos_url":"https://api.github.com/users/jasontedor/repos","events_url":"https://api.github.com/users/jasontedor/events{/privacy}","received_events_url":"https://api.github.com/users/jasontedor/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jasontedor/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":true,"url":"https://api.github.com/repos/jasontedor/netty","forks_url":"https://api.github.com/repos/jasontedor/netty/forks","keys_url":"https://api.github.com/repos/jasontedor/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jasontedor/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jasontedor/netty/teams","hooks_url":"https://api.github.com/repos/jasontedor/netty/hooks","issue_events_url":"https://api.github.com/repos/jasontedor/netty/issues/events{/number}","events_url":"https://api.github.com/repos/jasontedor/netty/events","assignees_url":"https://api.github.com/repos/jasontedor/netty/assignees{/user}","branches_url":"https://api.github.com/repos/jasontedor/netty/branches{/branch}","tags_url":"https://api.github.com/repos/jasontedor/netty/tags","blobs_url":"https://api.github.com/repos/jasontedor/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jasontedor/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jasontedor/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/jasontedor/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jasontedor/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/jasontedor/netty/languages","stargazers_url":"https://api.github.com/repos/jasontedor/netty/stargazers","contributors_url":"https://api.github.com/repos/jasontedor/netty/contributors","subscribers_url":"https://api.github.com/repos/jasontedor/netty/subscribers","subscription_url":"https://api.github.com/repos/jasontedor/netty/subscription","commits_url":"https://api.github.com/repos/jasontedor/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/jasontedor/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/jasontedor/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/jasontedor/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/jasontedor/netty/contents/{+path}","compare_url":"https://api.github.com/repos/jasontedor/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jasontedor/netty/merges","archive_url":"https://api.github.com/repos/jasontedor/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jasontedor/netty/downloads","issues_url":"https://api.github.com/repos/jasontedor/netty/issues{/number}","pulls_url":"https://api.github.com/repos/jasontedor/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/jasontedor/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/jasontedor/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jasontedor/netty/labels{/name}","releases_url":"https://api.github.com/repos/jasontedor/netty/releases{/id}","deployments_url":"https://api.github.com/repos/jasontedor/netty/deployments","created_at":"2016-07-05T20:36:42Z","updated_at":"2016-07-05T20:36:54Z","pushed_at":"2017-01-16T20:27:53Z","git_url":"git://github.com/jasontedor/netty.git","ssh_url":"git@github.com:jasontedor/netty.git","clone_url":"https://github.com/jasontedor/netty.git","svn_url":"https://github.com/jasontedor/netty","homepage":"http://netty.io/","size":43056,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"4.1"}},"base":{"label":"netty:4.1","ref":"4.1","sha":"7f01da8d0f65b5254ce515ef21d11ec603fea9fe","user":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"repo":{"id":1064563,"name":"netty","full_name":"netty/netty","owner":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/netty/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":false,"url":"https://api.github.com/repos/netty/netty","forks_url":"https://api.github.com/repos/netty/netty/forks","keys_url":"https://api.github.com/repos/netty/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/netty/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/netty/netty/teams","hooks_url":"https://api.github.com/repos/netty/netty/hooks","issue_events_url":"https://api.github.com/repos/netty/netty/issues/events{/number}","events_url":"https://api.github.com/repos/netty/netty/events","assignees_url":"https://api.github.com/repos/netty/netty/assignees{/user}","branches_url":"https://api.github.com/repos/netty/netty/branches{/branch}","tags_url":"https://api.github.com/repos/netty/netty/tags","blobs_url":"https://api.github.com/repos/netty/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/netty/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/netty/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/netty/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/netty/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/netty/netty/languages","stargazers_url":"https://api.github.com/repos/netty/netty/stargazers","contributors_url":"https://api.github.com/repos/netty/netty/contributors","subscribers_url":"https://api.github.com/repos/netty/netty/subscribers","subscription_url":"https://api.github.com/repos/netty/netty/subscription","commits_url":"https://api.github.com/repos/netty/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/netty/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/netty/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/netty/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/netty/netty/contents/{+path}","compare_url":"https://api.github.com/repos/netty/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/netty/netty/merges","archive_url":"https://api.github.com/repos/netty/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/netty/netty/downloads","issues_url":"https://api.github.com/repos/netty/netty/issues{/number}","pulls_url":"https://api.github.com/repos/netty/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/netty/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/netty/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/netty/netty/labels{/name}","releases_url":"https://api.github.com/repos/netty/netty/releases{/id}","deployments_url":"https://api.github.com/repos/netty/netty/deployments","created_at":"2010-11-09T09:22:21Z","updated_at":"2017-01-18T09:00:14Z","pushed_at":"2017-01-18T07:55:13Z","git_url":"git://github.com/netty/netty.git","ssh_url":"git@github.com:netty/netty.git","clone_url":"https://github.com/netty/netty.git","svn_url":"https://github.com/netty/netty","homepage":"http://netty.io/","size":44387,"stargazers_count":8864,"watchers_count":8864,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4402,"mirror_url":null,"open_issues_count":372,"forks":4402,"open_issues":372,"watchers":8864,"default_branch":"4.1"}},"_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/6224"},"html":{"href":"https://github.com/netty/netty/pull/6224"},"issue":{"href":"https://api.github.com/repos/netty/netty/issues/6224"},"comments":{"href":"https://api.github.com/repos/netty/netty/issues/6224/comments"},"review_comments":{"href":"https://api.github.com/repos/netty/netty/pulls/6224/comments"},"review_comment":{"href":"https://api.github.com/repos/netty/netty/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/netty/netty/pulls/6224/commits"},"statuses":{"href":"https://api.github.com/repos/netty/netty/statuses/2692dc06fd1b0dca697388be013d12944644b930"}}}}
{"actor":{"display_login":"jasontedor"}}