Why NServiceBus performance is affected by SignalR connection - signalr

I had a web service which has been using NServiceBus message handling between controller and domain logic. For a new functionality, I have to implement signalR webRT communication between clients and server. But there are some performance problems. I thought that, the problems occur from my design defect but I couldn't detect reason of the problem, yet.
Before SignalR integration, my web service was responsing in 20-30ms. But when a signalR client (only one client is enough) is connected to my web service, the responce time becomes to around 10000ms. When I remove NServiceBus implementation between my controller and domainlogic (directly operate my logic in controller and return) the responce time again down to reasonable value (around 20-30ms).
My web service is a .net core project. And I'm using long-pool threading mechanism for signalR.

Related

SignalR unavailable reasons

I'm developing a real time application using SignalR. Where SigalR will be hosted in an ASP.NET (VB.NET v.2010)
I have the following questions regarding SignalR availability:
What are the cases on which a client could not connect to the signalR?
Is SignalR is trusted to support Real Time Applications?
To have a static (shared) array in the hub, will it affect the performance if the array is too big?
Since the user of the client app will connect to the ASP.NET app via web-service, then is there a cases where the client app can consume the web-service and can not connect to the SignalR?
Can SignalR keep alive for long time, since my app will be working 24/7?ยด
What are the cases on which a client could not connect to the signalR?
Network failure will do it. SignalR will attempt to reconnect due to a transient failure. Or your app being down. :-)
Is SignalR is trusted to support Real Time Applications?
Yep. I'm currently working on an app that has around 3K continuously active users and we never have any widespread connectivity problems. In fact, I don't even recall seeing a support ticket related to SignalR connectivity.
To have a static (shared) array in the hub, will it affect the performance if the array is too big?
Well, pursuant to available memory, you should be fine. Be careful with threading. If you are locking to access an array that is frequently updated, watch out for lock contention.
Since the user of the client app will connect to the ASP.NET app via web-service, then is there a cases where the client app can consume the web-service and can not connect to the SignalR?
I can't envision a scenario. A proper SignalR implementation would be available if network connectivity is available.
Can SignalR keep alive for long time, since my app will be working
24/7?
Yep. SignalR will attempt to reconnect due to transient network interruptions. You can also handle events on the client for disconnect to attempt to reconnect after SignalR gives up.

using Message oriented middleware for communications within single web application realm

I wanted to check the viability of the design approach to use Message Oriented middle-ware (MOM) technology like JMS or ActiveMQ or RabbitMQ for handling asynchronous processing within single web application i.e. the publisher and the subscriber to the MOM server will be contained in the same web application.
The rationale behind this design is to offload some of the heavy duty processing functionality as a background asynchronous operation. The publisher in this case is the server side real-time web service method which need to respond back instantaneously (< than 1 sec) to the calling web service client and the publisher emits the message on MOM Topic. The subscriber is contained in the same web application as the publisher and the subscriber uses the message to asynchronously processes the complex slightly more time consuming (5-7 seconds) functionality.
With this design we can avoid having to spawn new threads within the application server container for handling the heavy duty complex processing functionality.
Does using MOM server in this case an overkill where the message publisher and message subscriber are contained in the same web server address space? From what I have read MOM tech is used mainly for inter-application communication and wanted to check if it is fine to use MOM for intra-application communication.
Let know your thoughts.
Thanks,
Perhaps you will not think it is a good example but in the JEE world using JMS for intra-application communication is quite common. Spawning new threads is considered a bad practive and message-driven beans make consuming messages relatively easy and you get transaction support. A compliant application server like GlassFish has JMS on board so production and consumption of messages does not involve socket communication as will be the case with a standalone ActiveMQ. But there might be reasons to have a standalone JMS, e.g. if there is a cluster of consumers and you want the active instances to take over work from the failed ones... but then the standalone JMS server becomes the single point of failure and now you want a cluster of them and so on.
One significant feature of JMS is (optional) message persistence. You may be concerned that the long-running task fails for some reason and the client's request will be lost. But persistent messages are much more expensive as they cause disk IO.
From what you've described I can tell that of the usual features of MOM (asynchronous processing, guaranteed delivery, order of messages) you only need asynchronous processing. So if guarantees are not important I would use some kind of a thread pool.

ways of making a communication between a webserver to a windows application in .NET

I need to find the most efficient way to communicate from an asp.net web server and a windows C++ application. The windows application does not have any permission to access the database of the asp.net web server.
When the user presses a button, that action with some bytes should be received by the C++ application.
In return, after processing the data on the C++ application, it will send back the result to the web server.
The only way I can think of at the moment is as following:
The asp.net web server will have two web service methods:
the C++ application will call that web service for a method for an interval. if there is a change, then the C++ application will process.
after the C++ application finished its process, it will call a method on that web service to inform about the result.
Any other ways to solve this kind of communication?
Thanks in advance.
If the C++ Application is also on Windows, named pipes would be a good solution. They can be configured to be durable so they can queue messages if either side is not ready to receive the message and they are quite easy to use. They basically look like files that you can read or write from and the data appears on the other side of the "pipe".
Take a look at the documentation (C++) here: http://msdn.microsoft.com/en-us/library/aa365781(v=VS.85).aspx
On the ASP.NET side you would use .NET API's. Here's a nice example to get you started: http://msdn.microsoft.com/en-us/library/bb546085.aspx (This example includes both client and server code.)
Named pipes would be a great solution if the C++ application is located in the same physical server as the ASP.NET application. In that case the OS would be just moving memory between processes for you so it could be very quick.
Additionally, I would configure the C++ Application as a Windows Service so it's always available and can be restarted when the server it's running on is restarted. If keeping it running is very important you could integrate Performance Counters and then have your ops team monitor the counters to make sure it is operating within expected thresholds.
The C++ application can also make a simple GET or POST request with enough information that the webserver can handle in case you don't want to expose a webservice.
You could use network sockets. It's been a long time since I have done anything with them so I can't be much help. Research Winsock (aka Windows Sockets API).
You could use WCF services and connect to them using your C++ client. You will have to research consuming WCF services from C++ client.
As #parapura suggested you could use simple HTTPRequest get & post methods. You could create your own http handler for these request to customize the response.
As you suggested you could use simple web services.

