Justagreenonion 2019-12-24
最近线上服务经常 出现cpu达到100%的问题,发现都是执行oracle操作的方法就没有返回。经过排查,最后定位到cpu消耗在以下方法
System.Collections.Generic.Dictionary`2<system.type,system.boolean>.FindEntry (...)
System.Collections.Generic.Dictionary`2<system.__canon,system.boolean>.TryGetValue (...)
MyBatis.DataMapper.TypeHandlers.TypeHandlerFactory.IsSimpleType (...)
MyBatis.DataMapper.DataExchange.ComplexDataExchange.GetData (...)
MyBatis.DataMapper.Model.ParameterMapping.ParameterMap.SetParameter (...)
MyBatis.DataMapper.Data.DefaultPreparedCommand.ApplyParameterMap (...)
MyBatis.DataMapper.Data.DefaultPreparedCommand.Create (...)
MyBatis.DataMapper.MappedStatements.MappedStatement.Execute (...)
MyBatis.DataMapper.MappedStatements.MappedStatement.ExecuteUpdate (...)
MyBatis.DataMapper.DataMapper.Update (...)
查看IsSimpleType方法内部实现
public bool IsSimpleType(Type type)
{
bool result = false;
if (!simpleTypes.TryGetValue(type, out result))
{
if (type != null)
{
ITypeHandler handler = GetTypeHandler(type, null);
if (handler != null)
{
result = handler.IsSimpleType;
}
simpleTypes[type] = result;
}
}
return result;
}Dictionary 操作没有加锁,get和set并发执行时就有几率导致cpu占满,方法无法跳出