cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Jirsa (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CASSANDRA-13760) presize collections
Date Thu, 31 Aug 2017 03:48:00 GMT

    [ https://issues.apache.org/jira/browse/CASSANDRA-13760?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16148400#comment-16148400
] 

Jeff Jirsa edited comment on CASSANDRA-13760 at 8/31/17 3:47 AM:
-----------------------------------------------------------------

The unit test run was clean. The dtest run timed out before I saw the result, so I've restarted
it [here|https://builds.apache.org/view/A-D/view/Cassandra/job/Cassandra-devbranch-dtest/254/]

I'm +1 on the patch as long as the dtest run comes back no worse than the other trunk dtests.

I've made two small changes to the version I've uploaded as {{0001-Presize-collections.patch}}
(which you're free to use, or you can commit from your own branch with your own name/email/whatever)
:

On {{src/java/org/apache/cassandra/db/compaction/CompactionStrategyManager.java}} , I added
the expected size to the currGroup list made within the loop as well:

{code}
--- a/src/java/org/apache/cassandra/db/compaction/AbstractCompactionStrategy.java
+++ b/src/java/org/apache/cassandra/db/compaction/AbstractCompactionStrategy.java
@@ -539,7 +539,7 @@ public abstract class AbstractCompactionStrategy
         Collections.sort(sortedSSTablesToGroup, SSTableReader.sstableComparator);

         Collection<Collection<SSTableReader>> groupedSSTables = new ArrayList<>();
-        Collection<SSTableReader> currGroup = new ArrayList<>();
+        Collection<SSTableReader> currGroup = new ArrayList<>(groupSize);

         for (SSTableReader sstable : sortedSSTablesToGroup)
         {
@@ -547,7 +547,7 @@ public abstract class AbstractCompactionStrategy
             if (currGroup.size() == groupSize)
             {
                 groupedSSTables.add(currGroup);
-                currGroup = new ArrayList<>();
+                currGroup = new ArrayList<>(groupSize);
             }
         }
{code}

Similarly in {{src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java}}
, added the initial size to the nested group as well:

{code}
--- a/src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java
+++ b/src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java
@@ -223,14 +223,14 @@ public class LeveledCompactionStrategy extends AbstractCompactionStrategy

         for (Collection<SSTableReader> levelOfSSTables : sstablesByLevel.values())
         {
-            Collection<SSTableReader> currGroup = new ArrayList<>();
+            Collection<SSTableReader> currGroup = new ArrayList<>(groupSize);
             for (SSTableReader sstable : levelOfSSTables)
             {
                 currGroup.add(sstable);
                 if (currGroup.size() == groupSize)
                 {
                     groupedSSTables.add(currGroup);
-                    currGroup = new ArrayList<>();
+                    currGroup = new ArrayList<>(groupSize);
                 }
             }
{code}

Other than that, +1, looks good.





was (Author: jjirsa):
The unit test run was clean. The dtest run timed out before I saw the result, so I've restarted
it [here|https://builds.apache.org/view/A-D/view/Cassandra/job/Cassandra-devbranch-dtest/254/]

I'm +1 on the patch as long as the dtest run comes back no worse than the other trunk dtests.

I've made two small changes to the version I've uploaded as {{0001-Presize-collections.patch}}
:

On {{src/java/org/apache/cassandra/db/compaction/CompactionStrategyManager.java}} , I added
the expected size to the currGroup list made within the loop as well:

{code}
--- a/src/java/org/apache/cassandra/db/compaction/AbstractCompactionStrategy.java
+++ b/src/java/org/apache/cassandra/db/compaction/AbstractCompactionStrategy.java
@@ -539,7 +539,7 @@ public abstract class AbstractCompactionStrategy
         Collections.sort(sortedSSTablesToGroup, SSTableReader.sstableComparator);

         Collection<Collection<SSTableReader>> groupedSSTables = new ArrayList<>();
-        Collection<SSTableReader> currGroup = new ArrayList<>();
+        Collection<SSTableReader> currGroup = new ArrayList<>(groupSize);

         for (SSTableReader sstable : sortedSSTablesToGroup)
         {
@@ -547,7 +547,7 @@ public abstract class AbstractCompactionStrategy
             if (currGroup.size() == groupSize)
             {
                 groupedSSTables.add(currGroup);
-                currGroup = new ArrayList<>();
+                currGroup = new ArrayList<>(groupSize);
             }
         }
{code}

Similarly in {{src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java}}
, added the initial size to the nested group as well:

{code}
--- a/src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java
+++ b/src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java
@@ -223,14 +223,14 @@ public class LeveledCompactionStrategy extends AbstractCompactionStrategy

         for (Collection<SSTableReader> levelOfSSTables : sstablesByLevel.values())
         {
-            Collection<SSTableReader> currGroup = new ArrayList<>();
+            Collection<SSTableReader> currGroup = new ArrayList<>(groupSize);
             for (SSTableReader sstable : levelOfSSTables)
             {
                 currGroup.add(sstable);
                 if (currGroup.size() == groupSize)
                 {
                     groupedSSTables.add(currGroup);
-                    currGroup = new ArrayList<>();
+                    currGroup = new ArrayList<>(groupSize);
                 }
             }
{code}

Other than that, +1, looks good.




> presize collections
> -------------------
>
>                 Key: CASSANDRA-13760
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-13760
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Core
>            Reporter: Dave Brosius
>            Assignee: Dave Brosius
>            Priority: Trivial
>             Fix For: 4.x
>
>         Attachments: 0001-Presize-collections.patch, 13760.txt
>
>
> presize collections where sane, to avoid reallocs, or excess garbage



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message