Advertisement
keybounce

Release candidate 2, memory adjusting minecraft launcher

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