zookeeper icon indicating copy to clipboard operation
zookeeper copied to clipboard

ZOOKEEPER-4797: Allow for -XX:MaxRAMPercentage JVM setting

Open frederiko opened this issue 1 year ago • 5 comments

When running Zk in a containerized environment, it's sometimes desirable to express your heap size in terms of percentage of available memory allocated to a container.

As it stands, zkEnv.sh forces your to have -Xmx set to a value, otherwise it defaults to 1GB. Some environments wanted to set it to more, mostly related to the amount of Ram, not to an absolute value.

This is a request to implement the option of using -XX:MaxRamPercentage option when starting zookeeper.

Suggested implementation is to also make a variable ZK_SERVER_MAXRAMPERCENTAGE available to be appended to SERVER_JVMFLAGS. If the variable is set, ZK_HEAP_SERVER is ignored, if no ZK_SERVER_MAXRAMPERCENTAGE, ZK_SERVER_HEAP is set as usual.

Example output:

Without any heap size set.

./bin/zkServer.sh print-cmd
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/fsc/src/zookeeper/bin/../conf/zoo.cfg
"java"  ....  **-Xmx1000m**   -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain "/home/fsc/src/zookeeper/bin/../conf/zoo.cfg" > "/home/fsc/src/zookeeper/bin/../logs/zookeeper-fsc-server-lap.out" 2>&1 < /dev/null

With ZK_SERVER_HEAP set to 2000

$ ZK_SERVER_HEAP=2000 ./bin/zkServer.sh print-cmd
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/fsc/src/zookeeper/bin/../conf/zoo.cfg
"java"  ...  **-Xmx2000m**   -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain "/home/fsc/src/zookeeper/bin/../conf/zoo.cfg" > "/home/fsc/src/zookeeper/bin/../logs/zookeeper-fsc-server-lap.out" 2>&1 < /dev/null

When ZK_SERVER_MAXRAMPERCENTAGE is added (with or without ZK_SERVER_HEAP)

$ ZK_SERVER_MAXRAMPERCENTAGE=30.0 ZK_SERVER_HEAP=2000 ./bin/zkServer.sh print-cmd (ZK_SERVER_HEAP is ignored)
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/fsc/src/zookeeper/bin/../conf/zoo.cfg
"java" ... **-XX:MaxRAMPercentage=30.0**   -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain "/home/fsc/src/zookeeper/bin/../conf/zoo.cfg" > "/home/fsc/src/zookeeper/bin/../logs/zookeeper-fsc-server-lap.out" 2>&1 < /dev/null

frederiko avatar Jan 30 '24 05:01 frederiko

ISSUE: when using export $SERVER_JVFMLAGS="******$SERVER_JVMFLAGS" in zkEnv.sh, it will cause zkEnv.sh load variable $SERVER_JVMFLAGS twice when restart zkEnv.sh.

This issue will complain error when adding variables containing -javaagent

dreamcatcherer avatar Mar 08 '24 10:03 dreamcatcherer

@tisonkun @anmolnar @ztzg PTAL

eolivelli avatar Mar 08 '24 12:03 eolivelli

export $SERVER_JVFMLAGS

@dreamcatcherer did I miss something or the export $SERVER_JVFMLAGS="******$SERVER_JVMFLAGS" should actually be something along the lines of export SERVER_JVFMLAGS="******$SERVER_JVMFLAGS"?

frederiko avatar Mar 08 '24 23:03 frederiko

Hello, is there some ETA for this to be merged?

frederiko avatar Aug 20 '24 16:08 frederiko

Hello, is there some ETA for this to be merged?

Sorry, I'm not a committer, so I don't have permission to merge this. If you don't get a response here, you can try pinging the ZooKeeper developer mailing list.

ctubbsii avatar Aug 21 '24 17:08 ctubbsii