如何将 Cassandra (>2.0) JVM 堆大小设置为 8GB?

How to set Cassandra (>2.0) JVM heap size of 8GB?

如何设置Cassandra (>2.0) JVM堆大小为8GB?当我输入 free -m 时,它会给我以下信息。如何将 Cassandra JVM 堆大小设置为 8GB?

             total       used       free     shared    buffers     cached
Mem:         16047      11336       4711          0         81       5814
-/+ buffers/cache:       5441      10606
Swap:            0          0          0

如文档的 Tuning Java resources 部分所述:

If you decide to change the Java heap sizing, both MAX_HEAP_SIZE and HEAP_NEWSIZE should should be set together in conf/cassandra-env.sh.

在 cassandra-env.sh 中,搜索此行:

#MAX_HEAP_SIZE="4G"

代码中的那一行发生在 MAX_HEAP_SIZE 计算发生之后,因此它可以作为覆盖。取消注释,并相应地设置它。

MAX_HEAP_SIZE="8G"

小心超过 8G。关于调整 JVM 的指导,我推荐 Amy Tobey's Cassandra 2.1 Tuning Guide。她提供了一些调整 CMS 的技巧,以及关于实施新 G1GC 的重要部分。

更新cassandra-env.sh

删除/注释掉整个 calculate_heap_sizes() 函数

  • 这是cassandra调用的自动分配JVM大小的函数。
  • 它需要 1/4 系统内存或 8GB 中较低的一个。这就是默认最大 JVM 大小为 8GB 的​​原因

Remove/comment 用 $MAX_HEAP_SIZE 换行。

  • 行开头为:"only calcuate the size if..."

  • 删除/保留HEAP_NEWSIZE注释掉

MAX_HEAP_SIZE 设置为新值。例如:16G

  • 这应该是您唯一需要执行此操作的地方

重启

  • 理想情况下,您只需要重新启动 Cassandra 服务。但是,我只是在重新启动整个机器后才让它工作。

另请参阅另一个示例:https://medium.com/@mlowicki/move-cassandra-2-1-to-g1-garbage-collector-b9fb27365509