JVM Garbage Collector suddenly consumes 100% CPU after running for several hours
<p>I've got a strange problem in my Clojure app.</p>

<p>I'm using http-kit to write a websocket based chat application.</p>

<p>Client's are rendered using React as a single page app, the first thing they do when they navigate to the home page (after signing in) is create a websocket to receive things like real-time updates and any chat messages. You can see the site here: www.csgoteamfinder.com</p>

<p>The problem I have is after some indeterminate amount of time, it might be 30 minutes after a restart or even 48 hours, the JVM running the chat server suddenly starts consuming all the CPU. When I inspect it with NR (New Relic) I can see that all that time is being used by the garbage collector -- at this stage I have no idea what it's doing.</p>

<p>I've take a number of screenshots where you can see the effect.</p>

<p><a href="https://i.stack.imgur.com/wD0So.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wD0So.png" alt="New Relic showing memory usage over a 7 day period"></a></p>

<p><a href="https://i.stack.imgur.com/UgPpk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UgPpk.png" alt="More New Relic statistics"></a></p>

<p>You can see a number of spikes, those spikes correspond to large increases in CPU usage because of the garbage collector. To free up CPU I usually have to restart the JVM, I have been relying on receiving a CPU alert from NR in my slack account to make sure I jump on these quickly....but I really need to get to the root of the problem.</p>

<p>My initial thought was that I was possibly holding onto the socket reference when the client closed it at their end, but this is not the case. I've been looking at socket count periodically and it is fairly stable.</p>

<p>Any ideas of where to start? </p>

<p>Kind regards, Jason.</p>