关于webapi调用wcf并发假死的分析

原来IDFA(IOS推广获取到用户IOS手机的惟一标识,若是不刷机的话跟安卓的IMEI同样)在公司正常的页面是公用用一个网站和数据库的。mysql

起初怀疑并发数太多,把数据库链接池的数量从一百设置到三百,确实有点反应,可是支持不到一天就又报错。web

 

 

 

查看了webapi链接wcf不少都超时,一台api和wcf不够用而后叫运维从一台服务器扩展到多台,报错的频率比原来低了。sql

看到网上设置是否是由于WCF不是多线程的缘由,而后形成等待超时,而后设置了WCF支持多线程,可是仍是没有多少做用。数据库

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]api

 

 

还有怀疑天天的写入调用太频繁,把写入的数据改成消息队列,而不是开线程的插入,否则短期内线程多开太多,会形成服务器线程异常。服务器

 

怀疑并发太多形成数据库堵塞(最大一个表的数据达600W)。网络

 

 

常常报错,影响到原有的公司正常业务,可是看了数据一天请求也只不过一二十万的请求量,也不至于这么不抗压,抱着怀疑的心态跟上级申请把这块相关,另一个缘由是其余项目组也要用到这个项目,推广部以为如今的网站常常报错,也支撑不起另一个项目的IDFa的访问量,因此考虑独立一个数据库出来,而后在本地IIS和测试环境(一台真实服务器拆分下来分开多台的虚拟服务器)。多线程

而后怀疑是否是跟以前最开始的mysql数据库版本不兼容,形成的缘由。由于网上有说这方面的缘由,可是好久了好久以为不是这个缘由,由于其余平台也是这样迁移数据的。尚未错误。并发

 

 

在本地写了一个windform测试本地的IIS和测试环境(服务器搭建的虚拟机,有内存和CPU方面的限制)的IIS的网,网站链接WCF、wcf链接数据库都没有问题,而上线到线上却出问题了,我和运维各类尝试,后面在想直接写个winform程序链接wcf看看有没有问题,而后在线上跑确实没有问题,在想是否是真的网站链接wcf链接数太多,而后运维直接去写直接去查询,原来真的是链接数太多,一会儿有两千多个链接数,真的是网站链接wcf卡住了,要等要IIS应用程序池默认释放才行(默认是5分钟),而winform链接wcf,释放是winform本身释放的规则,而本地测试环境的IIS会本身释放的缘由是测试的时候并发太大,而内存和CPU自己很小,形成系统级让IIS强制回收没用的链接。app

 

查询某个端口被占用链接数的命令

netstat -ant  |findstr 10209 >1.txt

文件在C:\Users\Administrator下面。

 

IDFA相关的说明:

https://www.zhihu.com/question/38856446

登陆加入知乎

有没有人给解释一下IDFA是什么,能怎么用?

关注者

 

关注问题写回答

2 个回答

默认排序

 

沙铭

精通英语和ASO,擅长获取免费流量,为国内和出海App提供咨询服务。

87 人赞同了该回答

了解IDFA,看我这篇文章就够了

双11剁手后,我静静的限制了广告追踪

今年双11爆了,据统计,全天交易额1207亿,移动端占比82%,在马云的持续教育和移动端的爆发下,用户在移动端消费的习惯已经不可逆转!

然而,另一个你们没法忽视的问题就是:我的隐私。我在《App推广实战(含ASO)》视频课程中详细介绍过这个话题,里面提到了移动用户的网络身份证这个概念,有兴趣的能够点击连接深刻了解。

假如没有网络身份证,那么每一个商家(App)只能基于本身的帐号体系标识用户,并记录用户的行为。而有了统一的网络身份证以后,各个商家之间的数据就能够打通了,天猫不只知道用户A在淘宝系的购物数据,也能了解到该用户在社交网络的行为,以及旅游的喜爱,等等。

你们能够想象一下,随着时间的推移,用户在移动端的行为数据越积越多,用户就会变得愈来愈像透明人,除非换手机,几乎没有任何办法去抵御这个科技带来的负面效应。

只有一个例外,苹果!苹果的特立独行体如今诸多方面,用户隐私就是其中之一。

苹果为了保护用户隐私,早在2012年就再也不容许其生态中的玩家获取用户的惟一标识符,可是商家在移动端打广告的时候又但愿能监控到每一次广告投放的效果,所以,苹果想出了折中的办法,就是提供另一套和硬件无关的标识符,用于给商家监测广告效果,同时用户能够在设置里改变这串字符,致使商家没有办法长期跟踪用户行为。这个就叫作广告标识符(IDFA),设置路径是“设置->隐私->广告->还原广告标识符”,以下图所示(iOS9)

 

由于这个IDFA不是惟一的,因此一开始行业内是很抵触的,千方百计去获取UDID(跟手机绑定的,用户不能改变),引发苹果大怒,在13年时禁止全部App获取UDID,不然不能上架,也正由于其生态的封闭性,才能迫使你们就范。虽然IDFA不是惟一的,可是毕竟赛过没有,何况也没有多少用户会去更改。所以,通过几番争斗,IDFA已经成为通用的iPhone用户标识符,这个过程分为6个阶段,我用下图总结

 

然而在今年iOS10推出后,广告界大为震惊,由于苹果推出了“限制广告追踪”功能,设置的路径和iOS9一致。可能细心的人注意到了,这个功能并不是iOS10独有啊,在以前的版本中也同样存在。不过通过实际的测试,在iOS10以前,即便用户打开这个功能,商家同样能够获取IDFA,只不过与以前的不同了,每次切换这个开关与点击“还原广告标识符”的效果同样。而iOS10就不同了,当用户打开这个功能后,商家只能获取到一连串无心义的0,这才是广告界大为震惊的缘由所在!

 

