huanwei opened a new pull request #393: Polish the default JVM options for 
namesrv and broker
URL: https://github.com/apache/rocketmq/pull/393
 
 
   ## What is the purpose of the change
   
   1) The goal of this PR is to dynamically calculate proper JVM heap available 
for RocketMQ namesrv and broker, and set them in JVM options when they get 
started. It is derived from the community project apache/rocketmq-externals [PR 
#89](https://github.com/apache/rocketmq-externals/pull/89), which aims to run 
Rocketmq in Docker daemon environments. 
   
   2) Due to the default JVM heap demands of the RocketMQ namesrv and broker, 
user in community raised issue like  [Issue 
#78](https://github.com/apache/rocketmq-externals/issues/78). This PR also aims 
to solve this kind of issue from upstream.
   
   ## Brief changelog
   
   In this PR, we use gawk to calculate the max possible heap used by a JVM, 
and set JVM options for namesrv and broker. For example, in 
`${ROCKETMQ_HOME}/bin/runserver.sh`, we add the following changes:
   
   ```
   
#===========================================================================================
   # JVM Configuration
   
#===========================================================================================
   # Get the max heap used by a jvm, which used all the ram available to the 
container.
   MAX_POSSIBLE_HEAP=$(java -XX:+UnlockExperimentalVMOptions 
-XX:MaxRAMFraction=1 -XshowSettings:vm -version |& awk '/Max\. Heap Size 
\(Estimated\): [0-9KMG]+/{ print $5}' | gawk -f to_bytes.gawk)
   
   # Dynamically calculate parameters, for reference.
   Xms=$[MAX_POSSIBLE_HEAP/4]
   Xmx=$[MAX_POSSIBLE_HEAP/4]
   Xmn=$[MAX_POSSIBLE_HEAP/8]
   # Set for `JAVA_OPT`.
   JAVA_OPT="${JAVA_OPT} -server -Xms${Xms} -Xmx${Xmx} -Xmn${Xmn}"
   JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC 
-XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 
-XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 
-XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8  -XX:-UseParNewGC"
   JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:/dev/shm/rmq_srv_gc.log 
-XX:+PrintGCDetails"
   JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
   JAVA_OPT="${JAVA_OPT}  -XX:-UseLargePages"
   JAVA_OPT="${JAVA_OPT} 
-Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"
   #JAVA_OPT="${JAVA_OPT} -Xdebug 
-Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
   JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
   JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
   ```
   
   And  in `${ROCKETMQ_HOME}/bin/runbroker.sh`, we add the following changes:
   
   ```
   
#===========================================================================================
   # JVM Configuration
   
#===========================================================================================
   # Get the max heap used by a jvm, which used all the ram available to the 
container.
   MAX_POSSIBLE_HEAP=$(java -XX:+UnlockExperimentalVMOptions 
-XX:MaxRAMFraction=1 -XshowSettings:vm -version |& awk '/Max\. Heap Size 
\(Estimated\): [0-9KMG]+/{ print $5}' | gawk -f to_bytes.gawk)
   
   # Dynamically calculate parameters, for reference.
   Xms=$[MAX_POSSIBLE_HEAP/4]
   Xmx=$[MAX_POSSIBLE_HEAP/4]
   Xmn=$[MAX_POSSIBLE_HEAP/8]
   MaxDirectMemorySize=$[MAX_POSSIBLE_HEAP/4]
   # Set for `JAVA_OPT`.
   JAVA_OPT="${JAVA_OPT} -server -Xms${Xms} -Xmx${Xmx} -Xmn${Xmn}"
   JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m 
-XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 
-XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8"
   JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:/dev/shm/mq_gc_%p.log 
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime 
-XX:+PrintAdaptiveSizePolicy"
   JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 
-XX:GCLogFileSize=30m"
   JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
   JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch"
   JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=${MaxDirectMemorySize}"
   JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking"
   JAVA_OPT="${JAVA_OPT} 
-Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"
   #JAVA_OPT="${JAVA_OPT} -Xdebug 
-Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
   JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
   JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
   ```
   
   ## Verifying this change
   
   The changes have been verified in Docker environment based on CentOS 7.  So 
it should be compatible with any VM or bare-metal environments based on CentOS 
7. Details can be found in apache/rocketmq-externals [PR 
#89](https://github.com/apache/rocketmq-externals/pull/89).
   
   
   Follow this checklist to help us incorporate your contribution quickly and 
easily. Notice, `it would be helpful if you could finish the following 5 
checklist(the last one is not necessary)before request the community to review 
your PR`.
   
   - [x] Make sure there is a [Github 
issue](https://github.com/apache/rocketmq/issues) filed for the change (usually 
before you start working on it). Trivial changes like typos do not require a 
Github issue. Your pull request should address just this issue, without pulling 
in other changes - one PR resolves one issue. 
   - [x] Format the pull request title like `[ISSUE #123] Fix UnknownException 
when host config not exist`. Each commit in the pull request should have a 
meaningful subject line and body.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Write necessary unit-test(over 80% coverage) to verify your logic 
correction, more mock a little better when cross module dependency exist. If 
the new feature or significant change is committed, please remember to add 
integration-test in [test 
module](https://github.com/apache/rocketmq/tree/master/test).
   - [x] Run `mvn -B clean apache-rat:check findbugs:findbugs 
checkstyle:checkstyle` to make sure basic checks pass. Run `mvn clean install 
-DskipITs` to make sure unit-test pass. Run `mvn clean test-compile 
failsafe:integration-test`  to make sure integration-test pass.
   - [x ] If this contribution is large, please file an [Apache Individual 
Contributor License Agreement](http://www.apache.org/licenses/#clas).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to