Author: brandonwilliams Date: Tue Sep 14 22:35:41 2010 New Revision: 997126
URL: http://svn.apache.org/viewvc?rev=997126&view=rev Log: Adaptively set the heap size and memtable thresholds at runtime. Patch by brandonwilliams, reviewed by jbellis for CASSANDRA-1469 Modified: cassandra/trunk/conf/cassandra-env.sh cassandra/trunk/conf/cassandra.yaml cassandra/trunk/src/java/org/apache/cassandra/config/Config.java Modified: cassandra/trunk/conf/cassandra-env.sh URL: http://svn.apache.org/viewvc/cassandra/trunk/conf/cassandra-env.sh?rev=997126&r1=997125&r2=997126&view=diff ============================================================================== --- cassandra/trunk/conf/cassandra-env.sh (original) +++ cassandra/trunk/conf/cassandra-env.sh Tue Sep 14 22:35:41 2010 @@ -14,10 +14,21 @@ # See the License for the specific language governing permissions and # limitations under the License. +calculate_heap_size() +{ + system_memory=`free -m | awk '/Mem:/ {print $2}'` + MAX_HEAP_SIZE=$((system_memory / 2))M +} # The amount of memory to allocate to the JVM at startup, you almost -# certainly want to adjust this for your environment. -MAX_HEAP_SIZE="1G" +# certainly want to adjust this for your environment. If left commented +# out, the heap size will be automatically determined by calculate_heap_size +# MAX_HEAP_SIZE="4G" + +if [ "x$MAX_HEAP_SIZE" = "x" ]; then + calculate_heap_size + echo "Using adaptive heap size: " $MAX_HEAP_SIZE +fi # Specifies the default port over which Cassandra will be available for # JMX connections. Modified: cassandra/trunk/conf/cassandra.yaml URL: http://svn.apache.org/viewvc/cassandra/trunk/conf/cassandra.yaml?rev=997126&r1=997125&r2=997126&view=diff ============================================================================== --- cassandra/trunk/conf/cassandra.yaml (original) +++ cassandra/trunk/conf/cassandra.yaml Tue Sep 14 22:35:41 2010 @@ -143,11 +143,14 @@ binary_memtable_throughput_in_mb: 256 # This needs to be large enough that it won't cause a flush storm # of all your memtables flushing at once because none has hit # the size or count thresholds yet. -memtable_flush_after_mins: 60 +# defaults to 60 +#memtable_flush_after_mins: 60 # Size of the memtable in memory before it is flushed -memtable_throughput_in_mb: 64 +# if left undefined, 1/8 of the heap will be used +#memtable_throughput_in_mb: 256 # Number of objects in millions in the memtable before it is flushed -memtable_operations_in_millions: 0.3 +# if left undefined, the memtable_throughput_in_mb / 64 * 0.3 will be used +#memtable_operations_in_millions: 1.2 # Add column indexes to a row after its contents reach this size. # Increase if your column values are large, or if you have a very large Modified: cassandra/trunk/src/java/org/apache/cassandra/config/Config.java URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/Config.java?rev=997126&r1=997125&r2=997126&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/config/Config.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/config/Config.java Tue Sep 14 22:35:41 2010 @@ -73,9 +73,9 @@ public class Config /* Number of minutes to keep a memtable in memory */ public Integer memtable_flush_after_mins = 60 * 60 * 1000; /* Size of the memtable in memory before it is dumped */ - public Integer memtable_throughput_in_mb = 64; + public Integer memtable_throughput_in_mb = (int) Runtime.getRuntime().maxMemory() / 8; /* Number of objects in millions in the memtable before it is dumped */ - public Double memtable_operations_in_millions = 0.1; + public Double memtable_operations_in_millions = memtable_throughput_in_mb / 64 * 0.3; /* if the size of columns or super-columns are more than this, indexing will kick in */ public Integer column_index_size_in_kb = 64;
