首页 新闻 搜索 专区 学院

为什么程序的内存在缓慢上涨,没有回收?

0
悬赏园豆:10 [已关闭问题] 关闭于 2020-03-25 07:49

问题现像:core.net3.1最新版,采用Dapper调用数据库,数据库为ms2017版本,现在内存在回收,很多内存转换为Heap Generation 2内存,服务器内存在慢慢的涨,最高涨到8个多G,但是系统不是很卡。不知道是什么原因。
内存分布:

数据访问代码:
public async Task<IEnumerable<dynamic>> GetTopVideo(int topSize, Guid userId = default)
{
var strSql =
"SELECT Top(@TopSize) A.*,B.Id as UserId,B.NickName,B.Verified,B.AvatarUrl,B.AlbumName,B.IsAdmin,C.VideoTypeName,(select IsCancel from User_Behavior_Table where VideoId=A.Id and [TYPE]=5 and UserId=@UserId) as IsCollection FROM [User_Video_Table] A INNER JOIN User_VideoUser_Table B ON A.VideoAuthorId=B.Id Inner join User_VideoType_Table C on C.Id=A.VideoType WHERE VideoFlag=2 And IsTop=1 ORDER BY VideoUpTime DESC";
await using var conn = new SqlConnection(ConnectionString);
var topList = await conn.QueryAsync<dynamic>(strSql, new {TopSize = topSize,UserId=userId});
var newVideoList = new List<dynamic>();

        foreach (var item in topList)
        {
            var videoCoverPath = Utils.StringHelper.GetPicSrcPath((string) item.VideoCoverPath);
            var videoPath = Utils.StringHelper.GetVideoSrcPath((string) item.VideoPath);
            var avatarUrl = Utils.StringHelper.GetPicSrcPath((string) item.AvatarUrl);
            string timeStr = item.VideoTime;
            DateTime videoUpTime = item.VideoUpTime;
            var videoTime = videoUpTime.ToString("yyyy-MM-dd HH:MM");
            if (timeStr.Split(":").Length == 3)
            {
                timeStr = DateTime.TryParse(timeStr, out var time) ? time.ToString("mm:ss") : "00:00";
            }

            bool isCollection = item.IsCollection == null ? false : !item.IsCollection;
            newVideoList.Add(new
            {
                isPlay = false,
                item.Id,
                item.Hits,
                item.IsHot,
                item.IsRecommend,
                item.IsTop,                
                item.TopicId,
                item.VideoAuthorId,
                VideoCoverPath = videoCoverPath,
                item.VideoFlag,
                videoPath,
                item.VideoSummary,
                VideoTime = timeStr,
                item.VideoTitle,
                item.VideoType,
                VideoUpTime = videoTime,                  
                item.GoodHits,
                item.ShareHits,
                item.LikeHits,
                item.VideoTypeName,
                item.NickName,
                avatarUrl,
                item.CommentCount,
                item.AlbumName,
                item.SharePicHits,
                isCollection,
                item.Verified,
                item.IsOriginal,
                item.IsAdmin
            });

        }

        return newVideoList;
    }

前端调用代码
[HttpPost]
public async Task<IActionResult> GetTopVideo([FromForm]string userId, [FromForm]int topSize = 3)
{
if (Guid.TryParse(userId, out var id))
{
var videoList = await _videoRepository.GetTopVideo(topSize, id);
return Ok(videoList);
}
else
{
var videoList = await _videoRepository.GetTopVideo(topSize);
return Ok(videoList);
}

    }

莫非是Dapper缓存的原因吗?

冰封的心的主页 冰封的心 | 初学一级 | 园豆:178
提问于:2020-03-23 13:19
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册