Javascript AJAX数据库实现高CPU处理
我的需求编号通知代码:Javascript AJAX数据库实现高CPU处理,javascript,jquery,sql,ajax,Javascript,Jquery,Sql,Ajax,我的需求编号通知代码: function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status == 200) { var Bil = xhttp.responseText; document.getE
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var Bil = xhttp.responseText;
document.getElementById("MsgNoti").innerHTML = Bil;
if ( Bil != ""){
if (ChkSession != "Mobile"){
window.open("Message/ViewMsgPopUp.asp", "", "width=900,height=600,top=25,left=100");
}
}
}
};
xhttp.open("GET", "CheckMsg1.asp", true);
xhttp.send();
}
这是CheckMsg1.asp中的代码
SQL ="select count(MsgID) over() as bil, MsgID from Msg where PopUpStatus = 'TRUE'"
set read = conn.execute(SQL)
if read.eof then
Bil = "0"
else
Bil1= read("bil")
end if
read.close()
Conn.Close()
response.write(Bil1)
我的代码有问题吗?当25-30个用户使用时,为什么这段代码会使服务器中的CPU进程变高。AJAX可以在7秒内运行,使用Javascript定时器。请帮我提些建议好吗?这段代码在ASP Classic中运行,你能试试吗
select count(MsgID) from Msg where PopUpStatus = 'TRUE' Group by MsgId
我认为Msg表有这么多数据,count()函数扫描表中的所有数据。这是昂贵的
我对你的问题有些想法
1-)您可以使用Nosql db(Mongo,Raven tec.)代替Msg表。只需在nosqldb上写入和读取Msg数据
2-)尝试在Msg表上添加索引PopUpStatus
3-)您可以使用汇总表统计Msg表。您可以在db上编写作业此作业获取Count Msg表,然后在其他表中写入计数值谢谢您回答我的问题。实际上我的数据库是SQL。你想让我改成Nosql吗?您的查询帮助了我,我已经为我的表编制了索引。无需更改mysql。我说过你应该同时使用mysql和nosql数据库。您只需对消息数据使用Nosql db,而不是mysql。其他数据可以存储在mysql上。这是hybrit解决方案。如果你考虑这个