我有5个线程(还有来自码头网络服务器的许多线程)的多线程Java应用程序,其中一些不时在读/写mongodb。有些写操作很费力,我读了20万个mongodb对象,但是它们并不是连续发生的,而是每几分钟发生一次。几个小时后,应用程序完美运行,但是后来我看到了这种情况:
就我所知,Mongo没有做任何工作:
这是我的jstack输出:
https://gist.github.com/stiv-yakovenko/06b0d235fd2c32d839788edf56aaa6cd
You can see that all threads are waiting for one thread, which, in turn is waiting for mongo, while mongo is doing nothing. Before problem begings, healthy situation is that no threads are waiting for anyone else, because load is not that high to block everything. Before mongo I was using mapdb to store same data and I never had issues like that.
I've seen same situation with multiple threads waiting for mongo, so I decided to put all mongodb invocations under the same ReentrantLock(true). I hoped that rootcause was too many threads wanted to access mongo, but it doesn't help. I don't know what to do, tried to reproduce the problem with simple code, but I can't. Any ideas?
UPD: here is jstat output as one of commenters requested:
好吧,最后证明这是一个垃圾收集。我最终使用了G1垃圾收集器。但这还不够,因为它无法提供所需的延迟(尽管已经很接近)。我必须将应用程序分为两部分,一部分用于进行大量垃圾产生计算,另一部分用于低延迟Web响应。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句