msmqnservicebus

mqsvc.exe pegs cpu at full usage when deploying nservicebus to production


When I deployed my site that uses nservice to a new production box, it was unusably slow...

After some debugging I discovered that mqsvc.exe was taking up 50% of the CPU usage and the other 50% was being taken up by w3wp.exe

I found this post here: http://geekswithblogs.net/michaelstephenson/archive/2010/05/07/139717.aspx

which recommended the following:

  • Make sure you set the windows service for NserviceBus Generic Host to the right credentials

  • Make sure you have the queue set with the right permissions

  • Make sure you turn on the right logging configuration in NServiceBus

So I figured the issue was something related to permissions, but even after trying to set the permissions correctly (I thought) I still wasn't able to resolve the issue.


Solution

  • If you allow NServiceBus to create its own queues, then it will create them with the correct permissions it needs.

    The problem comes in when you set up a web application, and then the queues are created, and then the identity the application runs under changes. Then you get exactly this problem. NServiceBus tries to check the queue for a message, it does not have access to do so, so it immediately retries over and over, and you spike the processor.

    The fix: Delete the queue. Restart the web application. NServiceBus takes over.

    Edit: As noted in the comments, NServiceBus 3.x doesn't invoke the installers by default, which means queues are not automatically created in production unless you ask it to. See the documentation page on Installers for more detail.

    For a web application (or any other situation where you're not using NServiceBus.Host) you can invoke the installers as part of the fluent config. There is a full example in the NServiceBus download, but here is a link to the relevant file on GitHub.