不过,须要澄清的是,限制广告跟踪后看到的广告并不会少,只是商家没有办法根据兴趣去定向了,由于你成为了一个没有身份证的“黑户”。

据说这个功能一推出,就受到美国用户的追捧,而亚洲启用率偏低,据Adjust在10月中旬的一个统计,中国区用户只有11%打开了这个功能,而各个地区的启用率也没有呈现明显上升的趋势。

 

不过,不论这个比率如何,移动广告总会受到一些影响,据国内一知名公司宣称,在监测广告的过程当中,IDFA为0的用户占比仅在1%左右。

所以,也许广告圈对此的反应是有点过头了,毕竟如今大多数人并不在乎,或者说没有意识到。若是你们都能善用用户的信息,仅用于正常的商业推广,这个问题不会太严重。但人性老是贪婪的,人类做为一个群体来看,一方面享受着科技的便利,而另外一方面又用科技制造出来更大的问题,等到足够严重的时候再试图用新的科技来解决,是为“科技黑洞”!

剁手后,我静静的限制了广告追踪…

 

 

IDFA 是苹果 iOS 6 开始新增的广告标识符,英文全称是 Identifier for Advertising ,用于给开发者跟踪广告效果用的,能够简单理解为 iPhone 的设备临时身份证,说是临时身份证是由于它容许用户更换,IDFA 存储在用户 iOS 系统上,同一设备上的应用获取到的 IDFA 是相同的。iOS 用户能够经过(设置程序 -> 通用 -> 还原 -> 还原位置与隐私)更换 IDFA,iOS 10 系统开始提供禁止广告跟踪功能,用户勾选这个功能后,应用程序将没法读取到设备的 IDFA。

IDFA 是目前苹果生态广告交易的主要标识,通常跟广告商交易一个用户后广告商须要给你提供用户的 IDFA 做为凭证,主流的广告平台腾讯广点通、新浪粉丝通对帐是基于 IDFA 的。

 

另外,在统计惟一用户的时候,IDFA 的可变性会形成部分用户的重复统计,目前有一些比较好的开源方案,感兴趣能够继续往下看。

---------------------------------------------------------------------------------

认识一下iOS系统的各类设备识别码

一、UDID ,全称是 (Unique Device Identifier),顾名思义,它就是苹果IOS设备的惟一识别码,它由40个字符的字母和数字组成,为了保护用户隐私苹果已经禁止读取这个标识了。

二、UUID,全称是(Universally Unique IDentifier),是基于iOS设备上面某个单个的应用程序,只要用户没有彻底删除应用程序,则这个 UUID 在用户使用该应用程序的时候一直保持不变。若是用户删除了这个应用程序,而后再从新安装,那么这个 UUID 已经发生了改变。UUID 很差的地方就是用户删除了你开发的程序之后,基本上你就不可能获取以前的数据了。

三、MAC 地址,用来定义网络设备的位置。一个主机会有一个 MAC 地址,MAC 地址是网卡决定的,是固定的,为了保护用户隐私苹果已经禁止读取这个标识了。

四、OpenUDID,不是苹果官方的,是一个替代 UDID 的第三发解决方案, 缺点是若是你彻底删除所有带有 OpenUDID SDK 包的 App(好比恢复系统等),那么 OpenUDID 会从新生成,并且和以前的值会不一样,至关于新设备;

五、IDFA 广告标示符,适用于对外:例如广告推广,换量等跨应用的用户追踪等。

六、IDFV,Vindor 标示符 (IDFV-identifierForVendor),来自同一个运营商的应用运行在同一个设备上,此属性的值是相同的;不一样的运营商应用运行在同一个设备上值不一样。

 

关于 openUDID 不能用的说法不正确,至今 openUDID 仍是可用的(iOS7如今没什么用户了),部分广告渠道的点击接口依然支持使用 openUDID 做为用户标识。

 

 

 

 

 

IDFA流程图,

网站流程图,app-webapi-wcf服务-数据库-消息队列

 

 

过程当中遇到的错误日志:

 

System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: The remote server returned an error: (500) Internal Server Error. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:

System.Net.WebException: The remote server returned an error: (500) Internal Server Error.

at System.Net.HttpWebRequest.GetResponse()

at HWQ.WCF.CollectService.HttpWebRequestWrapper.GetResponse()

at d.RefshImageCode()

at RefshImageCode(String taskId)

at SyncInvokeRefshImageCode(Object , Object[] , Object[] )

at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)

at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)

at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)

at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&...).

 

 


System.ServiceModel.FaultException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at HWQ.OtherDataApi.WCFInterface.IWCFAreainfo.GetCityUpdate(DateTime pUpdateTime)
at ***.Call[K](Func`2 callBack)
at **.GetCityUpdate(DateTime pUpdateTime)
at **.city_update(Int64 timestamp)
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()

 

 

 


System.ServiceModel.FaultException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at *.GetHomeActivity(Int32 userid, Int32 activityusertype)
at *.Call[K](Func`2 callBack)
at *.gethomeactivityandbanner(String token, Int32 usertype)

 

 

 

 

 

 


System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Unable to connect to any of the specified MySQL hosts. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts.
at MBT.Data.SqlHelper.DBUtility.ExecuteScalar(String sql, CommandType cmdtype, DbParameter[] parameters)
at MBT.Data.SqlHelper.DBUtility.ExecuteScalar(String sql, DbParameter[] parameters)
at HWQ.IdfaDataApi.WCFService.ChannelService.GetChannelVerificationID(Int32 ChannelId)
at SyncInvokeGetChannelVerificationID(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessa...).

 

 

 

System.Threading.Tasks.TaskCanceledException: A task was canceled. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()

相关文章
相关标签/搜索