简体   繁体   中英

SignalR hub self-host or not?

I´m working on a project where a SignalR hub starts up 12 short-running threads (new Thread()). Each thread reports to the client on completion using websockets. The threads are not CPU-intensive, instead they get some information from other web-services.

Now my dilemma is this: Should I create a stand-alone self-hosted signalR hub application that is run as a service or should I just include the hub in my asp.net MVC project?

What is best performance wise?

The correct way to do this in .net 4.5 onwards is to do this single threaded asynchronous .

ASP.Net should NEVER be creating new threads . There are huge performance implications when explicitly using threads with ASP.Net.

Also you should know that threads are an abstraction of limited CPU resources (you noted as much by stating that your threads are not CPU intensive). In .net 4.5 onwards, that should tell you that you should NOT be using threads. Instead, in this case you should be using a threadless I/O api to call your webservices. I would advise you use the TAP (aka async await )pattern, which is basically .net 4.5.

This should allow you to scale with a moderately powerful machine to thousands of concurrent request.

If you have all of this in place, using TAP, ASP.Net MVC/IIS will play well with massive parallelization and "threading". In this case I would advise highly against using a windows service , as you will have better stability with IIS as your bootstrapper (handling lifetime, and restarting your service if it dies).

If performance is an issue I would use Thread Pool and not new Thread .

And i will host is a windows service , becuase that would give me more control in term of resources to allocate to the threads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM