Author: gdusbabek
Date: Wed Apr 14 19:51:38 2010
New Revision: 934147

URL: http://svn.apache.org/viewvc?rev=934147&view=rev
Log:
implement a compaction benchmark. Patch by Stu Hood, reviewed by Gary Dusbabek. 
CASSANDRA-767

Added:
    cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionSpeedTest.java
Modified:
    cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java

Added: 
cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionSpeedTest.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionSpeedTest.java?rev=934147&view=auto
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionSpeedTest.java 
(added)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionSpeedTest.java 
Wed Apr 14 19:51:38 2010
@@ -0,0 +1,109 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.cassandra.db;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.*;
+
+import org.apache.cassandra.Util;
+
+import org.junit.Test;
+
+import org.apache.cassandra.io.sstable.SSTableReader;
+import org.apache.cassandra.io.sstable.SSTableUtils;
+import org.apache.cassandra.CleanupHelper;
+import org.apache.cassandra.db.filter.QueryPath;
+import org.apache.cassandra.utils.FBUtilities;
+import static junit.framework.Assert.assertEquals;
+
+public class CompactionSpeedTest extends CleanupHelper
+{
+    public static final String TABLE1 = "Keyspace1";
+    public static final InetAddress LOCAL = FBUtilities.getLocalAddress();
+
+    /**
+     * Test compaction with a very wide row.
+     */
+    @Test
+    public void testCompactionWide() throws Exception
+    {
+        testCompaction(2, 1, 200000);
+    }
+
+    /**
+     * Test compaction with lots of skinny rows.
+     */
+    @Test
+    public void testCompactionSlim() throws Exception
+    {
+        testCompaction(2, 200000, 1);
+    }
+
+    /**
+     * Test compaction with lots of small sstables.
+     */
+    @Test
+    public void testCompactionMany() throws Exception
+    {
+        testCompaction(100, 800, 5);
+    }
+
+    protected void testCompaction(int sstableCount, int rowsPerSSTable, int 
colsPerRow) throws Exception
+    {
+        CompactionManager.instance.disableAutoCompaction();
+
+        Table table = Table.open(TABLE1);
+        ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
+
+        ArrayList<SSTableReader> sstables = new ArrayList<SSTableReader>();
+        for (int k = 0; k < sstableCount; k++)
+        {
+            SortedMap<String,ColumnFamily> rows = new 
TreeMap<String,ColumnFamily>();
+            for (int j = 0; j < rowsPerSSTable; j++)
+            {
+                String key = String.valueOf(j);
+                IColumn[] cols = new IColumn[colsPerRow];
+                for (int i = 0; i < colsPerRow; i++)
+                {
+                    // last sstable has highest timestamps
+                    cols[i] = Util.column(String.valueOf(i), 
String.valueOf(i), k);
+                }
+                rows.put(key, SSTableUtils.createCF(Long.MIN_VALUE, 
Integer.MIN_VALUE, cols));
+            }
+            SSTableReader sstable = SSTableUtils.writeSSTable(rows);
+            sstables.add(sstable);
+            store.addSSTable(sstable);
+        }
+
+        // give garbage collection a bit of time to catch up
+        Thread.sleep(1000);
+
+        long start = System.currentTimeMillis();
+        CompactionManager.instance.doCompaction(store, sstables, 
CompactionManager.getDefaultGCBefore());
+        System.out.println(String.format("%s: sstables=%d rowsper=%d 
colsper=%d: %d ms",
+                                         this.getClass().getName(),
+                                         sstableCount,
+                                         rowsPerSSTable,
+                                         colsPerRow,
+                                         System.currentTimeMillis() - start));
+    }
+}

Modified: 
cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java?rev=934147&r1=934146&r2=934147&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java 
(original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java 
Wed Apr 14 19:51:38 2010
@@ -29,15 +29,12 @@ import java.util.TreeMap;
 
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.Column;
+import org.apache.cassandra.db.IColumn;
 import org.apache.cassandra.db.ColumnFamily;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.io.util.DataOutputBuffer;
 
-/**
- * TODO: These methods imitate Memtable.writeSortedKeys to some degree, but
- * because it is so monolithic, we can't reuse much.
- */
 public class SSTableUtils
 {
     // first configured table and cf
@@ -49,6 +46,15 @@ public class SSTableUtils
         CFNAME = Table.open(TABLENAME).getColumnFamilies().iterator().next();
     }
 
+    public static ColumnFamily createCF(long mfda, int ldt, IColumn... cols)
+    {
+        ColumnFamily cf = ColumnFamily.create(TABLENAME, CFNAME);
+        cf.delete(ldt, mfda);
+        for (IColumn col : cols)
+            cf.addColumn(col);
+        return cf;
+    }
+
     public static File tempSSTableFile(String tablename, String cfname) throws 
IOException
     {
         File tempdir = File.createTempFile(tablename, cfname);


Reply via email to