Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

frederiko
Copy link
Contributor

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

bin/zkEnv.sh Outdated Show resolved Hide resolved
* Deprecates, for future versions, ZK_{SERVER,CLIENT}_HEAP in favor of ZK_{SERVER,CLIENT}_JVMARGS
* If no custom heap size is provided, still defaults to previous max heap size
@dreamcatcherer
Copy link

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

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@eolivelli
Copy link
Contributor

@tisonkun @anmolnar @ztzg PTAL

@frederiko
Copy link
Contributor Author

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"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants