3.cassandra遇到内存占用太高的问题

 

目前cssandra的内存分配以下:css

https://docs.datastax.com/en/cassandra/2.1/cassandra/operations/ops_tune_jvm_c.html#opsTuneJVM__tuning-the-java-heaphtml

# some systems like the raspberry pi don't report cores, use at least 1java

if [ "$system_cpu_cores" -lt "1" ]数据库

thenjvm

system_cpu_cores="1"分布式

fihtm

# set max heap size based on the followingblog

# max(min(1/2 ram, 1024MB), min(1/4 ram, 8GB))内存

# calculate 1/2 ram and cap to 1024MBget

# calculate 1/4 ram and cap to 8192MB

# pick the max

half_system_memory_in_mb=`expr $system_memory_in_mb / 2`

quarter_system_memory_in_mb=`expr $half_system_memory_in_mb / 2`

if [ "$half_system_memory_in_mb" -gt "1024" ]

then

half_system_memory_in_mb="1024"

fi

if [ "$quarter_system_memory_in_mb" -gt "8192" ]

then

quarter_system_memory_in_mb="8192"

fi

if [ "$half_system_memory_in_mb" -gt "$quarter_system_memory_in_mb" ]

then

max_heap_size_in_mb="$half_system_memory_in_mb"

else

max_heap_size_in_mb="$quarter_system_memory_in_mb"

fi

#MAX_HEAP_SIZE="${max_heap_size_in_mb}M"

# Young gen: min(max_sensible_per_modern_cpu_core * num_cores, 1/4 * heap size)

max_sensible_yg_per_core_in_mb="100"

max_sensible_yg_in_mb=`expr $max_sensible_yg_per_core_in_mb "*" $system_cpu_cores`

 

desired_yg_in_mb=`expr $max_heap_size_in_mb / 4`

 

if [ "$desired_yg_in_mb" -gt "$max_sensible_yg_in_mb" ]

then

HEAP_NEWSIZE="${max_sensible_yg_in_mb}M"

else

HEAP_NEWSIZE="${desired_yg_in_mb}M"

fi

 

经过阅读代码能够知道,

MAX_HEAP_SIZE:

A = 若是1/2的内存都比1024M要小,则取1/2的内存,不然取1024

B = 若是1/4的内存比8g要小,则取1/4的内存,不然取8G

再取MAX(A,B)

能够看出当最小时取1/2的内存(1/2的内存比1024M小),最大的内存取8G

 

HEAP_NEWSIZE = 核数*100M

若是MAX_HEAP_SIZE/4<核数*100M,则取MAX_HEAP_SIZE/4

 

改成MAX_HEAP_SIZE = 512M就能够正常运行了,这样就不会出现内存不够的状况,可是官方标配是:

 

!!!!!!!内存不够就不要用分布式数据库

相关文章
相关标签/搜索