yes, this is not a perfect solution, but it can alleviate this painful thing.<div>  e.g. our application receives 10 request per second, it means every 100 ms a request. and the stop the world is 500ms</div><div>if we don't monitor the status of jvm, when jvm stop the world, 5 requests are not processed. but if we send request before consulting the jvm, then only one request are blocked.</div>
<div>  of course there are extreme situation that the 5 requests comes at the same time and jvm tells them I am not stop the world, but when requests come, it stops the world.</div><div>  but comparing with these two solutions. asking then sending is a better one.<br>
<br><div class="gmail_quote">On Mon, Dec 12, 2011 at 9:57 PM, Vitaly Davidovich <span dir="ltr"><<a href="mailto:vitalyd@gmail.com">vitalyd@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p>But suppose you had this feature and the VM tells you that it's not doing (or doesn't have any pending) full gc.  Your load balancer then sends the request to that server - what happens if the processing of this request triggers a full gc? I just don't think there's a comprehensive solution here since you'd still run the risk of having a STW pause amidst request processing.</p>


<p>As for jmx notifications on heap usage it's still just a guess in terms of what that actually means - the gc that follows may be concurrent (not STW) or there may not be a gc at all if the mem allocations aren't high enough.</p>


<p>I agree with Krystal that it makes most sense in tuning the GC + checking your own code to make sure it plays well with the GC algorithm that you're using (I.e. CMS).</p><div><div></div><div class="h5">
<div class="gmail_quote">On Dec 11, 2011 10:56 PM, "Li Li" <<a href="mailto:fancyerii@gmail.com" target="_blank">fancyerii@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Krystal Mok</b> <span dir="ltr"><<a href="mailto:rednaxelafx@gmail.com" target="_blank">rednaxelafx@gmail.com</a>></span><br>

Date: Sun, Dec 11, 2011 at 5:53 PM<br>
Subject: Re: how to know jvm is stopping the world?<br>To: Li Li <<a href="mailto:fancyerii@gmail.com" target="_blank">fancyerii@gmail.com</a>><br><br><br>HI,<div><br></div><div>You're probably looking in the wrong direction. When the JVM "stops-the-world", it stops the world -- all Java threads (or "mutators") are suspended. There's no way for you to execute any Java code during that period.</div>



<div>HotSpot VM uses a "safepoint" mechanism to stop-the-world. You can get safepoint stats with -XX:+PrintSafepointStatistics.</div><div><br></div><div>There's an alternative that might help. Try GC notification with JMX [1]. Setup a notification threshold, and when the heap usage crosses the threshold, you'll get a notification. Put the load balancing logic in the callback. Even though this is different from "a notification of stop-the-world pause", it might work for you.</div>



<div><br></div><div>There's a GC notification mechanism in .NET that might have been closer to what you wanted [2].</div><div><br></div><div>- Kris</div><div><br></div><div>[1]: <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/management/MemoryMXBean.html" target="_blank">http://docs.oracle.com/javase/6/docs/api/java/lang/management/MemoryMXBean.html</a><br>



[2]: <a href="http://msdn.microsoft.com/en-us/library/cc713687.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/cc713687.aspx</a></div><div><div></div><div><div><br><div class="gmail_quote">On Sun, Dec 11, 2011 at 2:31 PM, Li Li <span dir="ltr"><<a href="mailto:fancyerii@gmail.com" target="_blank">fancyerii@gmail.com</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>hi,</div><div>    In our application of full text searching with lucene and solr. we will give jvm about 25GB memory. we use CMS as old generation garbage collector. But the jvm sometimes can't do anything. So our clients complain that the connection is time out. we find the reason is the jvm is doing full gc and it will stop service for about 1-3 seconds.</div>




<div>    I know that this situation is inevitable when using CMS collector. but we have more than one searching machines, so if I know jvm is doing full gc(specially stop the world), I can send requests to other machines. But the question now is that jvm don't provide an api for that. I think it's not very difficult(for guys developing hotspot, but is in deed difficult for me ). So I want your help.</div>




<div>    The first question is where is the position of CMS full gc.</div><div>    from <a href="http://blogs.oracle.com/jonthecollector/entry/did_you_know" target="_blank">http://blogs.oracle.com/jonthecollector/entry/did_you_know</a></div>




<div>    there are many steps:</div><div>      1. STW initial mark</div><div>      2. Concurrent marking</div><div>      3. Concurrent precleaning</div><div>      4. STW remark</div><div>      5. Concurrent sweeping</div>




<div>      6. Concurrent reset</div><div>    there are 2 stop the world stages. I want to know the line number(or functions) of this stages. so I can tell java program that jvm now is doing full gc.</div><div>     The second is that how to communicate between jvm and java program? My expected thing is like :</div>




<div>     //java program</div><div>     if(System.isStopTheWolrd()){</div><div>           //system is busy, tell the dispatch node that don't send request to me</div><div>     }else{</div><div>           do service;</div>




<div>     }</div><div>     I have no experience in jvm developing. jvm is implemented in c and jni is the interface between them. is there any other method that jvm can achieve this? obviously, it can extend System class and add a static method named isStopTheWorld(). Could some one tell me how to do this in details? Thank you very much.</div>




</blockquote></div><br></div>
</div></div></div><br>
</blockquote></div>
</div></div></blockquote></div><br></div>