记录每秒钟执行几次
CPU占用率确很高,近100% 请问是怎么回事
以前记录在几万条时cpu不会太高的
代码如下:
set rs=server.CreateObject("adodb.recordset")
sql="select Count,SaveTime From MyUser where UserName='"&Request.Cookies("UserName")&"'"
rs.open sql,conn,1,3
if not (rs.eof or rs.bof) then
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
conn.close
set conn=nothing
是否代码还需优化~~~~
8 个解决方案
#1
sql=" update myuser set count=count+5,savetime=now() where UserName='"&Request.Cookies("UserName")&"'"
conn.execute sql
conn.execute sql
#2
不说其他,你的代码是否有问题,是很简单的问题
if not (rs.eof or rs.bof) then--表示不为空
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end ---这里的处理明显当成空
else--下面的出来可以吗?都为空,还可以取出 rs("Count")???
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
conn.close
set conn=nothing
if not (rs.eof or rs.bof) then--表示不为空
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end ---这里的处理明显当成空
else--下面的出来可以吗?都为空,还可以取出 rs("Count")???
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
conn.close
set conn=nothing
#3
楼上的说得很对。我再补充一点,你的if---else ---endif 后面多出了一个endif
if not (rs.eof or rs.bof) then
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
if not (rs.eof or rs.bof) then
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
#4
这种写法是小打小闹才这样写,用的人多这样的写法会使荧幕死机,你还是封装在dll,或者用sp吧,否则web server会玩挂的
#5
你上面的代码也还有很多漏洞!修改
if rs.eof or rs.bof then
rs.close --释放所有的资源
set rs = nothing
conn.close --然后跳到没有记录提示页面
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
'如果下面不需要秀出结果,那么conn也可以释放
conn.close
set conn = nothing'做成一个好习惯,只要不用,要显示释放资源,减轻服务器的负担
end if
if rs.eof or rs.bof then
rs.close --释放所有的资源
set rs = nothing
conn.close --然后跳到没有记录提示页面
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
'如果下面不需要秀出结果,那么conn也可以释放
conn.close
set conn = nothing'做成一个好习惯,只要不用,要显示释放资源,减轻服务器的负担
end if
#6
不好意思,代码没全部复制过来,看起来有点别扭
代码是否还有更好的写法。不会在记录非常宠大,使用量很大时CPU很高
Leftie(左手,为人民币服务) :这种写法能解决这个问题吗?效果是否会明显的?
代码是否还有更好的写法。不会在记录非常宠大,使用量很大时CPU很高
Leftie(左手,为人民币服务) :这种写法能解决这个问题吗?效果是否会明显的?
#7
如果用存储写怎么样?
#8
Leftie(左手,为人民币服务) :这种写法能解决这个问题吗?效果是否会明显的?
的写法会比你的快点,但是如果每天频繁的存取数据,那么是非常的慢
用sp当然会快点,因为用sp<只是把数据传过去,然后在服务器端执行,效率当然高很多
用sp写吧,速度快,如果用vb写成dll,速度也有提升,但是更新代码麻烦,因为要等用户不用时候把com停掉,更新!
不管用com还是sp,总之如果用的人多,就是同时很多人在往你的database存取数据,那么记住更新的代码写在begin transaction ...commit 里面,出错要回退,并且给用户提示,这些都是好习惯
的写法会比你的快点,但是如果每天频繁的存取数据,那么是非常的慢
用sp当然会快点,因为用sp<只是把数据传过去,然后在服务器端执行,效率当然高很多
用sp写吧,速度快,如果用vb写成dll,速度也有提升,但是更新代码麻烦,因为要等用户不用时候把com停掉,更新!
不管用com还是sp,总之如果用的人多,就是同时很多人在往你的database存取数据,那么记住更新的代码写在begin transaction ...commit 里面,出错要回退,并且给用户提示,这些都是好习惯
#1
sql=" update myuser set count=count+5,savetime=now() where UserName='"&Request.Cookies("UserName")&"'"
conn.execute sql
conn.execute sql
#2
不说其他,你的代码是否有问题,是很简单的问题
if not (rs.eof or rs.bof) then--表示不为空
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end ---这里的处理明显当成空
else--下面的出来可以吗?都为空,还可以取出 rs("Count")???
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
conn.close
set conn=nothing
if not (rs.eof or rs.bof) then--表示不为空
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end ---这里的处理明显当成空
else--下面的出来可以吗?都为空,还可以取出 rs("Count")???
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
conn.close
set conn=nothing
#3
楼上的说得很对。我再补充一点,你的if---else ---endif 后面多出了一个endif
if not (rs.eof or rs.bof) then
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
if not (rs.eof or rs.bof) then
conn.close
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
end if
end if
#4
这种写法是小打小闹才这样写,用的人多这样的写法会使荧幕死机,你还是封装在dll,或者用sp吧,否则web server会玩挂的
#5
你上面的代码也还有很多漏洞!修改
if rs.eof or rs.bof then
rs.close --释放所有的资源
set rs = nothing
conn.close --然后跳到没有记录提示页面
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
'如果下面不需要秀出结果,那么conn也可以释放
conn.close
set conn = nothing'做成一个好习惯,只要不用,要显示释放资源,减轻服务器的负担
end if
if rs.eof or rs.bof then
rs.close --释放所有的资源
set rs = nothing
conn.close --然后跳到没有记录提示页面
set conn=nothing
Response.Redirect "no.htm"
Response.end
else
rs("Count")=rs("Count")+5
rs("SaveTime")=now()
rs.update
rs.close
set rs=nothing
'如果下面不需要秀出结果,那么conn也可以释放
conn.close
set conn = nothing'做成一个好习惯,只要不用,要显示释放资源,减轻服务器的负担
end if
#6
不好意思,代码没全部复制过来,看起来有点别扭
代码是否还有更好的写法。不会在记录非常宠大,使用量很大时CPU很高
Leftie(左手,为人民币服务) :这种写法能解决这个问题吗?效果是否会明显的?
代码是否还有更好的写法。不会在记录非常宠大,使用量很大时CPU很高
Leftie(左手,为人民币服务) :这种写法能解决这个问题吗?效果是否会明显的?
#7
如果用存储写怎么样?
#8
Leftie(左手,为人民币服务) :这种写法能解决这个问题吗?效果是否会明显的?
的写法会比你的快点,但是如果每天频繁的存取数据,那么是非常的慢
用sp当然会快点,因为用sp<只是把数据传过去,然后在服务器端执行,效率当然高很多
用sp写吧,速度快,如果用vb写成dll,速度也有提升,但是更新代码麻烦,因为要等用户不用时候把com停掉,更新!
不管用com还是sp,总之如果用的人多,就是同时很多人在往你的database存取数据,那么记住更新的代码写在begin transaction ...commit 里面,出错要回退,并且给用户提示,这些都是好习惯
的写法会比你的快点,但是如果每天频繁的存取数据,那么是非常的慢
用sp当然会快点,因为用sp<只是把数据传过去,然后在服务器端执行,效率当然高很多
用sp写吧,速度快,如果用vb写成dll,速度也有提升,但是更新代码麻烦,因为要等用户不用时候把com停掉,更新!
不管用com还是sp,总之如果用的人多,就是同时很多人在往你的database存取数据,那么记住更新的代码写在begin transaction ...commit 里面,出错要回退,并且给用户提示,这些都是好习惯