{"action":"created","comment":{"url":"https://api.github.com/repos/druid-io/druid/pulls/comments/64678064","id":64678064,"diff_hunk":"@@ -0,0 +1,104 @@\n+/*\n+ * Licensed to Metamarkets Group Inc. (Metamarkets) under one\n+ * or more contributor license agreements. See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership. Metamarkets licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"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,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied. See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package io.druid.collections;\n+\n+import com.google.common.base.Preconditions;\n+import com.google.common.base.Supplier;\n+import com.metamx.common.ISE;\n+import com.metamx.common.logger.Logger;\n+\n+import java.io.IOException;\n+import java.util.concurrent.ArrayBlockingQueue;\n+import java.util.concurrent.BlockingQueue;\n+import java.util.concurrent.atomic.AtomicBoolean;\n+\n+/**\n+ * Pool that pre-generates objects up to a limit, then permits possibly-blocking \"take\" operations.\n+ */\n+public class BlockingPool<T>\n+{\n+  private static final Logger log = new Logger(BlockingPool.class);\n+\n+  private final BlockingQueue<T> objects;\n+\n+  public BlockingPool(\n+      Supplier<T> generator,\n+      int limit\n+  )\n+  {\n+    this.objects = limit > 0 ? new ArrayBlockingQueue<T>(limit) : null;\n+\n+    for (int i = 0; i < limit; i++) {\n+      objects.add(generator.get());\n+    }\n+  }\n+\n+  public ResourceHolder<T> take() throws InterruptedException\n+  {\n+    Preconditions.checkState(objects != null, \"Pool was initialized with limit = 0, there are no objects to take.\");\n+    return new ObjectResourceHolder(objects.take());\n+  }\n+\n+  private class ObjectResourceHolder implements ResourceHolder<T>\n+  {\n+    private AtomicBoolean closed = new AtomicBoolean(false);\n+    private final T object;\n+\n+    public ObjectResourceHolder(final T object)\n+    {\n+      this.object = object;\n+    }\n+\n+    // WARNING: it is entirely possible for a caller to hold onto the object and call ObjectResourceHolder.close,\n+    // Then still use that object even though it will be offered to someone else in StupidPool.take\n+    @Override\n+    public T get()\n+    {\n+      if (closed.get()) {\n+        throw new ISE(\"Already Closed!\");\n+      }\n+\n+      return object;\n+    }\n+\n+    @Override\n+    public void close() throws IOException\n+    {\n+      if (!closed.compareAndSet(false, true)) {\n+        log.warn(new ISE(\"Already Closed!\"), \"Already closed\");\n+        return;\n+      }\n+      if (!objects.offer(object)) {\n+        throw new ISE(\"WTF?! Queue offer failed\");\n+      }\n+    }\n+\n+    @Override\n+    protected void finalize() throws Throwable\n+    {\n+      if (closed.compareAndSet(false, true)) {\n+        log.warn(\"Not closed! Object was[%s]. Returning to pool.\", object);","path":"common/src/main/java/io/druid/collections/BlockingPool.java","position":97,"original_position":97,"commit_id":"535a79403f45011d20b6da311c69bfa77a26d161","original_commit_id":"535a79403f45011d20b6da311c69bfa77a26d161","user":{"login":"fjy","id":428325,"avatar_url":"https://avatars.githubusercontent.com/u/428325?v=3","gravatar_id":"","url":"https://api.github.com/users/fjy","html_url":"https://github.com/fjy","followers_url":"https://api.github.com/users/fjy/followers","following_url":"https://api.github.com/users/fjy/following{/other_user}","gists_url":"https://api.github.com/users/fjy/gists{/gist_id}","starred_url":"https://api.github.com/users/fjy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fjy/subscriptions","organizations_url":"https://api.github.com/users/fjy/orgs","repos_url":"https://api.github.com/users/fjy/repos","events_url":"https://api.github.com/users/fjy/events{/privacy}","received_events_url":"https://api.github.com/users/fjy/received_events","type":"User","site_admin":false},"body":"is it possible here to try to return the same object to pool?","created_at":"2016-05-26T01:03:06Z","updated_at":"2016-05-26T01:03:06Z","html_url":"https://github.com/druid-io/druid/pull/2998#discussion_r64678064","pull_request_url":"https://api.github.com/repos/druid-io/druid/pulls/2998","_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/comments/64678064"},"html":{"href":"https://github.com/druid-io/druid/pull/2998#discussion_r64678064"},"pull_request":{"href":"https://api.github.com/repos/druid-io/druid/pulls/2998"}}},"pull_request":{"url":"https://api.github.com/repos/druid-io/druid/pulls/2998","id":70785494,"html_url":"https://github.com/druid-io/druid/pull/2998","diff_url":"https://github.com/druid-io/druid/pull/2998.diff","patch_url":"https://github.com/druid-io/druid/pull/2998.patch","issue_url":"https://api.github.com/repos/druid-io/druid/issues/2998","number":2998,"state":"open","locked":false,"title":"Alternative groupBy strategy.","user":{"login":"gianm","id":1214075,"avatar_url":"https://avatars.githubusercontent.com/u/1214075?v=3","gravatar_id":"","url":"https://api.github.com/users/gianm","html_url":"https://github.com/gianm","followers_url":"https://api.github.com/users/gianm/followers","following_url":"https://api.github.com/users/gianm/following{/other_user}","gists_url":"https://api.github.com/users/gianm/gists{/gist_id}","starred_url":"https://api.github.com/users/gianm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gianm/subscriptions","organizations_url":"https://api.github.com/users/gianm/orgs","repos_url":"https://api.github.com/users/gianm/repos","events_url":"https://api.github.com/users/gianm/events{/privacy}","received_events_url":"https://api.github.com/users/gianm/received_events","type":"User","site_admin":false},"body":"![](http://k39.kn3.net/taringa/1/6/7/4/5/6/1/natyvan/652.jpg?3924)\r\n\r\nThis patch introduces a GroupByStrategy concept and two strategies: \"oldFaithful\"\r\nis the current groupBy strategy and \"epinephelinae\" is a new one. It also\r\nintroduces a merge buffers concept in DruidProcessingModule, to try to better\r\nmanage memory used for merging.\r\n\r\nBoth of these are described in more detail in #2987.\r\n\r\nThere are two goals of this patch:\r\n\r\n1. Make it possible for historical/realtime nodes to return larger groupBy\r\n   result sets, faster, with better memory management.\r\n2. Make it possible for brokers to merge streams when there are no order-by\r\n   columns, avoiding materialization.\r\n\r\nThis patch does not do anything to help with memory management on the broker\r\nwhen there are order-by columns or when there are nested queries. That could\r\npotentially be done in a future patch.\r\n\r\nBenchmarks:\r\n\r\nmaster\r\n\r\n```\r\nBenchmark                                       (numSegments)  (rowsPerSegment)  (schemaAndQuery)  Mode  Cnt       Score      Error  Units\r\nGroupByBenchmark.processSingleIncrementalIndex              4            100000           basic.A  avgt   25  109206.640 ± 2110.087  us/op\r\nGroupByBenchmark.processSingleQueryableIndex                4            100000           basic.A  avgt   25   79239.089 ± 1903.127  us/op\r\nGroupByBenchmark.queryMultiQueryableIndex                   4            100000           basic.A  avgt   25  376020.150 ± 4878.307  us/op\r\nGroupByBenchmark.querySingleIncrementalIndex                4            100000           basic.A  avgt   25  253640.355 ± 9018.422  us/op\r\nGroupByBenchmark.querySingleQueryableIndex                  4            100000           basic.A  avgt   25  198558.886 ± 7151.646  us/op\r\n```\r\n\r\nepinephelinae\r\n\r\n```\r\nBenchmark                                       (numSegments)  (rowsPerSegment)  (schemaAndQuery)  Mode  Cnt       Score      Error  Units\r\nGroupByBenchmark.processSingleIncrementalIndex              4            100000           basic.A  avgt   25   59674.994 ± 1996.179  us/op\r\nGroupByBenchmark.processSingleQueryableIndex                4            100000           basic.A  avgt   25   38382.406 ±  848.041  us/op\r\nGroupByBenchmark.queryMultiQueryableIndex                   4            100000           basic.A  avgt   25  189633.397 ± 3665.856  us/op\r\nGroupByBenchmark.querySingleIncrementalIndex                4            100000           basic.A  avgt   25   69098.673 ± 3138.578  us/op\r\nGroupByBenchmark.querySingleQueryableIndex                  4            100000           basic.A  avgt   25   45949.471 ± 1807.845  us/op\r\n```","created_at":"2016-05-20T00:17:57Z","updated_at":"2016-05-26T01:03:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"02293844070f1c92139390e3d62276af48a5dc47","assignee":null,"milestone":{"url":"https://api.github.com/repos/druid-io/druid/milestones/20","html_url":"https://github.com/druid-io/druid/milestones/0.9.2","labels_url":"https://api.github.com/repos/druid-io/druid/milestones/20/labels","id":1571409,"number":20,"title":"0.9.2","description":"","creator":{"login":"fjy","id":428325,"avatar_url":"https://avatars.githubusercontent.com/u/428325?v=3","gravatar_id":"","url":"https://api.github.com/users/fjy","html_url":"https://github.com/fjy","followers_url":"https://api.github.com/users/fjy/followers","following_url":"https://api.github.com/users/fjy/following{/other_user}","gists_url":"https://api.github.com/users/fjy/gists{/gist_id}","starred_url":"https://api.github.com/users/fjy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fjy/subscriptions","organizations_url":"https://api.github.com/users/fjy/orgs","repos_url":"https://api.github.com/users/fjy/repos","events_url":"https://api.github.com/users/fjy/events{/privacy}","received_events_url":"https://api.github.com/users/fjy/received_events","type":"User","site_admin":false},"open_issues":25,"closed_issues":6,"state":"open","created_at":"2016-02-08T22:01:21Z","updated_at":"2016-05-25T19:05:10Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/druid-io/druid/pulls/2998/commits","review_comments_url":"https://api.github.com/repos/druid-io/druid/pulls/2998/comments","review_comment_url":"https://api.github.com/repos/druid-io/druid/pulls/comments{/number}","comments_url":"https://api.github.com/repos/druid-io/druid/issues/2998/comments","statuses_url":"https://api.github.com/repos/druid-io/druid/statuses/535a79403f45011d20b6da311c69bfa77a26d161","head":{"label":"gianm:epinephelinae","ref":"epinephelinae","sha":"535a79403f45011d20b6da311c69bfa77a26d161","user":{"login":"gianm","id":1214075,"avatar_url":"https://avatars.githubusercontent.com/u/1214075?v=3","gravatar_id":"","url":"https://api.github.com/users/gianm","html_url":"https://github.com/gianm","followers_url":"https://api.github.com/users/gianm/followers","following_url":"https://api.github.com/users/gianm/following{/other_user}","gists_url":"https://api.github.com/users/gianm/gists{/gist_id}","starred_url":"https://api.github.com/users/gianm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gianm/subscriptions","organizations_url":"https://api.github.com/users/gianm/orgs","repos_url":"https://api.github.com/users/gianm/repos","events_url":"https://api.github.com/users/gianm/events{/privacy}","received_events_url":"https://api.github.com/users/gianm/received_events","type":"User","site_admin":false},"repo":{"id":28350072,"name":"druid","full_name":"gianm/druid","owner":{"login":"gianm","id":1214075,"avatar_url":"https://avatars.githubusercontent.com/u/1214075?v=3","gravatar_id":"","url":"https://api.github.com/users/gianm","html_url":"https://github.com/gianm","followers_url":"https://api.github.com/users/gianm/followers","following_url":"https://api.github.com/users/gianm/following{/other_user}","gists_url":"https://api.github.com/users/gianm/gists{/gist_id}","starred_url":"https://api.github.com/users/gianm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gianm/subscriptions","organizations_url":"https://api.github.com/users/gianm/orgs","repos_url":"https://api.github.com/users/gianm/repos","events_url":"https://api.github.com/users/gianm/events{/privacy}","received_events_url":"https://api.github.com/users/gianm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gianm/druid","description":"Real²time Exploratory Analytics on Large Datasets","fork":true,"url":"https://api.github.com/repos/gianm/druid","forks_url":"https://api.github.com/repos/gianm/druid/forks","keys_url":"https://api.github.com/repos/gianm/druid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gianm/druid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gianm/druid/teams","hooks_url":"https://api.github.com/repos/gianm/druid/hooks","issue_events_url":"https://api.github.com/repos/gianm/druid/issues/events{/number}","events_url":"https://api.github.com/repos/gianm/druid/events","assignees_url":"https://api.github.com/repos/gianm/druid/assignees{/user}","branches_url":"https://api.github.com/repos/gianm/druid/branches{/branch}","tags_url":"https://api.github.com/repos/gianm/druid/tags","blobs_url":"https://api.github.com/repos/gianm/druid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gianm/druid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gianm/druid/git/refs{/sha}","trees_url":"https://api.github.com/repos/gianm/druid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gianm/druid/statuses/{sha}","languages_url":"https://api.github.com/repos/gianm/druid/languages","stargazers_url":"https://api.github.com/repos/gianm/druid/stargazers","contributors_url":"https://api.github.com/repos/gianm/druid/contributors","subscribers_url":"https://api.github.com/repos/gianm/druid/subscribers","subscription_url":"https://api.github.com/repos/gianm/druid/subscription","commits_url":"https://api.github.com/repos/gianm/druid/commits{/sha}","git_commits_url":"https://api.github.com/repos/gianm/druid/git/commits{/sha}","comments_url":"https://api.github.com/repos/gianm/druid/comments{/number}","issue_comment_url":"https://api.github.com/repos/gianm/druid/issues/comments{/number}","contents_url":"https://api.github.com/repos/gianm/druid/contents/{+path}","compare_url":"https://api.github.com/repos/gianm/druid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gianm/druid/merges","archive_url":"https://api.github.com/repos/gianm/druid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gianm/druid/downloads","issues_url":"https://api.github.com/repos/gianm/druid/issues{/number}","pulls_url":"https://api.github.com/repos/gianm/druid/pulls{/number}","milestones_url":"https://api.github.com/repos/gianm/druid/milestones{/number}","notifications_url":"https://api.github.com/repos/gianm/druid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gianm/druid/labels{/name}","releases_url":"https://api.github.com/repos/gianm/druid/releases{/id}","deployments_url":"https://api.github.com/repos/gianm/druid/deployments","created_at":"2014-12-22T17:32:01Z","updated_at":"2016-01-18T01:27:33Z","pushed_at":"2016-05-24T20:45:58Z","git_url":"git://github.com/gianm/druid.git","ssh_url":"git@github.com:gianm/druid.git","clone_url":"https://github.com/gianm/druid.git","svn_url":"https://github.com/gianm/druid","homepage":"http://druid.io","size":106393,"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":"master"}},"base":{"label":"druid-io:master","ref":"master","sha":"dcabd4b1ee1e87f83c7524b1a62cc5ad1b17687b","user":{"login":"druid-io","id":4203474,"avatar_url":"https://avatars.githubusercontent.com/u/4203474?v=3","gravatar_id":"","url":"https://api.github.com/users/druid-io","html_url":"https://github.com/druid-io","followers_url":"https://api.github.com/users/druid-io/followers","following_url":"https://api.github.com/users/druid-io/following{/other_user}","gists_url":"https://api.github.com/users/druid-io/gists{/gist_id}","starred_url":"https://api.github.com/users/druid-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druid-io/subscriptions","organizations_url":"https://api.github.com/users/druid-io/orgs","repos_url":"https://api.github.com/users/druid-io/repos","events_url":"https://api.github.com/users/druid-io/events{/privacy}","received_events_url":"https://api.github.com/users/druid-io/received_events","type":"Organization","site_admin":false},"repo":{"id":6358188,"name":"druid","full_name":"druid-io/druid","owner":{"login":"druid-io","id":4203474,"avatar_url":"https://avatars.githubusercontent.com/u/4203474?v=3","gravatar_id":"","url":"https://api.github.com/users/druid-io","html_url":"https://github.com/druid-io","followers_url":"https://api.github.com/users/druid-io/followers","following_url":"https://api.github.com/users/druid-io/following{/other_user}","gists_url":"https://api.github.com/users/druid-io/gists{/gist_id}","starred_url":"https://api.github.com/users/druid-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druid-io/subscriptions","organizations_url":"https://api.github.com/users/druid-io/orgs","repos_url":"https://api.github.com/users/druid-io/repos","events_url":"https://api.github.com/users/druid-io/events{/privacy}","received_events_url":"https://api.github.com/users/druid-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/druid-io/druid","description":"Column oriented distributed data store ideal for powering interactive applications","fork":false,"url":"https://api.github.com/repos/druid-io/druid","forks_url":"https://api.github.com/repos/druid-io/druid/forks","keys_url":"https://api.github.com/repos/druid-io/druid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/druid-io/druid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/druid-io/druid/teams","hooks_url":"https://api.github.com/repos/druid-io/druid/hooks","issue_events_url":"https://api.github.com/repos/druid-io/druid/issues/events{/number}","events_url":"https://api.github.com/repos/druid-io/druid/events","assignees_url":"https://api.github.com/repos/druid-io/druid/assignees{/user}","branches_url":"https://api.github.com/repos/druid-io/druid/branches{/branch}","tags_url":"https://api.github.com/repos/druid-io/druid/tags","blobs_url":"https://api.github.com/repos/druid-io/druid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/druid-io/druid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/druid-io/druid/git/refs{/sha}","trees_url":"https://api.github.com/repos/druid-io/druid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/druid-io/druid/statuses/{sha}","languages_url":"https://api.github.com/repos/druid-io/druid/languages","stargazers_url":"https://api.github.com/repos/druid-io/druid/stargazers","contributors_url":"https://api.github.com/repos/druid-io/druid/contributors","subscribers_url":"https://api.github.com/repos/druid-io/druid/subscribers","subscription_url":"https://api.github.com/repos/druid-io/druid/subscription","commits_url":"https://api.github.com/repos/druid-io/druid/commits{/sha}","git_commits_url":"https://api.github.com/repos/druid-io/druid/git/commits{/sha}","comments_url":"https://api.github.com/repos/druid-io/druid/comments{/number}","issue_comment_url":"https://api.github.com/repos/druid-io/druid/issues/comments{/number}","contents_url":"https://api.github.com/repos/druid-io/druid/contents/{+path}","compare_url":"https://api.github.com/repos/druid-io/druid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/druid-io/druid/merges","archive_url":"https://api.github.com/repos/druid-io/druid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/druid-io/druid/downloads","issues_url":"https://api.github.com/repos/druid-io/druid/issues{/number}","pulls_url":"https://api.github.com/repos/druid-io/druid/pulls{/number}","milestones_url":"https://api.github.com/repos/druid-io/druid/milestones{/number}","notifications_url":"https://api.github.com/repos/druid-io/druid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/druid-io/druid/labels{/name}","releases_url":"https://api.github.com/repos/druid-io/druid/releases{/id}","deployments_url":"https://api.github.com/repos/druid-io/druid/deployments","created_at":"2012-10-23T19:08:07Z","updated_at":"2016-05-25T21:06:31Z","pushed_at":"2016-05-25T23:39:39Z","git_url":"git://github.com/druid-io/druid.git","ssh_url":"git@github.com:druid-io/druid.git","clone_url":"https://github.com/druid-io/druid.git","svn_url":"https://github.com/druid-io/druid","homepage":"http://druid.io","size":130516,"stargazers_count":3268,"watchers_count":3268,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":728,"mirror_url":null,"open_issues_count":439,"forks":728,"open_issues":439,"watchers":3268,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/2998"},"html":{"href":"https://github.com/druid-io/druid/pull/2998"},"issue":{"href":"https://api.github.com/repos/druid-io/druid/issues/2998"},"comments":{"href":"https://api.github.com/repos/druid-io/druid/issues/2998/comments"},"review_comments":{"href":"https://api.github.com/repos/druid-io/druid/pulls/2998/comments"},"review_comment":{"href":"https://api.github.com/repos/druid-io/druid/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/druid-io/druid/pulls/2998/commits"},"statuses":{"href":"https://api.github.com/repos/druid-io/druid/statuses/535a79403f45011d20b6da311c69bfa77a26d161"}}}}
{"actor":{"display_login":"fjy"}}