性能下降 [英] Performance degradtion

查看:71
本文介绍了性能下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将在webservices中声明的静态变量会降低性能。在UI的每次命中都会发生什么。

解决方案

会发生什么每次点击来自UI


据我所知,静态变量与AppDomain范围相关联。因此,每次AppDomain中的执行代码自创建/加载AppDomain以来第一次引用类时。在ASP.NET网站中,对于给定的Web服务站点,
AppDomain将在第一次请求Web方法时初始化,之后,以下Web方法请求将在同一AppDomain下执行。这意味着Web Service类中定义的静态变量可以跨Web方法请求共享其值





$ b 在webservices中声明的静态变量会降低性能吗?



不会降低性能。静态变量通常是更好的选择,因为它们具有更好的性能(使用静态变量存储和读取值的速度可以高达500倍),因为当你向它们引用
时,它们不需要在集合中查找 - 正如Application对象和Caching所发生的那样。但静态变量风险很小


1. 如果您的ApplicationPool被IIS回收,静态数据将被删除。


2. 不必线程安全[只读静态就好]


3. 静态变量限制部署您的Web服务在单一服务器中,即网络耕作[扩展/负载平衡]不适用于静态数据。


如果这有用,请不要忘记将其标记为答案。


will the static variables declared in webservices degrade the performance.what will happen in each hit from UI.

解决方案

What will happen in each hit from UI

As far I know, Static variables are tied to AppDomain scopes. So, every time an executing code within an AppDomain references a class for the the first time since the AppDomain was created/loaded.So, in ASP.NET web site, for a given Web Service site,the AppDomain would be initialized upon the first request for a web method and, after that, the following web method requests would execute under the same AppDomain. That would mean that static variables defined in a Web Service class could share their values across web method requests.


Static variables declared in webservices degrade the performance ?

No it do not degrade performance. Static variables are often a better choice because of their better performace (storing and reading a value can be up to 500 times faster with static variables), since they don't require a lookup in a collection when you refer to them - as it happens for the Application objects and Caching. But there are few risks with static variables

1. If Your ApplicationPool is recycled by IIS Static data will be erased.

2. Not necessary thread safe [Readonly static is fine]

3. Static variable restrict your web service to be deployed in a single server i.e web farming [Scale out /Load balancing] will not work with static data.

If this is helpful don't forget to mark it as answer.


这篇关于性能下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