Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 693
Dimo Avatar asked Oct 20 '22 08:10

Dimo


1 Answers

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).

like image 99
Aron Avatar answered Oct 23 '22 01:10

Aron