Optimizing Software Development
RSS icon Email icon Home icon
  • JMeter Script for Linux

    Posted on November 3rd, 2005 levent.gurses No comments

    I wrote a while ago that JMeter comes with several launch scripts for starting the testing tool in different environments and conditions. One of those scripts was jmeter-n.bat, designed for background execution. It was unusual that a proxy was not supported in the original version which prompted me to write one that does.

    I was playing with JMeter last night on my Linux box when I realized that some shell scripts for Linux were not included in the default JMeter distribution (Ver 2.2). In fact the only shell script that I could find was jmeter, the default JMeter launch script which needs a Swing interface to run. Other scripts were simply missing and the one I needed was jmeter-n.bat. Clearly a jmeter-n.sh was needed. So I decided to write my own. Here is a simplified jmeter-n.sh only tested in Linux 2.6.

    #   Licensed under the Apache License, Version 2.0 (the "License");
    #   you may not use this file except in compliance with the License.
    #   You may obtain a copy of the License at
    #
    #       http://www.apache.org/licenses/LICENSE-2.0
    #
    #   Unless required by applicable law or agreed to in writing, software
    #   distributed under the License is distributed on an "AS IS" BASIS,
    #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    #   See the License for the specific language governing permissions and
    #   limitations under the License.
     
    #  ============================================
    #  Non-GUI version of JMETER.BAT (WinNT/2K only)
    #
    #  Drop a JMX file on this batch script, and it
    #  will run it in non-GUI mode, with a log file
    #  formed from the input file name but with the
    #  extension .jtl
    #
    #  Only the first parameter is used.
    #
    #  For other OSes, the script currently behaves
    #  like jmeter.bat - patches welcome!
    #
    #  ============================================
     
    JAVA_HOME=/usr/java/j2sdk1.4.2_03/
    JAVA_EXEC=$JAVA_HOME/bin/java
    JMETER_HOME=/usr/local/jakarta-jmeter-2.0.2
    JMETER_CMD_LINE_ARGS=$1
     
    HEAP='-Xms256m -Xmx256m'
    NEW='-XX:NewSize=128m -XX:MaxNewSize=128m'
    SURVIVOR='-XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=50%'
    TENURING='-XX:MaxTenuringThreshold=2'
    EVACUATION='-XX:MaxLiveObjectEvacuationRatio=20%'
    RMIGC='-Dsun.rmi.dgc.client.gcInterval=600000 -Dsun.rmi.dgc.server.gcInterval=600000'
    PERM='-XX:PermSize=64m -XX:MaxPermSize=64m'
    DEBUG='-verbose:gc -XX:+PrintTenuringDistribution'
    ARGS="$HEAP $NEW $SURVIVOR $TENURING $EVACUATION $RMIGC $PERM $DEBUG"
    $JAVA_EXEC $ARGS -jar $JMETER_HOME/bin/ApacheJMeter.jar -n -t $JMETER_CMD_LINE_ARGS
    

    You can download the shell script from here. Do not forget to edit the environment variables (JAVA_HOME, JMETER_HOME) and $ chmod +x jmeter-n.sh before running the script.