first commit for new repo
[sdc/sdc-titan-cassandra.git] / config / cassandra / cassandra-env.sh
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements.  See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership.  The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License.  You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 calculate_heap_size()
18 {
19     case "`uname`" in
20         Linux)
21             system_memory_in_mb=`free -m | awk '/Mem:/ {print $2}'`
22             MAX_HEAP_SIZE=$((system_memory_in_mb / 2))M
23             return 0
24         ;;
25         FreeBSD)
26             system_memory_in_bytes=`sysctl hw.physmem | awk '{print $2}'`
27             MAX_HEAP_SIZE=$((system_memory_in_bytes / 1024 / 1024 / 2))M
28             return 0
29         ;;
30         *)
31             MAX_HEAP_SIZE=1024M
32             return 1
33         ;;
34     esac
35 }
36
37 # The amount of memory to allocate to the JVM at startup, you almost
38 # certainly want to adjust this for your environment. If left commented
39 # out, the heap size will be automatically determined by calculate_heap_size
40 # MAX_HEAP_SIZE="4G"
41
42 if [ "x$MAX_HEAP_SIZE" = "x" ]; then
43     calculate_heap_size
44 fi
45
46 # Specifies the default port over which Cassandra will be available for
47 # JMX connections.
48 JMX_PORT="9090"
49
50 # To use mx4j, an HTML interface for JMX, add mx4j-tools.jar to the lib/ directory.
51 # By default mx4j listens on 0.0.0.0:8081. Uncomment the following lines to control
52 # its listen address and port.
53 #MX4J_ADDRESS="-Dmx4jaddress=0.0.0.0"
54 #MX4J_PORT="-Dmx4jport=8081"
55
56
57 # Here we create the arguments that will get passed to the jvm when
58 # starting cassandra.
59
60 # enable assertions.  disabling this in production will give a modest
61 # performance benefit (around 5%).
62 #JVM_OPTS="$JVM_OPTS -ea"
63
64 # enable thread priorities, primarily so we can give periodic tasks
65 # a lower priority to avoid interfering with client workload
66 JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities"
67 # allows lowering thread priority without being root.  see
68 # http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html
69 JVM_OPTS="$JVM_OPTS -XX:ThreadPriorityPolicy=42"
70
71 # min and max heap sizes should be set to the same value to avoid
72 # stop-the-world GC pauses during resize, and so that we can lock the
73 # heap in memory on startup to prevent any of it from being swapped
74 # out.
75 JVM_OPTS="$JVM_OPTS -Xms$MAX_HEAP_SIZE"
76 JVM_OPTS="$JVM_OPTS -Xmx$MAX_HEAP_SIZE"
77 JVM_OPTS="$JVM_OPTS -XX:+HeapDumpOnOutOfMemoryError" 
78
79 if [ "`uname`" = "Linux" ] ; then
80     # reduce the per-thread stack size to minimize the impact of Thrift
81     # thread-per-client.  (Best practice is for client connections to
82     # be pooled anyway.) Only do so on Linux where it is known to be
83     # supported.
84     JVM_OPTS="$JVM_OPTS -Xss256k"
85 fi
86
87 # GC tuning options
88 JVM_OPTS="$JVM_OPTS -XX:+UseParNewGC" 
89 JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC" 
90 JVM_OPTS="$JVM_OPTS -XX:+CMSParallelRemarkEnabled" 
91 JVM_OPTS="$JVM_OPTS -XX:SurvivorRatio=8" 
92 JVM_OPTS="$JVM_OPTS -XX:MaxTenuringThreshold=1"
93 JVM_OPTS="$JVM_OPTS -XX:CMSInitiatingOccupancyFraction=75"
94 JVM_OPTS="$JVM_OPTS -XX:+UseCMSInitiatingOccupancyOnly"
95
96 # GC logging options -- uncomment to enable
97 # JVM_OPTS="$JVM_OPTS -XX:+PrintGCDetails"
98 # JVM_OPTS="$JVM_OPTS -XX:+PrintGCTimeStamps"
99 # JVM_OPTS="$JVM_OPTS -XX:+PrintClassHistogram"
100 # JVM_OPTS="$JVM_OPTS -XX:+PrintTenuringDistribution"
101 # JVM_OPTS="$JVM_OPTS -XX:+PrintGCApplicationStoppedTime"
102 # JVM_OPTS="$JVM_OPTS -Xloggc:/var/log/cassandra/gc.log"
103
104 # Prefer binding to IPv4 network intefaces (when net.ipv6.bindv6only=1). See 
105 # http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342561 (short version:
106 # comment out this entry to enable IPv6 support).
107 JVM_OPTS="$JVM_OPTS -Djava.net.preferIPv4Stack=true"
108
109 # jmx: metrics and administration interface
110
111 # add this if you're having trouble connecting:
112 # JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<public name>"
113
114 # see 
115 # http://blogs.sun.com/jmxetc/entry/troubleshooting_connection_problems_in_jconsole
116 # for more on configuring JMX through firewalls, etc. (Short version:
117 # get it working with no firewall first.)
118
119 # Disable JMX so multiple cassandras can run on 127.0.0.1, .2, .3, etc.
120 #JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT" 
121 #JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false" 
122 #JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false" 
123 #JVM_OPTS="$JVM_OPTS $MX4J_ADDRESS" 
124 #JVM_OPTS="$JVM_OPTS $MX4J_PORT"