问题现像: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缓存的原因吗?