From 7a49fb07979f7f8edaa638e5decce2366dda4102 Mon Sep 17 00:00:00 2001 From: Sylvain Lebresne Date: Fri, 29 Apr 2011 17:09:26 +0000 Subject: [PATCH] merge CASSANDRA-2558 from 0.8 git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1097889 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + conf/cassandra.yaml | 13 +++++++++---- src/java/org/apache/cassandra/config/Config.java | 2 +- .../apache/cassandra/config/DatabaseDescriptor.java | 11 +++++++---- .../org/apache/cassandra/db/CompactionManager.java | 4 +--- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1c447ccf31..9bf65991e3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,6 +17,7 @@ * fix incorrect use of NBHM.size in ReadCallback that could cause reads to time out even when responses were received (CASSAMDRA-2552) * trigger read repair correctly for LOCAL_QUORUM reads (CASSANDRA-2556) + * Allow configuring the number of compaction thread (CASSANDRA-2558) 0.8.0-beta1 diff --git a/conf/cassandra.yaml b/conf/cassandra.yaml index 7d817c1f99..8135815497 100644 --- a/conf/cassandra.yaml +++ b/conf/cassandra.yaml @@ -249,10 +249,15 @@ column_index_size_in_kb: 64 # will be logged specifying the row key. in_memory_compaction_limit_in_mb: 64 -# Enables multiple compactions to execute at once. This is highly recommended -# for preserving read performance in a mixed read/write workload as this -# avoids sstables from accumulating during long running compactions. -compaction_multithreading: false +# Number of compaction threads. This default to the number of processors, +# enabling multiple compactions to execute at once. Using more than one +# thread is highly recommended to preserve read performance in a mixed +# read/write workload as this avoids sstables from accumulating during long +# running compactions. The default is usually fine and if you experience +# problems with compaction running too slowly or too fast, you should look at +# compaction_throughput_mb_per_sec first. +# Uncomment to make compaction mono-threaded. +#concurrent_compacters: 1 # Throttles compaction to the given total throughput across the entire # system. The faster you insert data, the faster you need to compact in diff --git a/src/java/org/apache/cassandra/config/Config.java b/src/java/org/apache/cassandra/config/Config.java index 8efdd465c2..f76b6f22f0 100644 --- a/src/java/org/apache/cassandra/config/Config.java +++ b/src/java/org/apache/cassandra/config/Config.java @@ -82,7 +82,7 @@ public class Config /* if the size of columns or super-columns are more than this, indexing will kick in */ public Integer column_index_size_in_kb = 64; public Integer in_memory_compaction_limit_in_mb = 256; - public Boolean compaction_multithreading = true; + public Integer concurrent_compactors = Runtime.getRuntime().availableProcessors(); public Integer compaction_throughput_mb_per_sec = 16; public String[] data_file_directories; diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index e4f74b31ab..6c4e88d62b 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -341,8 +341,11 @@ public class DatabaseDescriptor throw new ConfigurationException("in_memory_compaction_limit_in_mb must be a positive integer"); } - if (conf.compaction_multithreading == null) - conf.compaction_multithreading = true; + if (conf.concurrent_compactors == null) + conf.concurrent_compactors = Runtime.getRuntime().availableProcessors(); + + if (conf.concurrent_compactors <= 0) + throw new ConfigurationException("concurrent_compactors should be strictly greater than 0"); if (conf.compaction_throughput_mb_per_sec == null) conf.compaction_throughput_mb_per_sec = 16; @@ -729,9 +732,9 @@ public class DatabaseDescriptor return conf.in_memory_compaction_limit_in_mb * 1024 * 1024; } - public static boolean getCompactionMultithreading() + public static int getConcurrentCompactors() { - return conf.compaction_multithreading; + return conf.concurrent_compactors; } public static int getCompactionThroughputMbPerSec() diff --git a/src/java/org/apache/cassandra/db/CompactionManager.java b/src/java/org/apache/cassandra/db/CompactionManager.java index 1ecbbcad5b..82003576d4 100644 --- a/src/java/org/apache/cassandra/db/CompactionManager.java +++ b/src/java/org/apache/cassandra/db/CompactionManager.java @@ -1212,9 +1212,7 @@ public class CompactionManager implements CompactionManagerMBean private static int getThreadCount() { - if (!DatabaseDescriptor.getCompactionMultithreading()) - return 1; - return Math.max(2, Runtime.getRuntime().availableProcessors()); + return Math.max(1, DatabaseDescriptor.getConcurrentCompactors()); } void beginCompaction(CompactionInfo.Holder ci)