search

Home  >  Q&A  >  body text

How to make Tomcat automatically remove from nginx upstream before GC to avoid timeout?

Tomcat will perform fullgc every once in a while. If nginx sends a request at this time, the request will time out.

One solution is to set a shorter timeout on the nginx side. If there is no response, change the machine to resend the request. However, the problem is that this request is a side effect and is not allowed to happen again.

I would like to ask, is there a mechanism whereby nginx automatically removes tomcat before gc, and then automatically adds it back after gc is completed?

In short, it is to avoid the timeout impact caused by tomcat gc~

PS:

nginx's upstream is set up with multiple tomcats. As long as one gc occurs, all requests falling on this machine will time out.

为情所困为情所困2738 days ago640

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:23:13

    Tomcat has a listener to prevent memory overflow:

    org.apache.catalina.core.JreMemoryLeakPreventionListener
    

    I suspect it is caused by adjusting System.gc(), and this GC may be using the stop the world method, which means it is non-concurrent. You can try the following two options:

    1.-XX:+ExplicitGCInvokesConcurrent concurrent GC
    2. Disable the listener or disable direct calls from the JVM level -XX:+DisableExplicitGC

    Then observe for a while.

    reply
    0
  • Cancelreply