How to use ServiceStack Redis in a web application to take advantage of pub / sub paradigm

I am interested in the Pub/Sub paradigm in order to provide a notifications system (ie : like Facebook), especially in a web application which has publishers (in several web applications on the same web server IIS) and one or more subscribers, in charge to display on the web the notifications for the front user.
I found out Redis, it seems to be a great server which provides interesting features : Caching (like Memcached) , Pub/Sub, queue.
Unfortunately, I didn't find any examples in a web context (ASP.NET, with Ajax/jQuery), except WebSockets and NodeJS but I don't want to use those ones (too early). I guess I need a process (subscriber) which receives messages from the publishers but I don't see how to do that in a web application (pub/sub works fine with unit tests).
EDIT : we currently use .NET (ASP.NET Forms) and try out ServiceStack.Redis library (http://www.servicestack.net/)
Actually Redis Pub/Sub handles this scenario quite well, as Redis is an async non-blocking server it can hold many connections cheaply and it scales well.
Salvatore (aka Mr Redis :) describes the O(1) time complexity of Publish and Subscribe operations:
You can consider the work of
subscribing/unsubscribing as a
constant time operation, O(1) for both
subscribing and unsubscribing
(actually PSUBSCRIBE does more work
than this if you are subscribed
already to many patterns with the
same client).
...
About memory, it is similar or smaller
than the one used by a key, so you
should not have problems to subscribe
to millions of channels even in a
small server.
So Redis is more than capable and designed for this scenario, but the problem as Tom pointed out in order to maintain a persistent connection users will need long-running connections (aka http-push / long-poll) and each active user will take its own thread. Holding a thread isn't great for scalability and technologically you would be better off using a non-blocking http server like Manos de Mono or node.js which are both async and non-blocking and can handle this scenario. Note: WebSockets is more efficient for real-time notifications over HTTP, so ideally you would use that if the users browser supports it and fallback to regular HTTP if they don't (or fallback to use Flash for WebSockets on the client).
So it's not the Redis or its Pub/Sub that doesn't scale here, it's the number of concurrent connections that a threaded HTTP server like IIS or Apache that is the limit, with that said you can still support a fair amount of concurrent users with IIS (this post suggests 3000) and since IIS is the bottleneck and not Redis you can easily just add an extra IIS server into the mix and distribute the load.
For this application, I would strongly suggest using SignalR, which is a .Net framework that enables real-time push to connected clients.
Redis publish/subscribe is not designed for this scenario - it requires a persistent connection to redis, which you have if you are writing a worker process but not when you are working with stateless web requests.
A publish/subscribe system that works for end users over http takes a little more work, but not too much - the simplest approach is to use a sorted set for each channel and record the time a user last got notifications. You could also do it with a list recording subscribers for each channel and write to the inbox list of each of those users whenever a notification is added.
With either of those methods a user can retrieve their new notifications very quickly. It will be a form of polling rather than true push notifications, but you aren't really going to get away from that due to the nature of http.
Technically you could use redis pub/sub with long-running http connections, but if every user needs their own thread with active redis and http connections, scalability won't be very good.

Webservices vs WCF

I am working on an asp.net application (.net 4 framework) design and was wanting to know what are the pros and cons and best practices for using webservices vs WCF techology? This application will eventually be used by outside clients to consume data.
When would you use WebServices and when would you use WCF?
Is one more scalable than the other?
I would use WCF because it can do everything webservices (asmx) does; while giving you the flexibility to extend much further.
You can setup a simple WCF Service just as easily as an ASMX service through Visual Studio. So if you're "Fresh" on both technologies, I'd spend time learning WCF.
Depending on your specific use-case, you might might also look into WCF Data Services (.NET4) and Entity Framework. It basically gives you a nice API that you can use to consume your database over http/https. The beauty of WCF Data Services, is that you end up writing very little code to get at your data, and you can focus on consuming it.
WCF Getting Started -- http://msdn.microsoft.com/en-us/library/ms734712.aspx
WCF Data Services -- http://msdn.microsoft.com/en-us/data/ee720180.aspx
Webservice?
Webservice use SOAP (Simple Object Access protocol) and it is used to
connect the web application using different type of technologies, and
possible to connect the application that have hosted in different type
of servers.
Disadvantage of Webservice
Webservice use only HTTP Protocol. It provides only singlex
communication, not half duplex and full duplex communication. They
work in an stateless fasion over HTTP and are hosted inside a web
server like IIS
Advantages of WCF Service
WCF Service support HTTP, TCP, IPC, and even Message Queues for
communication. We can consume Web Services using server side scripts
(ASP.NET), JavaScript Object Notations (JSON), and even REST
(Representational State Transfer). It can be configured to have
singlex, request-response, or even full duplex communication. These
can be hosted in many ways inside IIS, inside a Windows service, or
even self hosted.
Half duplex
Half-duplex data transmission means that data can be transmitted in
both directions on a signal carrier, but not at the same time.
half-duplex transmission implies a bidirectional line (one that can
carry data in both directions).
They work in an stateless fashion over HTTP and are hosted inside a web server like IIS
Full duplex
Full-duplex data transmission means that data can be transmitted in
both directions on a signal carrier at the same time. Full-duplex
transmission necessarily implies a bidirectional line (one that can
move data in both directions).

Resources