以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助][讨论]HttpRequest异步函数并发改进 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=128738) |
||||
-- 作者:浙江仔 -- 发布时间:2018/12/13 22:27:00 -- [求助][讨论]HttpRequest异步函数并发改进 HttpRequest代码中,加入了一些信息记录的函数,如下 实际运行过程中,已经把一些常用,容易同时使用的页面函数,都改造成了异步函数 但是涉及多人同时访问时,特别是我用微信群发模板消息出去后,用户短时间集中访问同一异步页面,还会造成拥堵排队现象 请帮我分析下,我这代码中,加了这些信息记录的函数,对程序的影响,对并发的影响是不是很大?怎么改善? Dim stt As Date = Date.Now try Select Case e.host Case "127.0.0.1","192.168.30.100" \'记录动作 Dim str As new StringBuilder str.AppendLine("path=" & e.Path) str.AppendLine("HttpMethod=" & e.Request.HttpMethod) If e.Cookies.ContainsKey("pxopenid") Then \'从cookie中获取微信用户id str.AppendLine("cookies=" & e.Cookies("pxopenid")) End If For Each key As String In e.Values.Keys str.AppendLine(key & "=" & e.Values(key) ) Next Functions.Execute("txtProgress",str.ToString) \'此代码用于窗口显示访问动态 Select Case e.Path Case "wxTest.htm" Functions.Execute("Http_WX_Test_openid",e)
Case 。。。。 End Select End Select catch ex As Exception Functions.Execute("ErrLogText",ex) \'记录错误日志 End Try Dim t As TimeSpan = Date.Now - stt Functions.Execute("weblog",e,t.TotalSeconds) \'记录页面访问相关信息,包括路径path ,耗时等 weblog: Dim e As RequestEventArgs = Args(0) Dim times As Single=args(1) Dim str As new StringBuilder For Each key As String In e.Values.Keys str.AppendLine(key & "=" & e.Values(key)) Next Dim host As String=e.host Dim path As String=e.path Dim Type As String=e.Request.HttpMethod Dim openid As String If e.host=Vars("V_host") Then If e.Cookies.ContainsKey("openid") Then \'从cookie中获取微信用户id Openid = Functions.Execute("CheckOpenid",e.Cookies("openid")) End If Else If e.Cookies.ContainsKey("pxopenid") Then \'从cookie中获取微信用户id Openid = e.Cookies("pxopenid") End If End If Dim cmd As new SQLCommand cmd.C cmd.CommandText = "Ins ert Into wxWeblog(host,path,CREATE_TIME,time,openid,type,remarks) Values(?,?,?,?,?,?,?)" cmd.Parameters.Add("@11",host) cmd.Parameters.Add("@22",path ) cmd.Parameters.Add("@66",now.Tostring.replace("-","").replace(" ","").replace(":","")) cmd.Parameters.Add("@33",times) cmd.Parameters.Add("@44",openid) cmd.Parameters.Add("@55",Type) cmd.Parameters.Add("@77",str.Tostring) cmd.ExecuteNonQuery txtProgress: Dim stt As Date = Date.Now Dim desc As String=args(0) If Forms("Http服务设置").opened Then Else Forms("Http服务设置").open End If desc = desc +"|"+ format(Date.now,"yyyy-MM-dd HH:mm:ss.ffff") Dim txtProgress As WinForm.TextBox = Forms("Http服务设置").Controls("txtProgress") txtProgress.Text = desc & vbcrlf & txtProgress.Text \'添加提示到文本框的第一行 Application.DoEvents() Output.Logs("AppLogs").Add( vbCrLf & desc) Output.Logs("AppLogs").Save(ProjectPath & "logs\\APPlogs"+format(Date.today,"yyyy-MM-dd")+".txt",True) \'日志位于当前项目目录里 Output.Logs("AppLogs").Clear If desc.length>1000 Then desc="" End If 实际运行时的耗时: |
||||
-- 作者:浙江仔 -- 发布时间:2018/12/13 22:31:00 -- 多人同时访问时,还会有如下错误,有时还会引起程序崩溃关闭
|
||||
-- 作者:有点甜 -- 发布时间:2018/12/13 23:01:00 -- 1、没有看到你写的异步函数。
2、异步操作的时候,不能对ui(窗口等)或者公共资源(表格等)赋值,不然可能会发生错误。
如果确实要做,需要同步函数 http://www.foxtable.com/mobilehelp/scr/3274.htm
3、具体做一个实例发上来测试。 |