MaxSimultaneousWorkflows 的替代品是什么?
主要问题:
我使用的是 Workflow Foundation 4.0,其中 WorkflowRuntime
已被 WorkflowApplication
取代,作为单个实例的工作流主机。
我希望控制同时运行的并发工作流实例的数量。在 WF 3.5 及更早版本中,可以在 WorkflowRuntime
使用的 DefaultWorkflowSchedulerService
上设置 MaxSimultaneousWorkflows
属性,这样就可以实现这种限制。如何使用 WF 4.0 执行相同操作?
背景和为什么我要这样做
在我的应用程序中,我想同时安排数百个工作流实例,并且我正在为每个实例创建一个新的 WorkflowApplication 实例,并在 WorkflowApplication 上调用“run”一个循环。
每个 WorkflowApplication 都有自己的 DbContext 实例,用于持久保存和从 SqlServer 读取数据。
当同时运行的 WorkflowApplication 线程数量相当少(比如几十个实例)时,一切都会很好地工作。但是,当我测试安排了数百个工作流实例的应用程序时,我发现 DbContext 使用的 SqlConnection 在等待 ThreadPool 中的线程时超时。
因此,我想将可运行的 WorkflowApplication 实例的最大数量限制为 .Net 默认决定的大约 50%,以便 SqlConnection 和 Asp.Net 的 .NET ThreadPool 中仍保留合理数量的线程(即也在机器上运行在单独的AppDomain中)。
MAIN QUESTION:
I am using Workflow Foundation 4.0 in which the WorkflowRuntime
has been replaced by the WorkflowApplication
as a workflow host for a single instance.
I am looking to control the number of concurrent Workflow instances running simultaneously. In WF 3.5 and earlier, one could set the MaxSimultaneousWorkflows
property on the DefaultWorkflowSchedulerService
used by WorkflowRuntime
and such throttling could be achieved. How can I do the same using WF 4.0?
BACKGROUND AND WHY I WANT TO DO THIS
In my application, I want to schedule hundreds of workflow instances concurrently and I am creating a new instance of WorkflowApplication for each of them and calling "run" on the WorkflowApplication in a loop.
Each WorkflowApplication has its own DbContext instance which it uses for persistence and reading of data from SqlServer.
Everything works great when the number of WorkflowApplication threads running simultaneously is reasonably small amount (say couple of dozen instances). However, when I test the app with hundreds of workflow instances scheduled, I am seeing that the SqlConnection being used by DbContext times out waiting for a thread from the ThreadPool.
Hence, I want to throttle the maximum number of WorkflowApplication instances that can run to about 50% of what .Net decides by default so that a reasonable number of threads are still left in the .NET ThreadPool for SqlConnection and Asp.Net (which is also running on the machine in a separate AppDomain).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论