开发者

NServiceBus Saga - How to configure millisToSleepBetweenMessages?

I'm new in C# and I'm working in a project where an NServiceBus Saga is being used.

Inside the logic of the saga, the RequestTimeout method is being called for 1 minute if a condition is not achieved.

The problem is that this call consumes too much of the processor and I think this is because the TimeoutManager use the default value of 10 millisenconds to开发者_StackOverflow社区 check if the time is up and send back the time out message to the saga.

Does anybody knows how this millisToSleepBetweenMessages property could by changed?

Thanks in advance! Seba


I gather the TimeoutManager you're currently using is either the 2.0 or 2.5 version. If this is the case, the TimeoutManager endpoint itself has a config file (Timeout.MessageHandlers.dll.config) with an appSetting.

Here's an example:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
  </configSections>

  <MsmqTransportConfig
    InputQueue="timeoutmanager"
    ErrorQueue="error"
    NumberOfWorkerThreads="1"
    MaxRetries="5"
  />

  <appSettings>
    <!-- relevant for a Serialization of "xml" only -->
    <add key="NameSpace" value="http://www.UdiDahan.com"/>

    <!-- can be either "xml", or "binary" -->
    <add key="Serialization" value="xml"/>

    <!-- default is 1000, influences memory use (16 bytes / saga ID) -->
    <add key="MaxSagasIdsToStore" value="10000"/>

    <!-- default is 10, decreasing this value gives better time resolution but higher IO churn -->
    <add key="MillisToSleepBetweenMessages" value="10"/>

  </appSettings>

</configuration>

In this version of the Timeout Manager, you have a choice. You can adjust MillisToSleepBetweenMessages, and that just adjusts the Thread.Sleep() timeout on each message the Timeout Manager processes. With a very small timeout, this does cause a lot of churn as the message is put back on the queue and reprocessed over and over.

You can adjust it to something higher like 1000ms, but keep in mind that you will lose a lot of your time accuracy, especially if there are lots of timeouts going on. If your requirements for ALL use cases going through this timeout manager are for a 1-minute timeout, give or take, then that's fine.

Otherwise, you have a few choices:

  • Take a look at the unreleased NServiceBus 3.0 code, where a much improved TimeoutManager is under development.
  • Take a look at my blog post NServiceBus TimeoutManager Revisited, where I have an implementation of a Timeout Manager that I use in my production scenarios. Keep in mind it isn't designed for multiple sites or multiple time zones or any of those types of issues, but it does solve the issue of being forced to give up on accuracy to reduce churn.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