Advertisement
keybounce

First beta release, memory adjusting minecraft server launch

Jan 4th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.44 KB | None | 0 0
  1. #!/bin/bash
  2. # This line is for starting from mac os icon double click
  3. cd "$( dirname "$0" )"
  4.  
  5. # Configurables:
  6. # -d32 is for heap size up to 2.5gb.
  7. # Change to -d64 if you use more.
  8.  
  9. # CMSInitiatingOccupancyFraction: Determine how frequently to do a full CMS
  10. # sweep. Lines like:
  11. # 1308.811: [Full GC (System) ...
  12. # indicate "CMS failure". This means a full "pause the app and full GC".
  13. # Too many: Lower the percentage.
  14. # Too low a percentage: More CMS full sweeps (looks like:)
  15. # 171.808: [GC [1 CMS-initial-mark: 212329K(367040K)] ...
  16. # and usually many, many more lines after that, ending with
  17. # 173.156: [CMS-concurrent-reset: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
  18. # Note the time stamps between those.
  19.  
  20. # -XX:+CMSIncrementalMode: Tells the garbage collector to break the job into many small parts.
  21. # May result in better performance. Essential on systems with few cores.
  22.  
  23. # Memory tuning:
  24. # Command line controls total heap, and "new". "Tenured" is the difference.
  25. # Bigger "new": Less frequent collections.
  26.  
  27. # These numbers are in "Megabytes", the java "m" suffix.
  28.  
  29. # The rule of memory tuning:
  30. # SurvivorSpace * (SurvivorRatio + 2) = New
  31. # ("SurvivorSpace" is twice the actual surviving threshold.)
  32. # SurvivorSpace * SurvivorRatio = Eden.
  33. # Two additional survivor spaces are used to copy surviving objects across minor collections.
  34.  
  35. # MAX: Maximum heap space used.
  36. # Does not include permanent (byte/compiled code)
  37. # Does not include JVM overhead
  38. MAX=800
  39.  
  40. # Tenured: Desired long-term storage space
  41. # Will vary based on mods, and "loaded chunks"
  42. # -- how many parties of players close to each other.
  43. #
  44. # Starting assumption: 250 for 1 person, plus 50 per group
  45. # of players near each other.
  46. #
  47. # That is a guess. Please report what numbers work for your server.
  48. Tenured=350
  49.  
  50. # Most important tuning number. Survivor.
  51. # Making this higher: Fewer full collections, but more wasted space.
  52. # During startup, expect this to overflow frequently.
  53. # Dynamic maps wants this at least 100, preferrably 125.
  54. # Actual space allocated is 2 spaces, each one twice this size.
  55. # "waste/overhead" will be two about to three times this number.
  56. # *** Maximum of 1/6rd of "new"
  57. # Pay attention to the tenuring distribution logs.
  58. # *** This should be enough for generation 3 95%+ of the time. ***
  59. # ** TOO SMALL WILL KILL YOUR GARBAGE COLLECTION **
  60. # ** TOO BIG WILL WASTE SPACE **
  61. SurvivorCopySize=12
  62.  
  63. ## Notes on "SurvivorCopySize":
  64. # Flying around in creative mode, in already generated chunks will want
  65. #   at least 30-35, preferrably 40 meg.
  66. # Standing around, single player, can be happy with less than 1.
  67. # Even in Mystcraft, with massive amounts of decay everywhere, 95% of the time 1 meg suffices.
  68. # Moving around a little, doing basic building/digging, about 3.
  69. #
  70. # The rule: You want to see "new threshold 4 (max 4)" most of the time.
  71. # The total value at age three --
  72. # - age   3:      36712 bytes,    5897520 total
  73. # should be less than this 95% of the time.
  74. # 12 meg is more than enough for one person with EBXL, Mystcraft, Twilight Forest,
  75. # and Custom Ore Gen. Even in EBXL's extreme jungle with Mystcraft's decay littering the ground.
  76. #
  77. # The single biggest factor is chunks loaded; that will depend more on parties than on players,
  78. # and the speed at which they move. Adjust to your server, and your mods.
  79. #
  80. # Single player won't need that much. Really.
  81.  
  82. # Second most important tuning. Eden.
  83. # Making this bigger means less frequent small collections.
  84. # General rule: Make this as big as your memory can handle.
  85. # Must be at least 2x SurvivorCopySize. Java requires it to be
  86. # an integer multiple of that value.
  87.  
  88. desiredEden=100
  89.  
  90. # Summary: Approximately desiredEden, plus 4 times SurvivorCopySpace,
  91. # plus 100, will be used by java to start the heap. Up to a max of MAX.
  92. # Script will attempt to ensure at least Tenured space exist;
  93. # should exit with a message if it cannot.
  94. #
  95. # In theory, Java will allocate extra space to new or tenured as needed.
  96. # In practice, I've never seen it increase "new".
  97. # ** Update! Just found a config flag conflict, and updated.
  98. # I suspect I've now gotten it to increase "new" as demand goes up.
  99. #
  100. # See the bottom of the config section for more.
  101.  
  102. # If your shell cannot do math, replace these with an appropriate constant
  103.  
  104. MaxNew=$(($MAX - $Tenured))
  105.  
  106. Survivor=$((2 * $SurvivorCopySize))
  107.  
  108. sanityTest=$((3 * $Survivor))
  109. if [ $sanityTest -gt $MaxNew ]
  110. then
  111.     echo Memory config error >& 2
  112.     exit 1
  113. fi
  114.  
  115. # We cannot use more than MaxNew.
  116.  
  117. # The idea:
  118. # 1. Find the multiple of Survivor that is bigger than S and less than MN.
  119. # 2. Determine survivor ratio from that. Subtract 2 (java.)
  120. # 3. Specify -Xmn for new, and survivor ratio, to set eden and new.
  121.  
  122. # "New" will be Eden plus 2* Survivor.
  123.  
  124. MaxRatio=$(($MaxNew / $Survivor - 2 ))
  125. desiredRatio=$(($desiredEden / $Survivor))
  126.  
  127. # SurvivorSpace * (SurvivorRatio + 2) = New
  128.  
  129. desiredNew=$(($Survivor * ($desiredRatio + 2) ))
  130. biggerNew=$(($Survivor * ($MaxRatio + 2) ))
  131.  
  132. echo Debug: Max ratio $MaxRatio, desiredRatio $desiredRatio, Max new $MaxNew
  133. echo Debug: desired eden $desiredEden, survivor $Survivor
  134. echo Debug: desiredNew: $desiredNew, bigger new: $biggerNew. Compare to eden/max.
  135.  
  136. # desiredNew: Gives an eden up to, not bigger, than desiredEden.
  137. # biggerNew: Gives an eden at least as big as desiredEden.
  138. # FIXME: DesiredNew / ratio should be smallest at least as big as desiredEden
  139. # This means, if less, then add 1 to ratio and add to new.
  140. #
  141. # "Bigger" assigns ALL non-tenured memory to new.
  142.  
  143. # Q: Desired numbers? Bigger/Max numbers?
  144.  
  145. # Choose one of these pairs
  146.  
  147. # New space is small -- specified eden.
  148. NEW=$desiredNew
  149. RATIO=$desiredRatio
  150.  
  151. # Tenured is small -- specified tenured space.
  152. ## Should Not Be Needed -- "NewSize" and "MaxNewSize" specified separately.
  153. # In theory, Java should now adjust new as neeed.
  154. #NEW=$biggerNew
  155. #RATIO=$MaxRatio
  156.  
  157. START=$(($NEW + 100))
  158.  
  159.  
  160. exec java \
  161.     -d32 -server \
  162.     -Xms${START}m -Xmx${MAX}m \
  163.     -XX:NewSize=${NEW}m -XX:MaxNewSize=${MaxNew}m \
  164.     -XX:SurvivorRatio=$RATIO \
  165.     -XX:CompileThreshold=3000 \
  166.         -XX:CMSInitiatingOccupancyFraction=95 \
  167. \
  168.         -XX:MaxPermSize=150m \
  169.     -XX:+UseConcMarkSweepGC -XX:+UseParNewGC \
  170.     -XX:MaxHeapFreeRatio=20 \
  171.     -XX:MinHeapFreeRatio=12 \
  172.     -XX:MaxTenuringThreshold=4 \
  173.     -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution \
  174.     -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -Xloggc:GC.log \
  175.     -jar new_server.jar nogui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement