Advertisement
keybounce

RC 3, 32/64-bit memory adjusting minecraft server launcher

Mar 17th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # This line is for starting from mac os icon double click
  3. cd "$( dirname "$0" )"
  4.  
  5. ## V1.4: 64 bit version, and ** LOTS OF MEMORY ALLOCATION **
  6. # This is to give information for data collection.
  7. #
  8. # Specifically: By making the memory pools large, we see how much is used.
  9. # Then, we can determine what to cut them down to.
  10. #
  11. # This will probably be the last CMS version; G1GC next.
  12.  
  13. ## V1.3: The -XX:SoftRefLRUPolicyMSPerMB=0 flag got lost! Back in now.
  14. ## This flag defaults to 1000, and can cause memory leaks.
  15.  
  16. ## V1.2: We now play with -XX:TargetSurvivorRatio=n to reduce waste in new, permitting more
  17. ## space to be used
  18.  
  19. # Configurables:
  20. # -d32 is for heap size up to 2.5gb.
  21. # Change to "-d64 XX:+UseCompressedOops" if you use more.
  22.  
  23. #JVM_SIZE="-d32 -server"
  24. JVM_SIZE="-d64 -XX:+UseCompressedOops -server"
  25.  
  26.  
  27. # ** Mention that flag specifically, do not rely on it being autoset.
  28. # ** Known and documented JVM bug -- https://forums.oracle.com/forums/thread.jspa?messageID=10017916
  29.  
  30. # CMSInitiatingOccupancyFraction: Determine how frequently to do a full CMS
  31. # sweep. Lines like:
  32. # 1308.811: [Full GC (System) ...
  33. # indicate "CMS failure". This means a full "pause the app and full GC".
  34. # Too many: Lower the percentage.
  35. # Too low a percentage: More CMS full sweeps (looks like:)
  36. # 171.808: [GC [1 CMS-initial-mark: 212329K(367040K)] ...
  37. # and usually many, many more lines after that, ending with
  38. # 173.156: [CMS-concurrent-reset: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
  39. # Note the time stamps between those.
  40.  
  41. # -XX:+UseAdaptiveGCBoundary -- apparently, adjust the boundary between new and tenured as needed.
  42. # Nice to see; did not know about it before.
  43. # Sadly, it seems to have no effect.
  44.  
  45. # -XX:+CMSIncrementalMode: Tells the garbage collector to break the job into many small parts.
  46. # May result in better performance. Essential on systems with few cores.
  47.  
  48. # Memory tuning:
  49. # Command line controls total heap, and "new". "Tenured" is the difference.
  50. # Bigger "new": Less frequent collections.
  51.  
  52. # These numbers are in "Megabytes", the java "m" suffix.
  53.  
  54. # The rule of memory tuning:
  55. # SurvivorSpace * (SurvivorRatio + 2) = New
  56. # ("SurvivorSpace" is twice the actual surviving threshold.)
  57. # SurvivorSpace * SurvivorRatio = Eden.
  58. # Two additional survivor spaces are used to copy surviving objects across minor collections.
  59.  
  60. # MAX: Maximum heap space used.
  61. # Does not include permanent (byte/compiled code)
  62. # Does not include JVM overhead
  63. MAX=2500   
  64.  
  65. # Tenured: Desired long-term storage space
  66. # Will vary based on mods, and "loaded chunks"
  67. # -- how many parties of players close to each other.
  68. #
  69. # Starting assumption: 250 for 1 person, plus 50 per group
  70. # of players near each other.
  71. #
  72. # That is a guess. Please report what numbers work for your server.
  73. Tenured=350
  74.  
  75. # Most important tuning number. Survivor.
  76. # Making this higher: Fewer full collections, but more wasted space.
  77. # During startup, expect this to overflow frequently.
  78. # Dynamic maps wants this at least 100, preferably 125.
  79. # Actual space allocated is 2 spaces, each one twice this size.
  80. # "waste/overhead" will be two about to three times this number.
  81. # *** Maximum of 1/6rd of "new"
  82. # Pay attention to the tenuring distribution logs.
  83. # *** This should be enough for generation 3 95%+ of the time. ***
  84. # ** TOO SMALL WILL KILL YOUR GARBAGE COLLECTION **
  85. # ** TOO BIG WILL WASTE SPACE **
  86. SurvivorCopySize=60
  87.  
  88. # Survivor target ratio. Java defaults to 50%, which wastes a lot of space. If you know how much
  89. # you need (see below), you can set this value higher; this gives less waste and "better performance".
  90.  
  91. TargetSurvivorRatio=90
  92.  
  93. ## Notes on "SurvivorCopySize":
  94. # Flying around in creative mode, in already generated chunks will want
  95. #   at least 30-35, preferrably 40 meg.
  96. # Standing around, single player, can be happy with less than 1.
  97. # Even in Mystcraft, with massive amounts of decay everywhere, 95% of the time 1 meg suffices.
  98. # Moving around a little, doing basic building/digging, about 3.
  99. #
  100. # The rule: You want to see "new threshold 4 (max 4)" most of the time.
  101. # The total value at age three --
  102. # - age   3:      36712 bytes,    5897520 total
  103. # should be less than this 95% of the time.
  104. # 12 meg is more than enough for one person with EBXL, Mystcraft, Twilight Forest,
  105. # and Custom Ore Gen. Even in EBXL's extreme jungle with Mystcraft's decay littering the ground.
  106. #
  107. # The single biggest factor is chunks loaded; that will depend more on parties than on players,
  108. # and the speed at which they move. Adjust to your server, and your mods.
  109. #
  110. # Single player won't need that much. Really.
  111.  
  112. # Second most important tuning. Eden.
  113. # Making this bigger means less frequent small collections.
  114. # General rule: Make this as big as your memory can handle.
  115. # Must be at least 2x SurvivorCopySize. Java requires it to be
  116. # an integer multiple of that value.
  117.  
  118. desiredEden=200
  119.  
  120. # Summary: Approximately desiredEden, plus 2 times Survivor,
  121. # plus 100, will be used by java to start the heap. Up to a max of MAX.
  122. # Script will attempt to ensure at least Tenured space exist;
  123. # should exit with a message if it cannot.
  124. #
  125. # In theory, Java will allocate extra space to new or tenured as needed.
  126. # In practice, I've never seen it increase "new".
  127. # ** Update! Just found a config flag conflict, and updated.
  128. # I suspect I've now gotten it to increase "new" as demand goes up.
  129. #
  130. # See the bottom of the config section for more.
  131.  
  132. # If your shell cannot do math, replace these with an appropriate constant
  133.  
  134. MaxNew=$(($MAX - $Tenured))
  135.  
  136. ## Survivor=$((2 * $SurvivorCopySize))
  137. ## Working with survivor target. "2" is for 50%. For 90%, it's much closer to 1.
  138. ## What we want is 100 / target percentage, as the ratio instead of 2.
  139. ## For integer only shell math, we re-write as (100 * survivor) / target, which gives us
  140. ## close integer to the desired result -- as close as we can get in the shell.
  141.  
  142. Survivor=$(( ($SurvivorCopySize * 100 ) / $TargetSurvivorRatio ))
  143.  
  144. ## Equally, the "3" in sanity test is from 3 bins -- two survivors, one eden.
  145. ## But that does NOT change here -- it's still the sanity test lower limit.
  146.  
  147. sanityTest=$((3 * $Survivor))
  148. if [ $sanityTest -gt $MaxNew ]
  149. then
  150.     echo Memory config error >& 2
  151.     exit 1
  152. fi
  153.  
  154. # We cannot use more than MaxNew.
  155.  
  156. # The idea:
  157. # 1. Find the multiple of Survivor that is bigger than S and less than MN.
  158. # 2. Determine survivor ratio from that. Subtract 2 (java.)
  159. # 3. Specify -Xmn for new, and survivor ratio, to set eden and new.
  160.  
  161. # "New" will be Eden plus 2* Survivor.
  162.  
  163. # MaxRatio -- what the ratio is if we use all of maxnew.
  164. MaxRatio=$(( ($MaxNew / $Survivor) - 2 ))
  165. # DesiredRatio -- what the ratio is based on declared eden space
  166. # There is no "-2" here -- this will allocate eden plus 2* survivor.
  167. desiredRatio=$(( ($desiredEden / $Survivor)  ))
  168.  
  169. # SurvivorSpace * (SurvivorRatio + 2) = New
  170.  
  171. # Now check for "desired Eden". If survivor is not an exact multiple of DE,
  172. # then we have just rounded down. Test for this, and if so, see if we can
  173. # raise it up (watch out for maxnew)
  174.  
  175. ## TODO! FIXME! This is a cheap approximation
  176. if ( [ $(( $desiredRatio + 1 )) -le $MaxRatio ] )
  177. then    desiredRatio=$(( $desiredRatio + 1 ))
  178. fi
  179.  
  180. desiredNew=$(($Survivor * ($desiredRatio + 2) ))
  181. biggerNew=$(($Survivor * ($MaxRatio + 2) ))
  182.  
  183. echo Debug: Max ratio $MaxRatio, desiredRatio $desiredRatio
  184. echo Debug: biggerNew $biggerNew, should be less than MaxNew $MaxNew
  185. echo Debug: desired eden $desiredEden, survivor $Survivor, actual new $desiredNew
  186.  
  187. # desiredNew: Gives an eden up to, not bigger, than desiredEden.
  188. # biggerNew: Gives an eden at least as big as desiredEden.
  189. # FIXME: DesiredNew / ratio should be smallest at least as big as desiredEden
  190. # This means, if less, then add 1 to ratio and add to new.
  191. #
  192. # "Bigger" assigns ALL non-tenured memory to new.
  193.  
  194. # Q: Desired numbers? Bigger/Max numbers?
  195.  
  196. # Choose one of these pairs
  197.  
  198. # New space is small -- specified eden.
  199. NEW=$desiredNew
  200. RATIO=$desiredRatio
  201.  
  202. # Tenured is small -- specified tenured space.
  203. ## Should Not Be Needed -- "NewSize" and "MaxNewSize" specified separately.
  204. # In theory, Java should now adjust new as neeed.
  205. #NEW=$biggerNew
  206. #RATIO=$MaxRatio
  207.  
  208. START=$(($NEW + 100))
  209.  
  210. ## TESTME: Does "MaxNewSize" matter if we have adaptive GC boundary? Does it hurt?
  211.  
  212. exec java \
  213.     $JVM_SIZE \
  214.     -Xms${START}m -Xmx${MAX}m \
  215.     -XX:NewSize=${NEW}m -XX:MaxNewSize=${MaxNew}m \
  216.     -XX:+UseAdaptiveGCBoundary \
  217.     -XX:SurvivorRatio=$RATIO \
  218.     -XX:TargetSurvivorRatio=$TargetSurvivorRatio \
  219.     -XX:CompileThreshold=3000 \
  220.         -XX:CMSInitiatingOccupancyFraction=95 \
  221. \
  222.     -XX:SoftRefLRUPolicyMSPerMB=0 \
  223.         -XX:MaxPermSize=150m \
  224.     -XX:+UseConcMarkSweepGC -XX:+UseParNewGC \
  225.     -XX:MaxHeapFreeRatio=20 \
  226.     -XX:MinHeapFreeRatio=15 \
  227.     -XX:MaxTenuringThreshold=4 \
  228.     -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution \
  229.     -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -Xloggc:GC.log \
  230.     -jar new_server.jar nogui 147test
  231.  
  232. # The last word of that exec statement -- '147test' -- is just something that shows up in
  233. # the process list, so I can tell which process is which server (each copy of this script
  234. # has a different name in that field).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement