ServiceStack如何处理并发调用? [英] How does ServiceStack handle concurrent calls?

查看:144
本文介绍了ServiceStack如何处理并发调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ServiceStack如何处理并发调用?我正在WCF中寻找ConcurrencyMode.Multiple的等效项。

How does ServiceStack handle concurrent calls? I'm looking for equivalent of ConcurrencyMode.Multiple in WCF.

我的WCF服务设置了以下属性:

My WCF services have this attribute set:

   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]

我是否需要在ServiceStack中启用任何功能才能使其在每次调用中使用多个线程?

Do I need to enable anything in ServiceStack to get it to use multiple threads for each call?

推荐答案

ServiceStack的每个AppHost都没有可配置的并发模型,它取决于您选择用来托管ServiceStack服务的AppHost:

ServiceStack doesn't have a configurable concurrency model per AppHost, it is dependent upon the AppHost you choose to host your ServiceStack services with:

对于ASP.NET Web主机,ServiceStack 本身不会创建任何新线程,这些请求只是在同一IIS上处理/ Nginx / etc处理请求的ASP.NET HTTP WebWorker。

For ASP.NET web hosts, ServiceStack doesn't create any new threads itself, the requests are simply handled on the same IIS/Nginx/etc ASP.NET HTTP WebWorker that handles the request.

仅ServiceStack cr在调用 new AppHost()。Start(url)时,会在启动上吃一个新线程。在运行时没有创建新线程,即在HttpListener异步回调线程上处理请求。

ServiceStack only creates a new thread on Startup when you call new AppHost().Start(url). There are no new threads created at run-time, i.e. the request is handled on the HttpListener async callback thread.

这是ServiceStack的另一个自主机HttpListener选项,它使用自己的托管ThreadPool执行请求(释放HttpListener异步回调线程)。 ThreadPool的默认poolSize是 500 个线程,尽管它可以在 AppHostHttpListenerLongRunningBase(poolSize)构造函数中配置。

This is another Self-Host HttpListener option for ServiceStack that uses its own managed ThreadPool to execute the request on (free-ing up the HttpListener async callback thread). The default poolSize of the ThreadPool is 500 threads, though this is configurable in the AppHostHttpListenerLongRunningBase(poolSize) constructor.

管理长时间运行的任务的一个好选择是将请求委托给Redis MQ主机,这是一种轻量级的MQ服务器,允许您在托管后台线程中延迟和处理请求。默认情况下,RedisMqServer为每种消息类型(即请求)生成一个后台线程,尽管它可以在启动时配置,例如:在下面的示例中, 2个后台线程用于处理 PostTwitter 请求,而每个后台线程仅用于处理 CallFacebook EmailMessage 请求:

A good option for managing long-running tasks is to delegate requests to a Redis MQ Host which is a light-weight MQ Server allowing you to defer and process requests in managed background threads. By default the RedisMqServer spawns a single background thread for each Message type (i.e. Request), though this is configurable on start-up, e.g: in the example below 2 background threads are used to handle PostTwitter requests, whilst only 1 background thread each is used to process CallFacebook and EmailMessage requests:

mq.RegisterHandler<PostTwitter>(ServiceController.ExecuteMessage, noOfThreads:2);
mq.RegisterHandler<CallFacebook>(ServiceController.ExecuteMessage);
mq.RegisterHandler<EmailMessage>(ServiceController.ExecuteMessage);

这篇关于ServiceStack如何处理并发调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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