Mysql 高并发情况下,Sqlsugar 执行速度很慢,数据库一切正常 返回
监测下来的 sqlsugar 执行时间
数据库执行时间【压测时直接数据库进行查询】
代码
/// <summary>
/// 获取详情
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<GroupBuyingDetailModel> GetDetailAsync([FromQuery] int id)
{
var shopId = MinAppUser.ShopId;
var openId = MinAppUser.OpenId;
var cusId = MinAppUser.CusId;
using var newDb = _groupBuyingGoodsRep.Context.CopyNew();
var info = await newDb.Queryable<T_GroupBuying, DC_Customer, T_CusDistribution>((x, cus, cusDistri) => new object[]
{
JoinType.Left,x.CusId == cus.F_Id,SqlWith.NoLock,
JoinType.Left,cus.F_Id == cusDistri.CusId, SqlWith.NoLock,
})
.Where((x, cus, cusDistri) => x.F_Id == id)
.Select((x, cus, cusDistri) => new GroupBuyingDetailModel
{
F_Id = x.F_Id,
StartTime = x.StartTime,
EndTime = x.EndTime,
ExpressWay = x.ExpressWay,
ForwardingSetting = x.ForwardingSetting,
GroupBuyingIds = x.GroupBuyingIds,
GroupBuyingIntroduction = x.GroupBuyingIntroduction,
IsShowKc = x.IsShowKc,
MinPurchaseSetting = x.MinPurchaseSetting,
MinPurchaseWaySetting = x.MinPurchaseWaySetting,
MinSetting = x.MinSetting,
NotificationPush = x.NotificationPush,
State = x.State,// == 3 ? 2 : x.State,
TourPrompt = x.TourPrompt,
UserDisplaySetting = x.UserDisplaySetting,
Title = x.Title,
SmartGroupBuying = x.SmartGroupBuying,
SumPrice = x.SumPrice,
ParentGroupBuyingCusId = x.ParentGroupBuyingCusId,
ParentGroupBuyingId = x.ParentGroupBuyingId > 0 ? x.ParentGroupBuyingId : x.F_Id,
PackagePriceSetting = x.PackagePriceSetting,
CusId = x.CusId,
CusName = cus.F_Name,
HeadImg = cus.HeadImg,//.Contains("http") ? cus.HeadImg : _options.Value.WebPath + cus.HeadImg,
Isme = cus.Openid == openId,
MemberNum = cusDistri.MemberNum,
CusPackageNum = cusDistri.PackageNumber,
CusRemark = cusDistri.Remark,
CusDistributionType = cusDistri.CusDistributionType,
CreateTime = x.CreateTime,
IsTop = x.Sort > 0,
SellDescription = x.SellDescription,
SellSetting = x.SellSetting,
HomeBackgroundUrl = x.HomeBackgroundUrl,//.Contains("http") ? x.HomeBackgroundUrl : _options.Value.WebPath + x.HomeBackgroundUrl,
IsShowBaseData = cusDistri.IsShowBaseData,
IsIntelligentBackground = x.IsIntelligentBackground,
//SellCusDistributionId = cus.Openid == openId ? 0 : x.SellSetting == 1 ? cusId : x.SellSetting == 2 ? SqlFunc.Subqueryable<T_SellGroupBuying>().Where(s => s.SellCusDistributionId == cusId && s.GroupBuyingId == x.F_Id).Select(s => s.SellCusDistributionId) : 0,
SellCusDistributionWay = x.SellCusDistributionWay,
NeteaseImAccId = cus.NeteaseImAccId,
NeteaseImToken = cus.NeteaseImToken,
GroupBuyingClassId = x.GroupBuyingClassId,
IsFreePrice = x.IsFreePrice,
PackageNumber = x.PackageNumber,
MinPrice = x.MinPrice,
MaxPrice = x.MaxPrice,
MinCusDistributionBrokeragePrice = x.MinCusDistributionBrokeragePrice,
MaxCusDistributionBrokeragePrice = x.MaxCusDistributionBrokeragePrice,
ExamineNum = x.ExamineNum + x.BaseExamineNum,
GroupNum = x.PackageNumber + x.FakePackageNumber,
//ExamineNum = x.ExamineNum + x.BaseExamineNum,
//GroupNum = x.PackageNumber + x.BasePackageNumber,
})
.FirstAsync();
}
热忱回答(3)
-
fate sta VIP01周前
max pool size设置成 512 试一下 ,异步连接池满了就会排队默认是100最大512 。数据库长时间并发尽量不要超过1000。1000以上想办法改成批量。
0 回复 -
johnsm VIP01周前
已设置 最小100 - 最大512 ,还是没啥效果
批量指的是?
0 回复 -
fate sta VIP01周前
@johnsm:查询用缓存,写入用批量 来减少数据库请求次数
一般异步处理长时间1000(持续很久)左右并发,短时间(1-2秒)5000左右并发。 如果并发过高那肯定是不行的
比如有耗时的操作等那肯定是不行的
0 回复