Java threads slow down towards the end of processing

风流意气都作罢 提交于 2019-12-01 06:42:42

This sounds alot like a Garbage Collection / Memory Issue.

When the Garbage Collection runs it pauses all threads so that the GC thread can do its "is this collectable garbage" analysis without things changing on it. While the GC is running you'll see exactly 1 thread at 100%, the other threads will be stuck at 0%.

I would consider adding a few Runtime.freeMemory() calls (or using a profiler) to see if the "grind to a halt" occurs during GC.

I'd also trying running your program on just the first 10k lines of your file to see if that works.

I'd also look to see if your program is building too many intermediate Strings when it should be using StringBuilders.

It sounds to me like you need to profile your memory usage.

I initially thought it was GC problems as well but I'm not so sure give the following information.

I've even tried on text files containing fewer lines and once again performance decreases towards the end of processing the file.

My guess is that the threads haven't quit but are jammed somehow. I would recommend taking a thread dump (kill -QUIT pid under *nix or by using jstack) and see where the threads are. This will help you identify if they are jammed somewhere.

I suspect that your program starts off with 24 threads running but over time you lose one and then another. Although it seems like there is a dramatic performance drop off at the end I wonder if the program has been getting slower and slower from the start.

  • Watch for sockets without proper connection or IO timeouts.
  • Maybe some sort of lock contention that is blocking threads?
  • Maybe something that Lucene is doing is either causing contention or is blocking your threads. As mentioned by @GPI, I would try commenting out the Lucene calls and see if the problem goes away. Again, a stack-trace will also show this to you.

Once you determine where the threads are blocking on, you will need to either resolve the lock issues, add timeouts to network calls, or otherwise fix the problem.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!