cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [6/7] git commit: reduce object allocations done by inserter
Date Tue, 04 Dec 2012 20:34:26 GMT
reduce object allocations done by inserter


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/25bf3bf0
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/25bf3bf0
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/25bf3bf0

Branch: refs/heads/trunk
Commit: 25bf3bf04e9a43006114be520c99a953ac90bb3f
Parents: aa9a602
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Sat Dec 1 20:50:54 2012 +0900
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Tue Dec 4 14:33:58 2012 -0600

----------------------------------------------------------------------
 .../cassandra/stress/operations/Inserter.java      |   40 +++++---------
 1 files changed, 14 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/25bf3bf0/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java b/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
index 0623e4c..24c7eaa 100644
--- a/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
+++ b/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
@@ -27,10 +27,7 @@ import org.apache.cassandra.utils.FBUtilities;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 public class Inserter extends Operation
 {
@@ -46,8 +43,8 @@ public class Inserter extends Operation
         if (values == null)
             values = generateValues();
 
-        List<Column> columns = new ArrayList<Column>();
-        List<SuperColumn> superColumns = new ArrayList<SuperColumn>();
+        List<Column> columns = new ArrayList<Column>(session.getColumnsPerKey());
+        List<SuperColumn> superColumns = null;
 
         // format used for keys
         String format = "%0" + session.getTotalKeysLength() + "d";
@@ -55,12 +52,13 @@ public class Inserter extends Operation
         for (int i = 0; i < session.getColumnsPerKey(); i++)
         {
             columns.add(new Column(columnName(i, session.timeUUIDComparator))
-                                .setValue(values.get(i % values.size()))
-                                .setTimestamp(FBUtilities.timestampMicros()));
+                            .setValue(values.get(i % values.size()))
+                            .setTimestamp(FBUtilities.timestampMicros()));
         }
 
         if (session.getColumnFamilyType() == ColumnFamilyType.Super)
         {
+            superColumns = new ArrayList<SuperColumn>();
             // supers = [SuperColumn('S' + str(j), columns) for j in xrange(supers_per_key)]
             for (int i = 0; i < session.getSuperColumns(); i++)
             {
@@ -70,17 +68,15 @@ public class Inserter extends Operation
         }
 
         String rawKey = String.format(format, index);
-        Map<ByteBuffer, Map<String, List<Mutation>>> record = new HashMap<ByteBuffer,
Map<String, List<Mutation>>>();
-
-        record.put(ByteBufferUtil.bytes(rawKey), session.getColumnFamilyType() == ColumnFamilyType.Super
-                                                                                ? getSuperColumnsMutationMap(superColumns)
-                                                                                : getColumnsMutationMap(columns));
+        Map<String, List<Mutation>> row = session.getColumnFamilyType() == ColumnFamilyType.Super
+                                        ? getSuperColumnsMutationMap(superColumns)
+                                        : getColumnsMutationMap(columns);
+        Map<ByteBuffer, Map<String, List<Mutation>>> record = Collections.singletonMap(ByteBufferUtil.bytes(rawKey),
row);
 
         long start = System.currentTimeMillis();
 
         boolean success = false;
         String exceptionMessage = null;
-
         for (int t = 0; t < session.getRetryTimes(); t++)
         {
             if (success)
@@ -114,33 +110,25 @@ public class Inserter extends Operation
 
     private Map<String, List<Mutation>> getSuperColumnsMutationMap(List<SuperColumn>
superColumns)
     {
-        List<Mutation> mutations = new ArrayList<Mutation>();
-        Map<String, List<Mutation>> mutationMap = new HashMap<String, List<Mutation>>();
-
+        List<Mutation> mutations = new ArrayList<Mutation>(superColumns.size());
         for (SuperColumn s : superColumns)
         {
             ColumnOrSuperColumn superColumn = new ColumnOrSuperColumn().setSuper_column(s);
             mutations.add(new Mutation().setColumn_or_supercolumn(superColumn));
         }
 
-        mutationMap.put("Super1", mutations);
-
-        return mutationMap;
+        return Collections.singletonMap("Super1", mutations);
     }
 
     private Map<String, List<Mutation>> getColumnsMutationMap(List<Column>
columns)
     {
-        List<Mutation> mutations = new ArrayList<Mutation>();
-        Map<String, List<Mutation>> mutationMap = new HashMap<String, List<Mutation>>();
-
+        List<Mutation> mutations = new ArrayList<Mutation>(columns.size());
         for (Column c : columns)
         {
             ColumnOrSuperColumn column = new ColumnOrSuperColumn().setColumn(c);
             mutations.add(new Mutation().setColumn_or_supercolumn(column));
         }
 
-        mutationMap.put("Standard1", mutations);
-
-        return mutationMap;
+        return Collections.singletonMap("Standard1", mutations);
     }
 }


Mime
View raw message