Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hession反序列化导致CPU占用飙高 #351

Closed
ghsau opened this issue Dec 2, 2016 · 5 comments
Closed

Hession反序列化导致CPU占用飙高 #351

ghsau opened this issue Dec 2, 2016 · 5 comments

Comments

@ghsau
Copy link

ghsau commented Dec 2, 2016

com.alibaba.com.caucho.hessian.io.SerializerFactory getDeserializer

try {
	Class cl = Class.forName(type, false, _loader);// 消费端api没有升级时,这里会重复反射,当qps非常高时,会造成CPU占用严重飙高
	deserializer = getDeserializer(cl);
} catch (Exception e) {
	log.warning("Hessian/Burlap: '" + type + "' is an unknown class in " + _loader + ":\n" + e);
	log.log(Level.FINER, e.toString(), e);
}
@bert82503
Copy link

bert82503 commented Dec 13, 2018

我们在生产环境也遇到这个问题,现象是服务提供者耗时就1~2ms,但消费者耗时偶发性的2s超时。最开始通过链路跟踪看到耗时在网络,怀疑是网络重传包引起,TCP监控看到有一些异常但不明显,通过tcpdump没发现问题。然后有同事观察到CPU占用偶发性高,与超时时间保持一致,同时观察到下面的异常日志每天有1.5w上下。

  • dubbo-2.5.8
  • org.jboss.netty:netty-3.2.5.Final

完整的异常日志:

2018-12-13 00:00:02,863 WARN  [New I/O client worker #1-5] c.a.c.c.h.io.SerializerFactory:613 - [] [] [] Hessian/Burlap: 'com.xxx.ucenter.constant.AccountAuthLoginTypeEnum' is an unknown class in TomcatEmbeddedWebappClassLoader
  context: ROOT
  delegate: true
----------> Parent Classloader:
org.springframework.boot.loader.LaunchedURLClassLoader@442d9b6e
:
java.lang.ClassNotFoundException: com.xxx.ucenter.constant.AccountAuthLoginTypeEnum

从异常日志看到是Dubbo消费者的Netty客户端工作者线程(New I/O client workerNioWorker)在反序列化时一直找不到某个类型(ClassNotFoundException: AccountAuthLoginTypeEnum),然后不停地加载类引起。修复这个异常后,偶发性超时就没有了。

我们准备在SerializerFactory里对ClassNotFoundException异常做本地缓存,避免重复地加载找不到的类。

@ghsau
Copy link
Author

ghsau commented Dec 19, 2018

我们在生产环境也遇到这个问题,现象是服务提供者耗时就1~2ms,但消费者耗时偶发性的2s超时。最开始通过链路跟踪看到耗时在网络,怀疑是网络重传包引起,TCP监控看到有一些异常但不明显,通过tcpdump没发现问题。然后有同事观察到CPU占用偶发性高,与超时时间保持一致,同时观察到下面的异常日志每天有1.5w上下。

  • dubbo-2.5.8
  • org.jboss.netty:netty-3.2.5.Final

完整的异常日志:

2018-12-13 00:00:02,863 WARN  [New I/O client worker #1-5] c.a.c.c.h.io.SerializerFactory:613 - [] [] [] Hessian/Burlap: 'com.xxx.ucenter.constant.AccountAuthLoginTypeEnum' is an unknown class in TomcatEmbeddedWebappClassLoader
  context: ROOT
  delegate: true
----------> Parent Classloader:
org.springframework.boot.loader.LaunchedURLClassLoader@442d9b6e
:
java.lang.ClassNotFoundException: com.xxx.ucenter.constant.AccountAuthLoginTypeEnum

从异常日志看到是Dubbo消费者的Netty客户端工作者线程(New I/O client workerNioWorker)在反序列化时一直找不到某个类型(ClassNotFoundException: AccountAuthLoginTypeEnum),然后不停地加载类引起。修复这个异常后,偶发性超时就没有了。

我们准备在SerializerFactory里对ClassNotFoundException异常做本地缓存,避免重复地加载找不到的类。

嗯,就是这样解决

@bert82503
Copy link

[握手] 既然问题根源已找到,这个Issue就关闭了吧 @ghsau

@aacaiweiming
Copy link

请问这个问题在哪个版本解决的?

@bert82503
Copy link

@aacaiweiming
update hessian-lite to 2.3.5, fix unnecessary class load #3538

fix performance overhead caused by too much unknown classloading during hessian2 deserialization
apache/dubbo-hessian-lite#7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants