Server launch.sh

Discussion in 'Performance Tweaking' started by Kainzo, Nov 26, 2012.

Thread Status:
Not open for further replies.
  1. For Linux/Debian:
    Just wanted to see what some of you guys had here, after many months of testing, this is Herocraft's best.

    Herocraft:
    Avg player: 100+
    Avg TPS: 15-20

    Code (Text):

    #!/bin/sh
    java \
            -Xms4G \
            -Xmx24G \
     
    Old below.
    Code (Text):

    #!/bin/sh
    java \
            -Xms4G \
            -Xmx24G \
            -server \
            -XX:SurvivorRatio=15 \
            -XX:TargetSurvivorRatio=90 \
            -XX:MaxGCPauseMillis=500 \
            -XX:+UseAdaptiveGCBoundary \
            -XX:PermSize=128m \
            -XX:MaxPermSize=256m \
            -jar spigot.jar
     
    #1 Kainzo, Nov 26, 2012
    Last edited: Jun 28, 2015
    • Like Like x 2
    • Informative Informative x 2
  2. Puremin0rez

    Moderator

    Rolling with this for the past year or so -
    Code (Text):

    java -server -Xmx4096M -Xms1024M -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+UseNUMA -XX:+CMSParallelRemarkEnabled -XX:MaxGCPauseMillis=50 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -XX:+UseBiasedLocking -XX:UseSSE=3 -XX:+UseStringCache -XX:+UseCompressedOops -XX:+OptimizeStringConcat -XX:+UseFastAccessorMethods -XX:+AggressiveOpts -jar craftbukkit.jar --log-limit=100000
     
     
    • Useful Useful x 3
  3. This is what i have been using for about a month but i dont think its correct
    Code (Text):
    @echo off
     
    echo ==================================
    echo ========  LTD Craft ========
    echo ==================================
    echo =    Limited Gaming Inc        =
    echo ==================================
    echo =      Server Starting!      =
    echo ==================================
     
    @ECHO off
     
    color 02
     
    IF /I "%PROCESSOR_ARCHITECTURE:~-2%"=="64" "%Program Files (x86)%\Java\jre7\bin\java.exe" -Xms1g -Xmx4g -jar "%~dp0craftbukkit.jar"
    IF /I "%PROCESSOR_ARCHITECTURE:~-2%"=="86"  java -Xms1g -Xmx4g -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -XX:PermSize=128m -XX:MaxPermSize=256m -jar "%~dp0craftbukkit.jar"
     
     
     
    • Agree Agree x 1
  4. andrewkm

    Patron ⭐⭐⭐

    "-jar" :)

    Seriously ... I started not specifying a single flag in my start up and noticed things just run better - much better. I find all those flags people use to be quite silly.
     
    • Agree Agree x 2
    • Like Like x 1
  5. Puremin0rez

    Moderator

    I ran with no flags either for abit, but garbage collection (i think?) was causing my server to pause soooo often but after playing with flags I was able to stop that.
     
  6. andrewkm

    Patron ⭐⭐⭐

    Java version? I noticed this as well a LONG time ago back on Java 6; it has long stopped on Java 7 - Im now on Java 7 update 9 running with no flags and absolutely no issues whatsoever.
     
  7. Puremin0rez

    Moderator

    Java 6 - time to update and try :)
     
  8. andrewkm

    Patron ⭐⭐⭐

    Indeed; throw on Java 7 update 9 and run with no flags - you will be very happy :)
     
  9. i never ran my server with anything less than java 7 but ive heard that the performance jump is pretty big.
     
  10. Code (Text):
    java -d64 -server -Xincgc -Xms5G -XX:+AggressiveOpts -jar spigot.jar nogui
    will try with no flags :)
     
  11. This works properly for me =D
    Code (Text):

    #!/bin/bash
    SERVICE="spigot-*.jar"
    MEMLOG="memory.log"
    SCREEN="Minecraft"
    CPU_COUNT=7
    INITMEM="4096M"
    MAXMEM="16384M"
    INVOCATION="java -Xms$INITMEM -Xmx$MAXMEM -XX:ParallelGCThreads=$CPU_COUNT -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -Xloggc:$MEMLOG -jar $SERVICE nogui"
     
    screen -dmS $SCREEN $INVOCATION
     
     
  12. Here is ours:
    Code (Text):
    #!/bin/bash
    SOCKET_NAME=bukkit
    IDENTIFICATION_CODE=
     
    SERVER_PATH=$(dirname $0)
    SERVER_FILE=spigot-268.jar
    SERVER_STATE_FILE=server.state
     
    # --------------------------------------------------------------------------------------------
    # Old Java parameters
    # --------------------------------------------------------------------------------------------
    #
    #JAVA_PARAMETERS="-Xms1G -Xmx1G"
    #
    #JAVA_PARAMETERS="-server -Xms6G -Xmx6G -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=5"
    #
    #JAVA_PARAMETERS="-server -Xms6G -Xmx6G -Dfile.encoding=UTF-8"
    # -Xrunhprof:cpu=samples,depth=6,thread=y
    #JAVA_PARAMETERS="-server -Xms6G -Xmx6G -XX:ParallelGCThreads=3 -Xincgc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts
    #-XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc
    #-XX:UseSSE=3 -XX:PermSize=128m -XX:LargePageSizeInBytes=4m -Dfile.encoding=UTF-8"
    #
    #JAVA_PARAMETERS="-server -d64 -Xms12G -Xmx12G -Xincgc \
    # -XX:ParallelGCThreads=3 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC \
    # -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+CMSParallelRemarkEnabled \
    # -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 \
    # -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc \
    # -Dfile.encoding=UTF-8"
    #
    #JAVA_PARAMETERS="-server -d64 -Xincgc -Xmx10G -XX:ParallelGCThreads=4 \
    # -Dfile.encoding=UTF-8"
    #
    # --------------------------------------------------------------------------------------------
    # Old Java parameters
    # --------------------------------------------------------------------------------------------
     
    JAVA_PARAMETERS="-server -d64 -Xms14G -Xmx14G \
    -XX:ParallelGCThreads=4 -XX:+UseParNewGC \
    -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+CMSParallelRemarkEnabled \
    -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=400 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 \
    -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc \
    -Dfile.encoding=UTF-8"
     
    JAVA_BIN=/usr/java/jre1.7.0_09/bin/java
    TMUX_BIN="tmux -u"
     
    setState()
    {
            echo $1 > $SERVER_STATE_FILE
    }
     
    fetchState()
    {
            SERVER_STATE=`cat $SERVER_STATE_FILE`
    }
     
    execute()
    {
            $TMUX_BIN send -t $SOCKET_NAME "$*" "enter"
            echo "Command executed: '$*'"
    }
     
    start_server()
    {
            OPTIONS="-d"
            if [[ $1 =~ ^att.* ]]
            then
                    OPTIONS=""
            fi
            $TMUX_BIN new $OPTIONS -s $SOCKET_NAME "$JAVA_BIN $JAVA_PARAMETERS -jar $SERVER_FILE nogui $IDENTIFICATION_CODE"
    }
     
    is_server_up()
    {
            TMP=`$TMUX_BIN list-sessions 2>/dev/null| grep $SOCKET_NAME 2>/dev/null`
            if [ "$TMP" = "" ]
            then
                    return 0
            else
                    return 1
            fi
    }
     
    countdown()
    {
            if [ "$1" = "" ]
            then
                    COUNTDOWN_TYPE="restart"
            else
                    COUNTDOWN_TYPE=$1
            fi
     
            if [ "$2" != "fast" ]
            then
                    execute "broadcast Varoitus! Palvelin $COUNTDOWN_TYPE 1 minuutin kuluttua!"
                    sleep 30
                    execute "broadcast Varoitus! Palvelin $COUNTDOWN_TYPE 30 sekunnin kuluttua!"
                    sleep 20
            fi
     
            for SECONDS in 10 9 8 7 6 5 4 3 2 1
            do
                    execute "broadcast Varoitus! Palvelin $COUNTDOWN_TYPE $SECONDS sekunnin kuluttua!"
                    sleep 1
            done
    }
     
    wait_server_stop()
    {
            I=0
            while [ "$I" -lt "20" ]
            do
                    is_server_up
                    if [ "$?" = "0" ]
                    then
                            I=100
                    else
                            sleep 5
                            let I=$I+1
                    fi
            done
    }
     
    cd $SERVER_PATH
     
    case "$1" in
     
            start)
                    is_server_up
                    if [ "$?" = "1" ]
                    then
                            echo "Server is already running. Aborting!"
                            exit 0
                    fi
                    start_server "$2"
                    sleep 1
                    is_server_up
                    if [ "$?" = "1" ]
                    then
                            echo "Server started."
                            setState "STARTED"
                    else
                            echo "ERROR! Coulnd't start the server!"
                            setState "ERROR"
                    fi
            ;;
     
            stop)
                    execute "stop"
                    echo "Server stopped."
            ;;
     
            shutdown)
                    countdown "SHUTDOWN" $2
                    execute "kickall Server shutdown!"
                    sleep 1
                    execute "stop"
                    setState "SHUTDOWN"
            ;;
     
            restart)
                    setState "RESTARTING"
                    is_server_up
                    if [ "$?" = "1" ]
                    then
                            countdown "restarttaa" $2
                            execute "save-all"
                            sleep 2
                            execute "broadcast Restart aloitettu..."
                            $0 stop
                            wait_server_stop
                            sleep 1
                    else
                            echo "Server is down, restarting the server..."
                    fi
     
                    sleep 1
     
                    $0 kill
     
                    sleep 1
     
                    mv server.log ../logs/$(date +%Y-%m-%d-%H-%M-%S).server.log
                    $0 start        ;;
     
            kill)
                    SERVER_PIDS=`ps x -o pid,args|grep java|grep $IDENTIFICATION_CODE|awk '{print $1}'`
                    for SERVER_PID in $SERVER_PIDS
                    do
                            kill -9 $SERVER_PID
                            echo "Process with $SERVER_PID PID killed."
                    done
            ;;
     
            save)
                    execute "save-all"
            ;;
     
            message)
                    if [ "$2" = "" ]
                    then
                            echo "usage: $0 message <message>"
                    else
                            MESSAGE=([email protected])
                            MESSAGE="${MESSAGE[@]:1}"
                            execute "say $MESSAGE"
                            echo "Message '$MESSAGE' sent."
                    fi
            ;;
     
            exec)
                    if [ "$2" = "" ]
                    then
                            echo "usage: $0  exec <command>"
                    else
                            MESSAGE=([email protected])
                            MESSAGE="${MESSAGE[@]:1}"
                            execute "$MESSAGE"
                            echo "Command '$MESSAGE' executed."
                    fi
            ;;
     
            reloadpermissions)
                    execute "permissions -reload all"
            ;;
     
            status)
                    is_server_up
                    if [ "$?" = "1" ]
                    then
                            echo "Server is up!"
                    else
                            echo "Server is down!"
                    fi
                    fetchState
                    echo "Server state: $SERVER_STATE"
            ;;
     
            watchdog)
                    fetchState
                    is_server_up
                    if [ "$?" = "0" ] && [ "$SERVER_STATE" != "RESTARTING" ] && [ "$SERVER_STATE" != "SHUTDOWN" ]
                    then
                            $0 restart
                    fi
            ;;
     
     
            att*)
                    $TMUX_BIN attach -t $SOCKET_NAME
            ;;
     
            *)
                    echo ""
                    echo "Minecraft Server Tool"
                    echo ""
                    echo "  Usage:"
                    echo "    $0 start [attach]"
                    echo "      - starts the server."
                    echo ""
                    echo "    $0 restart [fast]"
                    echo "      - sends the countdown messages and restarts the server."
                    echo ""
                    echo "    $0 shutdown [fast]"
                    echo "      - broadcasts the countdown and stops the server."
                    echo ""
                    echo "    $0 stop"
                    echo "      - stops the server without the countdown."
                    echo ""
                    echo "    $0 kill"
                    echo "      - WARNING!! kills the server process."
                    echo ""
                    echo "    $0 save"
                    echo "      - saves the game worlds."
                    echo ""
                    echo "    $0 message <message>"
                    echo "      - sends message to the players."
                    echo ""
                    echo "    $0 status"
                    echo "      - show the server status."
                    echo ""
                    echo "    $0 watchdog"
                    echo "      - checks if the server is up and tries to start the server if"
                    echo "        the server is not up."
                    echo ""
                    echo "    $0 attach"
                    echo "      - attaches the tmux session."
                    echo ""
                    exit 1
            ;;
     
    esac
     
    exit 0
     
    #12 tssge, Nov 26, 2012
    Last edited: Feb 19, 2013
    • Useful Useful x 2
    • Agree Agree x 1
    • Funny Funny x 1
  13. Heres Mine...... "C:\Program Files\Java\jre8\bin\java.exe" -Xmx5G -XX:+UseNUMA -jar Bukkit.jar
    pause

    andddd THATS IT! WOO
     
  14. Mine:
    Code (Text):
    @Echo OFF
    Title Bukkit Launcher
    java -Xmx2G -XX:ParallelGCThreads=6 -Xincgc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc -XX:UseSSE=3 -XX:PermSize=128m -XX:LargePageSizeInBytes=4m -server -jar craftbukki*.jar --log-limit 50000
    exit
     
  15. Puremin0rez

    Moderator

    Okay I'm on JRE7 with one flag "-server" now. Let's see how things roll :)

    Edit: Well of course, still using the memory allocation flags.
     
  16. hey just letting you know that SSE 3 isnt even the latest SSE anymore so you may be forcing it to use an older version. not sure what it really does though. just thought i would let you know because i did it.
     
  17. Here's what Luxcraft uses:

    Just a note regarding GC's that i've tested.

    G1 > Uses more cpu in favor for "better" GC
    XincGC > Uses a fair amount of cpu at the cost of GC (same as -XX:+UseParNewGC -XX:+UseConcMarkSweepGC)

    .. also using -XX:+DisableExplicitGC helps when running plugins that calls System.gc() .. i've read that Essentials is using this, cant verify it tho .. anyone who can?

    Lately i've started to allocate all RAM at startup.

    I started running Spigot on my dev server yesterday, the script is from my prod server thus the bukkit tags all over the Place :p

    Host: Hetzner
    OS: Ubuntu 12.04 LTS 64-bit
    Java: Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
    CPU: Intel Core i7-3770 (8 "cores")
    RAM: 16GB
    HDD: 2x 3TB (software raid-1)
    Player slots: 75
    Code (Text):
    #!/bin/bash
    bukkitdir=/bukkit/
    bukkitfilename=craftbukkit-beta.jar
    #javaparams="-server -Xincgc -Xmx10240M -XX:NewRatio=2 -XX:ParallelGCThreads=4 -XX:+DisableExplicitGC -XX:+AggressiveOpts"
    #javaparams="-server -XX:+UseG1GC -Xmx4096M -Xms2048M -XX:MaxGCPauseMillis=100 -XX:UseSSE=4 -XX:ParallelGCThreads=4"
    #javaparams="-server -XX:+UseG1GC -Xmx10240M -Xms2048M -XX:MaxGCPauseMillis=100 -XX:UseSSE=4 -XX:ParallelGCThreads=4 -XX:+DisableExplicitGC -XX:+AggressiveOpts"
    #javaparams="-server -XX:+UseG1GC -Xmx10240M -Xms2048M -XX:+DisableExplicitGC"
    javaparams="-server -XX:+UseG1GC -Xmx10240M -Xms10240M -XX:MaxGCPauseMillis=50 -XX:ParallelGCThreads=4 -XX:+DisableExplicitGC -XX:+AggressiveOpts"
    javagclog="-XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:gc.log"
    javaloc=/usr/bin/java
     
    startbukkit()
    {
        if [ "$(screen -ls | grep bukkit)" == "" ] ; then
            cd $bukkitdir
            screen -S bukkit -dmS $javaloc $javaparams $javagclog -jar $bukkitdir$bukkitfilename nogui --log-limit=2000000 --log-count=5
            echo "Starting bukkit server."
        else
            echo "Bukkit is already running."
            exit 0
        fi
    }
     
    stopbukkit()
    {
        if [ "$(screen -ls | grep bukkit)" == "" ] ; then
            echo "Bukkit is not running."
            exit 0
        else
            screen -S bukkit -p 0 -X stuff "stop$(echo -ne '\r')"
            sleep 5
        fi
    }
     
    case $1 in
        start)
            startbukkit
            ;;
        stop)
            stopbukkit
            ;;
        friendlystop)
            screen -S bukkit -p 0 -X stuff "say Going down in 5 minutes.$(echo -ne '\r')"
            sleep 240
            screen -S bukkit -p 0 -X stuff "say Going down in 60 seconds.$(echo -ne '\r')"
            sleep 55
            screen -S bukkit -p 0 -X stuff "say Going down in 5 seconds.$(echo -ne '\r')"
            sleep 5
            stopbukkit
            ;;
        *)
            echo "Usage: $0 {start|stop|friendlystop}"
    esac
     
    exit 0
     
     
    #17 sirmyllox, Nov 29, 2012
    Last edited: Nov 30, 2012
  18. Puremin0rez

    Moderator

    Okay so I'm now running ONLY with memory allocation flags and -server flag and -UseG1GC flag.

    Is G1GC the default in Java 7 update 9 now? I might not need the flag then.
     
  19. I think it is. I googled a bit and it sounds like it has been since update 4. I also remember reading about it somewhere. Not sure though. I guess it cant hurt having the flag just incase but I dont know much about java stuff.
     
  20. We have a server with a CPU containing four cores, and 8 threads at 3.8GHz, 32 gigabytes of ram at 1600MHz, a 100Mb/s internet connection, a ramdisk, a whole galaxy of multi-colored spigots, CB++, NoLaggs... Also, a stable online 100+ players and annoying complaints about lag ... Not that we needed all that for the massive server optimization, but once you get locked into a serious optimization, the tendency is to push it as far as you can. The only thing that really worried me was the java runtime flags . There is nothing in the world more helpless and irresponsible and depraved than a man in the depths of java flags, and I knew we'd get into that rotten stuff pretty soon.
    - Remaked quote from "Fear and Loathing in Las Vegas"
     
    #20 Username, Dec 3, 2012
    Last edited: Dec 3, 2012
Thread Status:
Not open for further replies.