2014-04-01 62 views
0

我的應用程序監聽kafka話題並將數據轉儲到cassandra。線程也從mongo加載一些信息。 kafka滯後題目增加。我已經看到,加載某些類時主要是線程被阻塞。下面附上我的thread_dump線程在加載Class時通過ClassUtils.java被阻止

"KafkaConsumer-49" prio=10 tid=0x00007f1178fdd000 nid=0x78e0 waiting for monitor entry [0x00007f1155fb5000] 
    java.lang.Thread.State: BLOCKED (on object monitor) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:403) 
     - waiting to lock <0x00000006c0655b58> (a java.lang.Object) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
     at org.springframework.util.ClassUtils.forName(ClassUtils.java:258) 
     at org.springframework.data.convert.SimpleTypeInformationMapper.resolveTypeFrom(SimpleTypeInformationMapper.java:56) 
     at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:103) 
     at org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed(DefaultTypeMapper.java:144) 
     at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:121) 
     at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:186) 
     at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:176) 
     at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:172) 
     at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:75) 
     at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:1840) 
     at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1536) 
     at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1336) 
     at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1322) 
     at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495) 
     at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:486) 
     at com.snapdeal.coms.timemachine.mao.TimeMachineMao.getVendorProductsForUploadId(TimeMachineMao.java:32) 
     at com.snapdeal.coms.timemachine.service.TimeMachineService.getVendorProductsForUploadIdAndSupc(TimeMachineService.java:35) 
     at com.snapdeal.coms.timemachine.event.SupcUploadIdStateUpdateEventHandler.handleEvent(SupcUploadIdStateUpdateEventHandler.java:40) 



KafkaConsumer-48" prio=10 tid=0x00007f1178fdb000 nid=0x78df waiting for monitor entry [0x00007f11560b6000] 
    java.lang.Thread.State: BLOCKED (on object monitor) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:403) 
     - waiting to lock <0x00000006c0655b58> (a java.lang.Object) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
     at org.springframework.util.ClassUtils.forName(ClassUtils.java:258) 
     at org.springframework.data.convert.SimpleTypeInformationMapper.resolveTypeFrom(SimpleTypeInformationMapper.java:56) 
     at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:103) 
     at org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed(DefaultTypeMapper.java:144) 
     at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:121) 
     at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:186) 
     at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:176) 
     at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:172) 
     at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:75) 
     at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:1840) 
     at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1536) 
     at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1336) 
     at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1322) 
     at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495) 
     at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:486) 
     at com.snapdeal.coms.timemachine.mao.TimeMachineMao.getVendorProductsForUploadId(TimeMachineMao.java:32) 
     at com.snapdeal.coms.timemachine.service.TimeMachineService.getVendorProductsForUploadIdAndSupc(TimeMachineService.java:35) 
     at com.snapdeal.coms.timemachine.event.SupcUploadIdStateUpdateEventHandler.handleEvent(SupcUploadIdStateUpdateEventHandler.java:40) 
     at com.snapdeal.coms.timemachine.TimeMachine.onEvent(TimeMachine.java:109) 

「KafkaConsumer-47」 PRIO = 10 TID = 0x00007f1178fd9800 NID = 0x78de等待監視器條目[0x00007f11561b7000] java.lang.Thread.State中:BLOCKED(對象監視器上) 在java.lang.ClassLoader中.loadClass(ClassLoader.java:403) - 等待鎖定< 0x00000006c0655b58>(java.lang.Object) at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader .loadClass(ClassLoader.java:356) at org.springframework.util.ClassUtils.forName(ClassUtils.java:258) at org.springframework.data.convert.SimpleTypeInfo在org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed(DefaultTypeMapper.java:144)上的rmationMapper.resolveTypeFrom(SimpleTypeInformationMapper.java:56) at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:103) 在org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:121) 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:186) 在org.springframework。 data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:176) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:172) at org.springframework.data。 mongodb.core.convert.MappingMongoConverter.read(Mappin gMongoConverter.java:75) at org.springframework.data.mongodb.core.MongoTemplate $ ReadDbObjectCallback.doWith(MongoTemplate.java:1840) at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java: 1536) 在org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1336) 在org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1322) 在有機springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495) 在org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:486)

"KafkaConsumer-46" prio=10 tid=0x00007f1178fd8000 nid=0x78dd waiting for monitor entry [0x00007f11562b8000] 

java.lang.Thread.State:BLOCKED(在對象監視器上) at java.lang.ClassLoader.loadClass(ClassLoader.java:403) - 等待鎖定< 0x00000006c0655b58>(java.lang.Object) at sun .misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at org.springframework.util.ClassUtils.forName(ClassUtils.java:258) org.springframework.data.convert.SimpleTypeInformationMapper.resolveTypeFrom(SimpleTypeInformationMapper.java:56) at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:103) at org.springframework.data.convert.DefaultTypeMapper .getDefaultedTypeToBeUsed(DefaultTypeMapper.java:144) 在org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:121) 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:186) 在org.springframework。 data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:176) at org.springframework.data.mongodb.core.convert。MappingMongoConverter.read(MappingMongoConverter.java:172) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:75) at org.springframework.data.mongodb.core.MongoTemplate $ ReadDbObjectCallback。 doGith(MongoTemplate.java:1840) at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1536) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java: 1336) 在org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1322) 在org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495) 在有機springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:486) at com。 snapdeal.coms.timemachine.mao.TimeMachineMao.getVendorProductsForUploadId(TimeMachineMao.java:32) at com.snapdeal.coms.timemachine.service.TimeMachineService.getVendorProductsForUploadIdAndSupc(TimeMachineService.java:35) at com.snapdeal.coms.timemachine。 event.SupcUploadIdStateUpdateEventHandler.handleEvent(SupcUploadIdStateUpdateEventHandler.java:40)

我不確定爲什麼所有線程都被阻塞。我以爲班級只能加載一次,之後不需要任何鎖定。

回答

0

您是否嘗試過使用ConsumerOffsetChecker來查看您的消費者是否還活着?你可以從你$KAFKA_ROOT_DIR/文件夾內嘗試使用以下命令

bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group consumer-group1 --zkconnect zkhost:zkport --topic topic1 

下面是從他們的FAQ頁採取幾注

如果消費者偏移一段時間後不動,那麼消費者很可能已經停止。如果消費者偏移正在發生變化,但消費者滯後(日誌結束與消費者偏移之間的差異)正在增加,消費者比生產者慢。如果消費者速度較慢,那麼典型的解決方案是增加消費者的並行度。這可能需要增加話題的分區數量。

以上常見問題解答頁面還解釋了您的消費者被阻止背後的可能原因,可能值得一看。

+0

我已經檢查過。消費者抵消正在發生,但滯後正在增加。我已經創建了100個關於我的主題的截圖,目前正在運行50個消費者線程。在分析線程轉儲時,我看到大多數線程處於阻塞狀態。已經附加線程轉儲 –

+0

'如果消費者偏移正在移動,但消費者滯後(日誌結束與消費者偏移之間的差異)正在增加,則消費者比生產者慢 - 從我可以算出的FAQ – user2720864

+0

這就是爲什麼我增加了消費者線程數。但大多數線程在從類加載器中的mongo中檢索數據時處於阻塞狀態。我不明白爲什麼同班同學再次加載。 –

0

問題在於從mongo獲取數據。有大量的數據和分頁沒有實現,並且特定的請求沒有套接字超時,因此線程被阻塞。

相關問題