Write down an online production problem

The ante-cause is that I wrote a piece of code, which is essentially a timed task, polling the database tables to see if there’s any stale data, and then deleting it. The code logic was already written, but now I add a few more tables, do the same thing, and then I find that when I deploy to a production environment, fullGc problems occur frequently.

To solve the process

First, the supervisor asked me to see if there was any code frequently creating objects in the submitted code. After I checked it several times, I found there was no code. So what would be the problem?

After many checks, I used Java VisulaVM tool of JDK to analyze the heap memory, and found that there were too many log objects in the system, accounting for nearly 70% of the total and 36% of the memory. The log used DAsyncLoggerConfig of Log4j. FullGc is frequently triggered because internal logs are frequently used in the system and the default RingBufferSize is too large, which occupies too much memory

Know the problem, we can solve, first of all, we can configure the parameters of the JVM – DAsyncLoggerConfig. RingBufferSize = 50000, to reduce the usage log instance, found that really effect is very obvious.

reflection

In code, try not to create objects too often. Singletons, like for loops, can also help avoid these problems.