如何降低CPU消耗

wtogether wtogether 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近做了个WAP项目,访问的人一多,CPU就100,但是由于终端限制,无COOKIE,无Javascript,无框架,所以静态页面是没法用的,同时站点里多数页面都得有用户权限检测,所以搜索用户表是怎么也偷不了鸡的,就算不检测,同样需要把用户信息通过QUERY_STRING传递到下个需要检测的页面。

于是做了如下测试,测试的频率都是一样的:100个并发,每个并发20个请求,间隔100毫秒,这样的频率最多相当1000个并发
1.asp
<%@language="vbscript"%>
<%
Option Explicit

Response.Write "Hello World!"
%>
CPU在30左右

2.asp
<%@language="vbscript"%>
<%
Option Explicit

Dim xmlDoc
Set xmlDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlDoc.insertBefore xmlDoc.createProcessingInstruction("xml", "version=""1.0"" encoding=""utf-8"""), xmlDoc.childNodes(0)
xmlDoc.appendChild xmlDoc.createElement("root")
xmlDoc.Save Response
Set xmlDoc = Nothing
%>
CPU在40左右

3.asp,是一个简单VBS类,无任何COM,纯String操作,用到If Then/Select Case结构,只有Server.HTMLEncode/InStr/LCase/Replace/CBool/Left这些系统函数,没有&连接,CPU就在60-70间徘徊了,加上并发测试程序的20个CPU以及其他系统的CPU,整个系统已经100个CPU了
<%@language="vbscript"%>
<%Option Explicit%>
<%
Class IXML
Private blnCodePage
Private strDoctype
Private strTitle
Private strAlign
Private strFormTemp

Private Sub Class_Initialize()
blnCodePage = CBool(InStr(Request.ServerVariables("SERVER_SOFTWARE"), "5.0") = 0)
Response.Charset = "utf-8"
If blnCodePage Then
Response.CodePage = 65001
End If
strTitle = "WAP"
End Sub

Private Sub Class_Terminate()
Call XMLEnd
End Sub

Public Property Let Title(strIn)
strTitle = strIn
End Property

Public Sub SetPrefix(strIn)
Dim strAccept
strAccept = Request.ServerVariables("HTTP_ACCEPT")
strDoctype = LCase(strIn)
Select Case strDoctype
Case "wml"
Response.ContentType = "text/vnd.wap.wml"
Case "html"
Response.ContentType = "text/html"
Case "xhtml"
If InStr(strAccept, "application/vnd.wap.xhtml+xml") <> 0 Then
Response.ContentType = "application/vnd.wap.xhtml+xml"
ElseIf InStr(strAccept, "application/xhtml+xml") <> 0 Then
Response.ContentType = "application/xhtml+xml"
Else
Response.ContentType = "text/html"
strDoctype = "html"
End If
Case Else
If InStr(strAccept, "application/vnd.wap.xhtml+xml") <> 0 Then
Response.ContentType = "application/vnd.wap.xhtml+xml"
strDoctype = "xhtml"
ElseIf InStr(strAccept, "application/xhtml+xml") <> 0 Then
Response.ContentType = "application/xhtml+xml"
strDoctype = "xhtml"
ElseIf InStr(strAccept, "text/vnd.wap.wml") <> 0 Then
Response.ContentType = "text/vnd.wap.wml"
strDoctype = "wml"
Else
Response.ContentType = "text/html"
strDoctype = "html"
End If
End Select
Call XMLStart
End Sub

Public Sub Echo(varIn)
Printf varIn
Printf vbCrLf
End Sub

Public Sub Printf(varIn)
If blnCodePage = False Then
Response.BinaryWrite ConvertStringToUTF8(varIn)
Else
Response.Write varIn
End If
End Sub

Public Sub Println(varIn)
Printf varIn
Printf "<br/>"
End Sub

Private Function ConvertStringToUTF8(strIn)
Dim ret
Dim i
Dim uByte
Dim lByte(2)
For i = 1 To Len(strIn)
uByte = AscW(Mid(strIn, i, 1))
If uByte < 0 Then uByte = uByte + 65536
If uByte < 128 Then
ret = ret & ChrB(uByte)
ElseIf uByte < 2048 Then
lByte(1) = &H80 Xor (uByte And &H3F)
uByte = uByte \ (2 ^ 6)
lByte(0) = &HC0 Xor (uByte And &H1F)
ret = ret & ChrB(lByte(0)) & ChrB(lByte(1))
Else
lByte(2) = &H80 Xor (uByte And &H3F)
uByte = uByte \ (2 ^ 6)
lByte(1) = &H80 Xor (uByte And &H3F)
uByte = uByte \ (2 ^ 6)
lByte(0) = &HE0 Xor (uByte And &HF)
ret = ret & ChrB(lByte(0)) & ChrB(lByte(1)) & ChrB(lByte(2))
End If
Next
ConvertStringToUTF8 = ret
End Function

...全文

相关推荐

如何降低MIPS CPU 50%的动态功耗

在现代电子设计中,降低MIPS(MIPS架构的CPU)的动态功耗是一个关键的挑战,因为这直接影响到设备的能效和电池寿命。动态功耗是指由于晶体管开关活动产生的能量消耗,通常与工作频率和电压成正比。

weixin_38570519

Oracle消耗CPU的SQL分析[项目代码]

它们使数据库管理员能够快速定位问题所在,采取措施降低高消耗操作对系统性能的影响,最终提升数据库的整体运行效率。

kmeans3miner

网络游戏-利用内存零复制降低云计算网络传输能源消耗的方法.zip

**节能减排**:通过减少不必要的CPU操作,降低数据中心的能源消耗,符合绿色计算的发展趋势。4. **优化资源分配**:节省下来的CPU资源可以用于处理更多并发玩家,提升云服务器的整体承载能力。

programyg

电子功用-在备用模式中降低功率消耗的电源

编写高效能的代码,减少不必要的计算和循环,可以减少CPU的唤醒次数和时间,从而降低功耗。此外,适时关闭无线连接和传感器等外围设备,也能有效减少备用模式下的功率消耗。

programyg

面向多租户应用CPU资源消耗的回归分析方法改进研究.pdf

然而,随着租户数量的增长,如何有效管理和优化CPU资源消耗成为一个关键问题。本文主要探讨了针对多租户应用的CPU资源消耗进行回归分析方法的改进研究,旨在提高系统性能并确保服务质量。

数据资源
评论 8
收藏 已收藏
分享
返回顶部
wtogether
ASP 28,401 成员 356,940 内容