fanliang11 / surging

Surging is a micro-service engine that provides a lightweight, high-performance, modular RPC request pipeline. support Event-based Asynchronous Pattern and reactive programming ,The service engine supports http, TCP, WS,Grpc, Thrift,Mqtt, UDP, and DNS protocols. It uses ZooKeeper and Consul as a registry, and integrates it. Hash, random, polling, Fair Polling as a load balancing algorithm, built-in service governance to ensure reliable RPC communication, the engine contains Diagnostic, link tracking for protocol and middleware calls, and integration SkyWalking Distributed APM
MIT License
3.24k stars 924 forks source link

服务引擎Server部署到CentOS Linux 7 的Docker中,运行一段时间后内存占用会变高 #174

Open wlhappy01 opened 6 years ago

wlhappy01 commented 6 years ago

在Rancher中监控到我部署的服务,在运行几天后内存占用到1个多G,我重启服务后内存占用又变为几十M,请问是什么原因?

fanliang11 commented 6 years ago

有多少服务,并发多少,docker 使用的是什么版本

fanliang11 commented 6 years ago

经过检测dotnetty 0.5.0+版本会有内存泄漏的问题,现在已经降至0.4.8版本

wlhappy01 commented 5 years ago

fanliang11,您好,我下载了最新版本进行测试,发现用你的Demo示例内存并没有增加,但是我编写的业务组件则内存一直增加,奇怪的是在我并没有访问服务的情况下也是一直在增加,我对比了我写的业务组件与您的Demo(Surging.Modules.Common)的区别,如下:

1.我在业务组件中使用了Mongodb数据库 2.代码如下 服务 public class XXXXService : ProxyServiceBase,IXXXXService { private readonly MongoBaseRespository _repository; public MongoTestService(MongoBaseRespository repository) { this._repository = repository; } ............................................ } 数据库MongoBaseRespository

public class MongoBaseRespository : BaseRepository { ///

/// MongoDB配置文件名 /// private const string CONFIG_FILE_NAME = "appsettings.json"; /// /// 是否使用在Surging /// public bool UseSurging { get; set; } = true; /// /// mongodb配置文件对象 /// public MongoDBConfig DBConfig { get; set; }

    public MongoBaseRespository()
    {
        //构建配置对象DBConfig
        InitConfig();
    }
    #region 初始化数据库
    /// <summary>
    /// 构建mongodb配置文件对象
    /// </summary>
    private void InitConfig()
    {
        MongoDBConfig config = new MongoDBConfig();
        if (UseSurging)
        {
            IConfigurationSection mongoSection = Surging.Core.CPlatform.AppConfig.GetSection("MongoDB");
            if (mongoSection == null)
            {
                throw new ArgumentNullException("在surging appsettings.json中没有配置MongoDB配置节");
            }
            config.IpAddress = mongoSection["IpAddress"];
            config.Port = mongoSection["Port"];
            config.UserName = mongoSection["UserName"];
            config.Password = mongoSection["Password"];
            config.PoolMin = mongoSection["PoolMin"];
            config.PoolMax = mongoSection["PoolMax"];
            config.ConnectTimeOut = mongoSection["ConnectTimeOut"];
            config.DataBase = mongoSection["DataBase"];
            config.AuthDatabase = mongoSection["AuthDB"];
        }
        else
        {
            var build = new ConfigurationBuilder().AddJsonFile(CONFIG_FILE_NAME, true, true);
            IConfigurationRoot configuration = build.Build();
            config.IpAddress = configuration["MongoDB:IpAddress"];
            config.Port = configuration["MongoDB:Port"];
            config.UserName = configuration["MongoDB:UserName"];
            config.Password = configuration["MongoDB:Password"];
            config.PoolMin = configuration["MongoDB:PoolMin"];
            config.PoolMax = configuration["MongoDB:PoolMax"];
            config.ConnectTimeOut = configuration["MongoDB:ConnectTimeOut"];
            config.DataBase = configuration["MongoDB:DataBase"];
            config.AuthDatabase = configuration["MongoDB:AuthDB"];

        }
        DBConfig = config;
    }

..............................................

}

因为我在测试服务器上并没有对服务进行访问,但内存还是在自己增长,但是我部署您编写的Demo则正常,实在想不出原因,水平有限,请教了~~~~

fanliang11 commented 5 years ago

抱歉,我肉眼也看不出内存泄漏的问题,你可以用IDE内置工具来跟踪内存占用

wlhappy01 commented 5 years ago

fanliang11,我用IDE观察了内存变化,发现是一个StringBuilder对象一直增加,但不能查看对象引用位置,不知如何查看此StringBuilder对象所在位置,求大神指点,截图如下: image image image image

fanliang11 commented 5 years ago

按照上面截图来看,应该是nlog出现的问题,Nlog写入file,还是Console?minlevel是什么,可以试试按照https://github.com/NLog/NLog/issues/2933 进行操作