WCF最佳性能设置 [英] WCF Optimal performance settings

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

问题描述

你好我创建使用WCF的API。我的问题可以分解为两个独立的人

Hi i am creating an API using WCF. My question can be broken down into two seperate ones

1),我有好几个电话,比如我有与该客户的来电,产品,订单,员工。

1) I have quite a few calls, for instance i have calls relating to the customer, products, orders, employees.

我的问题是应这一切去到一个公共接口类例如

My question is should all this go into one public interface class e.g

public interface IRestService
public class RestService : IRestService

或者我应该有一个为每个呼叫例如

Or should I have one for each call e.g

public interface ICustomer
public class Customer : ICustomer

public interface IProducts
public class Products: IProducts

2)如果您有这将数以万计的用户和成千上万的用户并发,你会如何设置,怎样将你的web配置的设置是例如在节流方面进行访问的API。另外你会给什么设置你的 InstanceContextMode ConcurrencyMode 。最后,那会是什么类型的结合,考虑到网站和手机轴承可以访问API。

2) If you have an API which will be accessed by tens of thousands of users and thousands of users concurrently, how would you set up, what will your web config settings be for instance in terms of throttling. Also what setting would you give your InstanceContextMode, or ConcurrencyMode. Finally what type of binding would it be, bearing in mind websites and mobile phones can access the api.

推荐答案

有关好习惯的缘故,我就这么你有他们分裂成在未来单独实现的选项分手API为独立的接口。你仍然可以只设一个服务类实现所有的接口,像这样的:

For the sake of good practice, I would break up the API into separate interfaces so you have the option of splitting them into separate implementations in the future. You can still have just one service class implement all of the interfaces, like this:

public class RestService : ICustomer, IProducts, IOrders

然而,它听起来好像你可能想使他们有不同的实现呢。

However, it sounds as if you'd probably want to make them separate implementations anyway.

在并发设置方面,问问自己需要对每个呼叫使用哪些资源。如果您的服务类的构造函数可以在没有任何冗长的启动编写,然后使用PerCall。如果您需要初始化昂贵的资源,那么我建议你用InstanceContextMode.Single和ConcurrencytMode.Multiple确保您编写线程安全的code。例如:确保您锁定()在任何类属性或其他共享资源在使用之前

In terms of concurrency settings, ask yourself what resources need to be used on each call. If your service class's constructor can be written without any lengthy startup, then use PerCall. If you need to initialize expensive resources, then I'd recommend InstanceContextMode.Single with ConcurrencytMode.Multiple and make sure you write thread-safe code. Eg: make sure you lock() on any class properties or other shared resources before you use them.

数据库连接会的的计数为昂贵的初始化,但是,因为ADO会做连接池,为您和消除这种开销。

Database connections would not count as "expensive to initialize", though, because ADO will do connection pooling for you and eliminate that overhead.

您限制设置将通过测试来发现,因为拉吉斯拉夫提到。你想强调,测试服务,并使用结果来获取你需要多少台机器服务您的预期负载的想法。然后,你需要一个专门的负载均衡器将请求路由作为或者循环,或者一些检查每个服务器的健康状况。负载均衡器可以设置以获得systemhealth.asp页面,并检查结果。如果返回OK,那么这台机器停留在游泳池,或者可以从池中暂时删除,如果超时或返回任何其他状态。

Your throttling settings will be revealed by testing, as Ladislav mentions. You'd want to stress-test your service and use the results to get an idea of how many machines you'd need to service your anticipated load. Then you'll need a dedicated load balancer to route requests as either round-robin, or something that checks the health of each server. Load balancers can be set up to GET a "systemhealth.asp" page and check the results. If you return an "OK" then that machine stays in the pool, or can be temporarily removed from the pool if it times out or returns any other status.

您绑定将需要的WebHttpBinding休息。 basicHttpBinding的是为SOAP接口,并且不支持[WebGet],例如

Your binding would need to be WebHTTPBinding for REST. BasicHTTPBinding is meant for SOAP interfaces and doesn't support [WebGet], for example.

如果它没有成为一个REST服务,那么你可以通过使用NetTcpBinding的获得更多的性能。

If it doesn't have to be a REST service, then you can get a bit more performance by using NetTcpBinding.

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

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