如題,網(wǎng)站增加個統(tǒng)計ip的功能,于是有了如下代碼:每有一個ip訪問,都會執(zhí)行一次Count方法。在一分鐘500ip的時候,IIS就反應(yīng)不過來了,CPU占用100%,求優(yōu)化啊(不含有數(shù)據(jù)庫操作)public static readonly List<IPLog> IPList = new List<IPLog>();public void Count(xxxxx)
{ var log = new IPLog()
{
IP = ip,
VisitTime = DateTime.Now
};
IPList.Add(log); if (IPList.Count >= 1000)
{ var clone = ipList.GetRange(0, IPList.Count);
IPList.Clear(); //保存到數(shù)據(jù)庫(clone) //每1000IP提交到數(shù)據(jù)庫一次
//已注釋 }
}
- 1 回答
- 0 關(guān)注
- 517 瀏覽
添加回答
舉報
0/150
提交
取消