{"action":"created","comment":{"url":"https://api.github.com/repos/netty/netty/pulls/comments/64456713","id":64456713,"diff_hunk":"@@ -0,0 +1,162 @@\n+/*\n+ * Copyright 2016 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+package io.netty.microbench.concurrent;\n+\n+import io.netty.microbench.util.AbstractMicrobenchmark;\n+import io.netty.util.concurrent.DefaultEventExecutor;\n+import io.netty.util.concurrent.DefaultPromise;\n+import io.netty.util.concurrent.EventExecutor;\n+import io.netty.util.concurrent.Future;\n+import io.netty.util.concurrent.GenericFutureListener;\n+import io.netty.util.concurrent.Promise;\n+import org.openjdk.jmh.annotations.AuxCounters;\n+import org.openjdk.jmh.annotations.Benchmark;\n+import org.openjdk.jmh.annotations.Fork;\n+import org.openjdk.jmh.annotations.Level;\n+import org.openjdk.jmh.annotations.Measurement;\n+import org.openjdk.jmh.annotations.Param;\n+import org.openjdk.jmh.annotations.Scope;\n+import org.openjdk.jmh.annotations.Setup;\n+import org.openjdk.jmh.annotations.State;\n+import org.openjdk.jmh.annotations.TearDown;\n+import org.openjdk.jmh.annotations.Threads;\n+import org.openjdk.jmh.annotations.Warmup;\n+\n+import java.util.concurrent.CountDownLatch;\n+import java.util.concurrent.ExecutionException;\n+import java.util.concurrent.ExecutorService;\n+import java.util.concurrent.Executors;\n+import java.util.concurrent.TimeUnit;\n+import java.util.concurrent.TimeoutException;\n+import java.util.concurrent.atomic.AtomicLong;\n+\n+@State(Scope.Benchmark)\n+@Fork(1)\n+@Threads(1)\n+@Warmup(iterations = 5)\n+@Measurement(iterations = 5)\n+public class DefaultPromiseBenchmark extends AbstractMicrobenchmark {\n+    private ExecutorService executorService;\n+    private EventExecutor executor;\n+    private TestGenericFutureListener[] listeners;\n+    private TestGenericFutureListener[] lastListeners;\n+    private static AtomicLong doneCount = new AtomicLong();\n+    private static CountDownLatch testLatch;\n+    private final Runnable toEventLoopRunnable = new Runnable() {\n+        @Override\n+        public void run() {\n+            startOutEventLoop();\n+        }\n+    };\n+\n+    @Param({ \"100000\", \"1000000\" })\n+    public int numPromises;\n+\n+    @Param({ \"1\", \"4\" })\n+    public int numListeners;\n+\n+    @Param({ \"0\", \"4\" })\n+    public int lateListeners;\n+\n+    @AuxCounters\n+    @State(Scope.Thread)\n+    public static class DoneCounter {\n+        @Setup(Level.Iteration)\n+        public void clean() {\n+            doneCount.set(0);\n+        }\n+\n+        public long doneCount() {\n+            return doneCount.get();\n+        }\n+    }\n+\n+    @Setup(Level.Trial)\n+    public void setupTrial() {\n+        executorService = Executors.newSingleThreadExecutor();\n+        executor = new DefaultEventExecutor(executorService);\n+        listeners = new TestGenericFutureListener[numListeners];\n+        for (int i = 0; i < listeners.length; ++i) {\n+            listeners[i] = new TestGenericFutureListener();\n+        }\n+        lastListeners = new TestGenericFutureListener[lateListeners];\n+        for (int i = 0; i < lastListeners.length; ++i) {\n+            lastListeners[i] = new TestGenericFutureListener();\n+        }\n+    }\n+\n+    @Setup(Level.Invocation)\n+    public void setupInvocation() {\n+        testLatch = new CountDownLatch(numPromises * (listeners.length + lastListeners.length));\n+    }\n+\n+    @TearDown(Level.Trial)\n+    public void teardownTrial() {\n+        final Future<?> f;\n+        try {\n+            executorService.shutdown();\n+        } finally {\n+            f = executor.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS);\n+        }\n+        try {\n+            executorService.awaitTermination(5, TimeUnit.SECONDS);\n+        } catch (InterruptedException e) {\n+            e.printStackTrace();\n+        }\n+        try {\n+            f.get(5, TimeUnit.SECONDS);\n+        } catch (InterruptedException e) {\n+            e.printStackTrace();\n+        } catch (ExecutionException e) {\n+            e.printStackTrace();\n+        } catch (TimeoutException e) {\n+            e.printStackTrace();\n+        }\n+    }\n+\n+    @Benchmark\n+    public void testInEventLoop(DoneCounter doneCounter) throws Exception {\n+        startInEventLoop();\n+        testLatch.await();\n+    }\n+\n+    @Benchmark\n+    public void testOutEventLoop(DoneCounter doneCounter) throws Exception {\n+        startOutEventLoop();\n+        testLatch.await();\n+    }\n+\n+    private void startInEventLoop() {\n+        executor.execute(toEventLoopRunnable);\n+    }\n+\n+    private void startOutEventLoop() {\n+        for (int i = 0; i < numPromises; ++i) {\n+            Promise<Void> p = new DefaultPromise<Void>(executor);\n+            p.addListeners(listeners);\n+            p.setSuccess(null);\n+            p.addListeners(lastListeners);","path":"microbench/src/main/java/io/netty/microbench/concurrent/DefaultPromiseBenchmark.java","position":135,"original_position":151,"commit_id":"413e7c8e251642934a73b3db444886e8786f8e72","original_commit_id":"1611c52fcc48b365435e9cec7d4b44d9773a150a","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"body":"> Microbenchmarking multithreading should be generally considered intractable.\r\n\r\nFair enough ... as discussed in another comment ... let me put this close this PR.","created_at":"2016-05-24T19:17:10Z","updated_at":"2016-05-24T19:17:10Z","html_url":"https://github.com/netty/netty/pull/5222#discussion_r64456713","pull_request_url":"https://api.github.com/repos/netty/netty/pulls/5222","_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/comments/64456713"},"html":{"href":"https://github.com/netty/netty/pull/5222#discussion_r64456713"},"pull_request":{"href":"https://api.github.com/repos/netty/netty/pulls/5222"}}},"pull_request":{"url":"https://api.github.com/repos/netty/netty/pulls/5222","id":69208238,"html_url":"https://github.com/netty/netty/pull/5222","diff_url":"https://github.com/netty/netty/pull/5222.diff","patch_url":"https://github.com/netty/netty/pull/5222.patch","issue_url":"https://api.github.com/repos/netty/netty/issues/5222","number":5222,"state":"open","locked":false,"title":"DefaultPromise MicroBenchmark","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"body":"Motivation:\r\nThere is no microbench for DefaultPromise.\r\n\r\nModifications:\r\n- Create a benchmark which covers a few mainstream use cases of DefaultPromise\r\n\r\nResult:\r\nJMH microbench exists for DefaultPromise","created_at":"2016-05-06T20:48:34Z","updated_at":"2016-05-24T19:17:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"64ff500e7efcace13577d24a2789be54580cafd3","assignee":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/netty/netty/milestones/141","html_url":"https://github.com/netty/netty/milestones/4.0.37.Final","labels_url":"https://api.github.com/repos/netty/netty/milestones/141/labels","id":1682502,"number":141,"title":"4.0.37.Final","description":"","creator":{"login":"normanmaurer","id":439362,"avatar_url":"https://avatars.githubusercontent.com/u/439362?v=3","gravatar_id":"","url":"https://api.github.com/users/normanmaurer","html_url":"https://github.com/normanmaurer","followers_url":"https://api.github.com/users/normanmaurer/followers","following_url":"https://api.github.com/users/normanmaurer/following{/other_user}","gists_url":"https://api.github.com/users/normanmaurer/gists{/gist_id}","starred_url":"https://api.github.com/users/normanmaurer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/normanmaurer/subscriptions","organizations_url":"https://api.github.com/users/normanmaurer/orgs","repos_url":"https://api.github.com/users/normanmaurer/repos","events_url":"https://api.github.com/users/normanmaurer/events{/privacy}","received_events_url":"https://api.github.com/users/normanmaurer/received_events","type":"User","site_admin":false},"open_issues":55,"closed_issues":89,"state":"open","created_at":"2016-04-04T16:35:57Z","updated_at":"2016-05-24T19:06:47Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/netty/netty/pulls/5222/commits","review_comments_url":"https://api.github.com/repos/netty/netty/pulls/5222/comments","review_comment_url":"https://api.github.com/repos/netty/netty/pulls/comments{/number}","comments_url":"https://api.github.com/repos/netty/netty/issues/5222/comments","statuses_url":"https://api.github.com/repos/netty/netty/statuses/413e7c8e251642934a73b3db444886e8786f8e72","head":{"label":"Scottmitch:default_promise_bench","ref":"default_promise_bench","sha":"413e7c8e251642934a73b3db444886e8786f8e72","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"repo":{"id":21251366,"name":"netty","full_name":"Scottmitch/netty","owner":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Scottmitch/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":true,"url":"https://api.github.com/repos/Scottmitch/netty","forks_url":"https://api.github.com/repos/Scottmitch/netty/forks","keys_url":"https://api.github.com/repos/Scottmitch/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Scottmitch/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Scottmitch/netty/teams","hooks_url":"https://api.github.com/repos/Scottmitch/netty/hooks","issue_events_url":"https://api.github.com/repos/Scottmitch/netty/issues/events{/number}","events_url":"https://api.github.com/repos/Scottmitch/netty/events","assignees_url":"https://api.github.com/repos/Scottmitch/netty/assignees{/user}","branches_url":"https://api.github.com/repos/Scottmitch/netty/branches{/branch}","tags_url":"https://api.github.com/repos/Scottmitch/netty/tags","blobs_url":"https://api.github.com/repos/Scottmitch/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Scottmitch/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Scottmitch/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/Scottmitch/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Scottmitch/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/Scottmitch/netty/languages","stargazers_url":"https://api.github.com/repos/Scottmitch/netty/stargazers","contributors_url":"https://api.github.com/repos/Scottmitch/netty/contributors","subscribers_url":"https://api.github.com/repos/Scottmitch/netty/subscribers","subscription_url":"https://api.github.com/repos/Scottmitch/netty/subscription","commits_url":"https://api.github.com/repos/Scottmitch/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/Scottmitch/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/Scottmitch/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/Scottmitch/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/Scottmitch/netty/contents/{+path}","compare_url":"https://api.github.com/repos/Scottmitch/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Scottmitch/netty/merges","archive_url":"https://api.github.com/repos/Scottmitch/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Scottmitch/netty/downloads","issues_url":"https://api.github.com/repos/Scottmitch/netty/issues{/number}","pulls_url":"https://api.github.com/repos/Scottmitch/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/Scottmitch/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/Scottmitch/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Scottmitch/netty/labels{/name}","releases_url":"https://api.github.com/repos/Scottmitch/netty/releases{/id}","deployments_url":"https://api.github.com/repos/Scottmitch/netty/deployments","created_at":"2014-06-26T18:56:19Z","updated_at":"2016-02-08T18:45:50Z","pushed_at":"2016-05-24T19:10:53Z","git_url":"git://github.com/Scottmitch/netty.git","ssh_url":"git@github.com:Scottmitch/netty.git","clone_url":"https://github.com/Scottmitch/netty.git","svn_url":"https://github.com/Scottmitch/netty","homepage":"http://netty.io/","size":40100,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"netty:4.1","ref":"4.1","sha":"26a175cd94c50aebdd3bdcba8e3cd0a30f664870","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":"2016-05-24T15:36:25Z","pushed_at":"2016-05-24T19:10:53Z","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":67432,"stargazers_count":6901,"watchers_count":6901,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3524,"mirror_url":null,"open_issues_count":308,"forks":3524,"open_issues":308,"watchers":6901,"default_branch":"4.1"}},"_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/5222"},"html":{"href":"https://github.com/netty/netty/pull/5222"},"issue":{"href":"https://api.github.com/repos/netty/netty/issues/5222"},"comments":{"href":"https://api.github.com/repos/netty/netty/issues/5222/comments"},"review_comments":{"href":"https://api.github.com/repos/netty/netty/pulls/5222/comments"},"review_comment":{"href":"https://api.github.com/repos/netty/netty/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/netty/netty/pulls/5222/commits"},"statuses":{"href":"https://api.github.com/repos/netty/netty/statuses/413e7c8e251642934a73b3db444886e8786f8e72"}}}}
{"actor":{"display_login":"Scottmitch"}}