- 性能和可扩展性(Performance and Scalability)
- 可靠性(Reliability)
- 可用性(Availability)
- 可管理性(Manageability)
1. 性能和可扩展性(Performance and Scalability)
-
部署与基础架构 Deployment and Infrastructure
-
合理的使用分布式架构,只在必要时才引入分布式
Use distributed architectures appropriately. Do not introduce distribution unnecessarily. -
谨慎地选择合适的分布式通讯的机制
Carefully select appropriate distributed communication mechanisms. -
把频繁交互的组件都尽可能的放在相同的边界内,或者尽可能的靠近(就近原则)
Locate components that interact frequently within the same boundary or as close to each other as possible. -
在设计中,把基础架构的限制考虑在内
Take infrastructure restrictions into account in your design. -
考虑网络带宽限制
Consider network bandwidth restrictions. -
明确资源限制
Identify resource restrictions. -
确保你的设计不会制约纵向扩展
Ensure your design does not prevent you from scaling up. -
使用支持横向扩展和逻辑分层的设计,避免无意中引入的依附关系,使能够支持负载均衡
Ensure your design does not prevent you from scaling out and it uses logical layers, does not unwittingly introduce affinity, and supports load balancing.
-
-
耦合和内聚 Coupling and Cohesion
-
确保你的设计是松散耦合的
Ensure your design is loosely coupled. -
在你的设计中体现适度的内聚,将相关的实体如类和方法分组
Exhibit appropriate degrees of cohesion in your design and group together logically related entities, such as classes and methods. -
有限制的使用后期绑定(如反射等),只在必要时适当地使用后期绑定
Restrict use of late binding and only use late binding where it is necessary and appropriate.
-
-
通讯 Communication
-
避免接口过度会话(即避免太小粒度的通讯接口)
Interfaces do not enforce chatty communication. -
确保你的应用程序只在必要的地方进行远程调用;通过客户端验证、客户端缓存以及批量作业最小化影响
Ensure your application only makes remote calls where necessary. Impact is minimized by client-side validation, client-side caching, and batching of work. -
优化远程数据交换(例如数据压缩,序列化等)
Optimize remote data exchange. -
选择适当的通讯加密机制
Choose appropriate secure communication mechanisms. -
使用消息队列解耦你系统的各个组件
Use message queues to decouple component parts of your system. -
使用消息队列,“射后不理”方式(fire-and forget)以及异步方法调用等,降低Long-running调用的影响
Mitigate the impact of long-running calls by using message queues, "fire-and forget" approaches, and asynchronous method calls. -
在应用程序域更合适的情况下不要使用进程
Do not use processes where application domains are more appropriate.
-
-
并发 Concurrency
-
不要在你的程序里为每一次请求创建线程,使用CLR提供的和Win32提供的线程池代替
In your application do not create threads on a per-request basis, and use the common language runtime (CLR) thread pool and Win32 thread pool instead. -
只把那些必须线程安全处理的类型置为线程安全
Only types that need to be thread-safe are made thread-safe. -
谨慎考虑锁的粒度
Carefully consider lock granularity. -
确保你的程序获取资源和锁尽可能的迟,释放他们尽可能的早,从而减少冲突可能
Ensure your application acquires shared resources and locks late and releases them early to reduce contention. -
选择恰当的同步基元
Choose appropriate synchronization primitives. -
选择一个恰当的事务隔离级别
Choose an appropriate transaction isolation level. -
确保让异步执行I/O密集任务,但对于CPU密集任务则就无需异步执行
Ensure your application uses asynchronous execution for I/O bound tasks and not for CPU bound tasks.
-
-
资源管理 Resource Management
- 确保你的设计支持并高效的利用各种“池技术”
Ensure your design supports and makes effective use of pooling. - 确保你的程序对资源的获取和释放遵循尽量晚获取,即早释放
Ensure your application acquires resources late and releases them early. -
缓存 Caching
-
对那些代价大的数据(如数据获取,复杂运算以及呈现)使用缓存
Use caching for data that is expensive to retrieve, compute, and render. -
缓存适当的数据,如静态页面,输出数据的某些特定项,存储过程的参数以及查询结果等
Cache appropriate data such as relatively static Web pages, specific items of output data, stored procedure parameters, and query results. -
不要对那些不稳定的数据使用缓存
Do not use caching for data that is too volatile. -
选择一个合理的缓存位置
Select an appropriate cache location. -
选择一个合理的缓存过期策略
Select an appropriate cache expiration policy. -
状态管理 State Management
-
你的设计应该尽可能的使用无状态的组件,除非你已经认真考虑对于可扩展性的负面影响后才决定使用状态化组件
Your design favors stateless components. Or, you considered the negative impact on scalability if you decided to use stateful components. -
如果使用.NET Remoting并且需要支持负载均衡,你需要使用Single Call的服务器端激活模式(SAO)
If you use Microsoft® .NET Framework remoting and need to support load balancing, you use single call server-activated objects (SAO). - 如果你使用WebServices, 你也需要使用一种基于消息的无状态模式
If you use Web services, you also use a message-based stateless programming model. - 如果你使用Enterprise Services, 也需要使用无状态的组件使其能够放入对象池中
If you use Enterprise Services, also use stateless components to facilitate object pooling. - 那些需要被放到状态存储中的的对象必须可序列化
Objects that you want to store in state stores support serialization. - 考虑ViewState对性能的影响
Consider the performance impact of view state. - 根据Session的并发量以及每用户使用的Session数据量来选择一个合适的Session状态存储模式
Use statistics relating to the number of concurrent sessions and average session data per user to help choose an appropriate session state store. -
数据结构与算法 Data Structure and Algorithms
- 确保你的设计使用了合适的数据结构
Ensure your design uses appropriate data structures. - 只要在万不得已的情况下使用自定义集合
Use custom collections only where absolutely necessary. - 如果你需要实现自己的集合请实现IEnumerable接口
Extend the IEnumerable interface for your custom collections. -
数据访问 Data Access
- 在各层之间传递数据时使用最合适的数据格式,认真的考虑性能影响
Pass data across the layers by using the most appropriate data format. Carefully consider the performance implications. - 通过Paremters(参数集合,.NET调用SQL的API)的形式调用参数过程进行数据访问
Use stored procedures with the Parameters collection for data access. - 只处理和传递那些你真正需要的数据
Only process the data that is required. - 为那些大数据量的查询结果集提供合适的数据分页解决方案
Where appropriate, provide data paging solutions for large result sets. - 对那些涉及多个资源管理器的事务,在事务上下文需要跨越多个部件时,可以采用企业服务的声明式事务来处理Use Enterprise Services declarative transactions for transactions that span multiple resource managers or where you need to flow transaction context across components.
- 如果你要控制二进制大对象(BLOBs),使用恰当的chunking技术,不要重复的移动相同的BLOB
If you manipulate binary large objects (BLOBs), use appropriate chunking techniques, and do not repeatedly move the same BLOB. - 把重复的数据访问代码集中放入Helper类中
Consolidate repeated data access code into helper classes. -
异常处理 Exception Handling
- 不要使用异常去控制正常的程序逻辑流程
Do not use exceptions to control regular application flow. - 使用明确的异常处理边界(防止异常信息扩散)
Use well-defined exception handling boundaries. - 结构化的异常处理是更好的错误处理机制,不要使用错误代码来反馈
Structured exception handling is the preferred error handling mechanism. Do not rely on error codes. - 只为特定的原因,并在真的需要捕捉的时候去捕捉异常
Only catch exceptions for a specific reason and when it is required. -
类设计的考虑 Class Design Considerations
- 类拥有它们操作的数据
Classes own the data that they act upon. - 只在必要时使用显性接口. 当你有一些公有的功能穿插于多个类时,使用显性接口实现多态以及版本化
Do not use explicit interfaces unnecessarily. Use explicit interfaces for versioning and for polymorphism where you have common functionality across multiple classes. - 除非真的需要,否则不要类里包含虚方法
Classes do not contain virtual methods when they are not needed. - 使用重载方法比使用可变参数方法更好
Prefer overloaded methods to methods that take variable parameters.
2. 可靠性 (Reliability)
-
设计方面 Designing for Reliability
-
参照Windows Server 2003的应用程序开发规范
Follow the Application Specification for Microsoft Windows Server 2003 http://www.microsoft.com/windowsserver2003/partners/isvs/appspec.mspx -
把可靠性需求列入开发规范
Put Reliability requirements into the specification. -
良好的基础架构的使用
Use of good architectural infrastructure -
把管理信息也放入应用程序中
Built Management Information into the application -
使用冗余提高可靠性
Use Redundancy for Reliability -
使用内置的应用程序健康状态检查
Use Built-In Application health checks -
使用可靠的错误处理
Use Consistent Error Handling -
测试方面 Testing for Reliability
-
使用组件压力测试
Use Component Stress Testing -
使用集成压力测试
Use Integration Stress Testing -
使用实际环境测试
Use Real-World Testing -
使用随机破坏测试
Use Random Destruction Testing
3. 可用性 (Availability)
-
设计方面 Designing for Availability
-
通过使用群集减少计划外的宕机时间
Reduce Unplanned Downtime with Clustering -
使用网络负载均衡
Use Network Load Balancing -
使用RAID磁盘阵列进行数据存储
Use Raid for Data Stores -
减少计划内的宕机时间
Reduce Planned Downtime -
隔离危险应用
Isolate Mission Critical Applications -
使用队列
Use Queuing -
使用分布式文件系统(DFS)
Use Distributed Files System (DFS) -
测试方面 Testing for Availability
-
变更控制过程测试
Test the Change Control Process -
灾难性故障测试
Test Catastrophic Failure -
测试故障转移技术
Test the Failover Technologies -
测试监控技术
Test the Monitoring Technology -
测试Help Desk过程
Test the Help Desk Procedures -
资源冲突测试
Test for Resource Conflicts
4. 可管理性 (Manageability)
-
设计方面 Designing for Manageability
-
在应用程序中使用企业库的Logging框架以提高可管理性
Use Enterprise Library Logging Framework in Application to support Manageability -
使用WMI
Use Windows Management Instrumentation -
使用SMS服务器
Use Systems Management Server -
使用性能监视
Use Performance Monitor -
使用系统准备工具 (Sysprep. Exe)
Use System Preparation Tool -
使用SNMP网络监控协议
Uses SNMP -
使用HTTP监控工具
Use HTTP Monitoring Tool -
使用MS Web兼容性分析工具
Use MS Web Capacity Analysis Tool -
测试方面 Testing for Manageability
-
测试WMI
Test WMI -
测试群集配置
Test Cluster Configuration -
测试网络负载均衡
Test Network load Balancing -
测试应用程序同步
Test Application Synchronization