Showing posts with label signalr. Show all posts
Showing posts with label signalr. Show all posts

Wednesday, January 1, 2014

SignalR Performance and Scalability



ASP.NET Core SignalR is a library by Microsoft (now opensource) which allows server to communicate with client side web apps asynchronously. Performance and scalabality is a major consideration developers needs to consider when developing applications.

Performance tips

Reduce SignalR message size
You can reduce this by reducing size of your serialized objects. In Server, if you're sending an object that contains properties that don't need to be transmitted to client, use JsonIgnore attribute to make them not pass through. 

You can also reduce property name sizes using JsonProperty attribute. To make things readable in client side you can remap them to a meaningful name. 

Since messages are stored in the message bus in server memory, reducing the size of messages can also address server memory issues.

SignalR 
DefaultMessageBufferSize : By default SignalR keeps 1000 messages in memory per hub per connection. If large messages are transferred, this can create memory issues. This setting can be set in Application_Start event. Reducing this make server utilize memory in a better way (If using large messages)

IIS Settings
Max concurrent requests per application: Increasing the number of concurrent IIS requests will increase server resources available for serving requests.

ApplicationPool QueueLength: This is the maximum number of requests that Http.sys queues for the application pool. When the queue is full, new requests receive a 503 “Service Unavailable” response. The default value is 1000.

Shortening the queue length for the worker process in the application pool hosting your application will conserve memory resources.

Troubleshooting tips

You can use SignalR performance counter to measure no. of events since last application pool or server restart.

To measure performance, SignalR team uses Crank.

Scalability
You can scale up (larger server) or scale out (multiple servers). When scaling out since we have multiple servers one server might not be up to date with messages recieved by the other server. Therefore you need to use a backplane.

http://www.asp.net/signalr/overview/getting-started/real-time-web-applications-with-signalr This article also includes how to create BackPlane using SQL Server

Resources

Saturday, July 27, 2013

How SignalR Works

SignalR is a library which can add realtime web functionality to applications. It provides a simple API for creating server to client RPC, that call JavaScript functions from server side .NET code.SignalR handles connection management automatically. It also has a API for this.

SignalR is an abstraction over a connection. It gives you 2 programming models over the connection (Hub and Persistent Connection). 

SignalR applications can scale out to thousands of clients using Service BUS, SQL Server or Redis. 

Supported transports by SignalR

SignalR connection starts as HTTP, and is then promoted to WebSocket connection if it is available. If WebSocket is not available it falls back to older transports.

HTML5 Transports
  • WebSocket
This is the ideal technology for SignalR because it uses server memory efficiently. It has the lowest latency and full duplex communication between client and server. But WebSocket requires Windows Server 2012 or Windows 8 and .NET framework 4.5. 

Basically to use WebSocket both client and server should support WebSocket.
  • Server Sent Events
Also known as EventSource. Does not support in IE. :-(

Comet Transports
Here browser or other client maintains a long-held HTTP request, which server can use to push data to client without client specifically requesting it. 
  • Forever Frame
For IE only. Creates a hidden IFrame which makes a request to an endpoint on server which does not complete. 

The server then continually sends script to the client which immediately executed, which provides one way real time connection from server to client. The connections server to client and client to server uses separate connections. A new connection is created for each piece of data that needs to be sent.
  • Ajax Long Polling
Does not create a persistent connection, instead polls the server with a request that stays open until the server responds, at which time the connection closes. and a new connection is established(requested) automatically. This may introduce some latency when connection gets resets. 


You can enable logging for hub's events in a browser using $.connection.hub.logging = true; command. 

If the client capabilities are known, transport can be specified when client connection is started using connection.start({ transport: 'longPolling' }); command. you can also specify fallback order like connection.start({ transport: ['webSockets','longPolling'] });

Connections and Hubs

SignalR has PersistentConnection and Hub connections. Persistent connection API provides direct access to low level communication protocols. A Hub is a more high level pipeline built on top of Connection API. 

Using Hubs also allows you to pass strongly typed parameters to methods, enabling model binding.

Self Hosting SignalR applications
Hosting SignalR is not restricted to IIS. Using SignalR Self Host library which is built on OWIN you can host SignalR on Console applications and Windows services. Check this article.

In the ASP.NET SignalR space there are lot of articles you can look into.


Here we limit client and server to a limited no. of times to be communicated (e.g: 25 times per second)




Resources:

Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook