Custom SignalR back plane implementation for unique pay load - c#

we are in a situation where millions of connections (approximately 30 million) will be connected to application. (SignalR Hubs)
however 90% of them will be idle and main operation is server push to specific client thus i need to implement a scale out mechanism.
so i came across this fantastic talk on channel 9 by Damian Edwards where he states that current implementations of backplanes for SignalR is very limited and in scenarios like mine a Custom scale out is needed specifically in server push situation. (at 58:29 of above talk)
after spending many hours in web, i could not find any clear guidance on how to implement a custom backplane which suits my need.
i would like to know how signalR back plane internally works and basically how a backplane works in general. so i can implement my own one.
any help, blog post etc.. is highly appreciated.

Please read this piece of documentation, specifically the piece regarding Implementation.
TL;DR -
When a message is sent, it goes to the backplane, and the backplane sends it to every server. When a server gets a message from the backplane, it puts the message in its local cache. The server then delivers messages to clients from its local cache.

Related

WebSockets and Long Polling

I have a chat room application that has been implemented in C# with SignalR WebSockets capabilities and hosted on Azure so it connects using WebSockets. I've also Implemented the same application to use long polling as a transport method.
What I want to do now is find "tests" as to which I can compare the network traffic and latency issues (or any other major differences) on both applications. One suggested evaluation for a comparison is the initial connection of the unnecessary network throughput but not quite sure how to go about that.
Any comments and suggestions would be highly appreciated.
Would a simple latency display be enough ?
An easy way to do this is :
implement a client to server call in which you send a browser-computed Date.now()
make the server immediately call a method in the client, sending back the value unchanged
the client computes the difference Date.now() - receivedDate. You now know the time interval for a back and forth request client->server->client.

How to scale out signalr to a large number of users

I have read a lot on scaling out in signalr and the favourites seem to be those mentioned in :
http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-in-signalr
Namely the following service buses:
- SQL
- Redis
- Azure
The problem is is even stated in the text however:
"Using a backplane, the maximum message throughput is lower than it is when clients talk directly to a single server node. That's because the backplane forwards every message to every node, so the backplane can become a bottleneck."
I am creating...wait for it... YEP! A chat application. And I want to be able to scale it out to MILLIONS of users. Regardless of whether I make it big (ha!) or not, I plan on documenting the step by step process. Now I have most of the app ready, and I am wondering about this scale out issue. I watched this, highly useful video:
http://channel9.msdn.com/Events/Build/2013/3-502
Skip to 55 minutes. "Custom scale-out". And the other ideas such as filtering the message bus.
Now hopefully you're excited and not contemplating suicide over the boredom I am ushering unto you...
My idea is to do as follows:
- per popular rooms give a single server
- each room therefore can easily cope with the traffic and signalr can work nicely broadcasting to the clients and storing the message log to a GROUPS server (ie holds all group messaging per group)
- Then private messaging will need to either use a backplane or server push
- the user connections will therefore need to be updated in a sql server DB (easy enough) and the data posted via ajax rather than signalr
However, I want to explore all options. (Please post any better ideas if you have them) I want to also try testing REDIS for the private messaging. WHY?!! Because what if I want the users to be able to have private messaging groups... and users 1,2 and 3 are all highly annoying and are on servers 1,2 and 3. (Ah you little ...!) For better performance though, I will want to implement a Redis message filter to only send to the servers with the clients on them!
So, what exactly am I looking for? Basically I need resources. I can't find any useful Redis message bus examples (asp.net example has no filter. yes, I can add the AddResolverblabla line! :) )
I also need examples of the following:
- server to server ajax post: I am a server noobie!
- a load balancer example to specify a certain room per chat room (or just some page)
- how many messages can the Redis message bus handle? Will it easily be a bottle neck even with the filter? I cant find any example of performances WITH a filter
Finally I need your brains! ;) If you are sat there thinking there's a better way, please let me know.
Many thanks to all who read this essay, I look forward to your replies. (Please up-vote this if you find it useful! There's a lot of forums with similar questions, but no proper answers)
I plan to start answering this as I find documentation. Hopefully more will join!
1.
How to define a connection string to a SQL Server 2008 database?
2.
SQL Server filter:
http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.messaging.sqlfilter.aspx
3. web farm
http://weblogs.asp.net/scottgu/archive/2010/09/08/introducing-the-microsoft-web-farm-framework.aspx
4. WF tutorials:
http://www.asp.net/web-forms/tutorials/deployment/configuring-server-environments-for-web-deployment/creating-a-server-farm-with-the-web-farm-framework
3/12/2014
A possible better solution is to use memecache - what facebook is based on
still need to find whether you can specify: use signalr or use redis message bus.
still need to find redis filter tutorials
14/03
GlobalHost.DependencyResolver.UseRedis("server", port, "password", "AppName");
Defines the servers to use redis. Need a filter
6/10/2014
After more research on scaling out, a possibleanswer is to not think of servers as a web of communications, but self-contained. The server uses sends to update the DB and using a timer you can get all the required information (messages etc) each loop from the DB for the users CURRENTLY logged in to that server. As such, it will scale out much easier. Not cheaply however.

Mobile server implementations for tournament-style game? Access via REST services/wcf

I'm working on implementing a game server on AppHarbor for a tournament style game. I'm planning on using WCF and C#. I want the server to generate new "levels" every 5 minutes and send it out to all the clients that are online at the time. The clients would then after 3 minutes send back the results of the level (how the player did) and the server will analyze the results and send back the universal results to each client (leaderboards, statistics, etc). And this cycle would repeat.
I'm not sure where I should start. I was looking into making a WCF service application with REST services to get the information, but I don't know who to make the server do calculations and generations independent of the clients.
I would greatly appreciate any help that you all could give me.
Thank you.
You can use SignalR to create independent persistent connections to your clients. At this point SignalR doesn't scale that well as it is only possible to run it on one worker/server out of the box. There is a feature request for scaling but it's not done yet. Depending on how many users you are counting on getting the first months, I would say SignalR is the way to go and then when you need scaling you can improve SignalR to be scaleable as it is open source. :)

Web Chat Application - ASP.NET/Jabber/Ajax/WCF/Comet/ReverseAjax - Issues Faced - Seeking Insights

I've been trying to build a web based chat application for the past three weeks and i'm facing issues with whatever route (programming technique/technology) i take to build it. I've explained the issues i've experienced with all of'em below. Kindly provide whatever insights you have in this.
ASP.NET-AJAX
First issue is that it is Not Really Real Time
If client hits the chat server every x seconds (constant time stamp) it is not going to be real time unless x is very very less
If x is very small like 1 second and if there are 1000 users online at the same time i think it is really going to hammer the chat server and cause scalability/performance issues
WCF-Duplex
I unfortunately wasted considerable amount of time in this trying to build a WCF duplex service which maintains all the clients and invokes the client through the channel as and when required. But i recently learnt that WCF duplex callback wont work with ASP.NET (since http is request and respond type). I was following this great article to build a duplex service.
Comet/ReverseAjax/HTTP Server Push
I'm extremely new to this technique and wonder how well enough it can scale. After my first glance on this programming technique here in wiki and the very first article on Comet by Alex here, i learned that the client always maintains an open connection (long living ajax calls) to the server which can be used by the server to push "interesting events happening in the server" to the browser (client). So how well can it scale? What if the max no of open connections exceed in IIS or any other issues like that?
Jabber Server/Client (XMPP)
I see that most of the prominent chat applications that can be seen online are making use of Jabber. I also learned that writing a Jabber server from the scratch is a tedious task. I have separate user profile store for by application. Can i integrate that with Jabber easily? Any open source Jabber servers that i can host privately? (I've seen many open source tools to build the client easily)
Any insights provided are very much appreciated.
Thank you
NLV
If you are using .NET, check out WebSync. It allows for fully scalable comet using IIS to integrate directly with your application. There is a free Community edition you can try out, along with tons of examples and chat demos.
I just recently implemented a multi-client Jabber web-app using WebSync and jabber-net.
PokeIn provides shared objects among the clients and it simply helps you to create impressively solid and fast web applications. Even if your application is hosted on multiple servers, PokeIn manages the shared objects on all of them. So, this feature will help you to create quite effective solutions. In addition to these, you will find very useful samples over there
I know this is old but if somone new founds this you should consider using SignalR
Open Source Jabber Server
Have you checked out OpenFire

How should server push data to rich client

I'm writing a simple accounting program consists of several C# winform clients and a java server app that read/write data into a database. One of the requirement is that all C# clients should receive updates from the server. For example, if user a create a new invoice from his C# client, other users should see this new invoice from their client.
My experience is mainly on web development and I don't know what's the best way to fulfill this requirement with C#s client and Java servlet server.
My initial though is to run ActiveMQ with Glassfish and use messaging pub/sub method so that updates can be pushed to C# client. I will create different topics like newInvoice, cancelInvoice, etc in order to differentiate the message type. Each message will simply contains the object encoded in JSON.
But it seems to me that this involves quite a lot of work. Given that my user base is very small ( just 3 or 4 concurrent user), it seems to me that there should be some simpler solutions. (I'm not familiar socket programming :) )
I know this is a client-server programming 101 questions but would be great if any experienced programmer can point me to some simple solutions.
The simplest approach here is often to simply use a poll - i.e. have the clients query for data every (your time interval). That avoids a whole family of issues (firewalls, security, line-of-sight, resolution, client-tracking, etc).
With WCF, you can have callbacks on duplex channels (allowing the server to actively send a message to clients), but this is more complex. I value simplicity, so I usually just poll.
Tricks that help here are designing the system to have an inbuilt mechanism for querying "changes since x" - for example, an audit table, perhaps fed by database triggers. The exact details vary per project, of course.
Another option that you might want to look at is ADO.NET Sync Services; this does much of what you ask for, for keeping a local copy of the database up to date with the server - but has a few complexities of its own. This is available (IIRC) in the "Local Database Cache" VS template.
Rather than pushing information from the server to 1:N Clients, would it not be easier to have the clients Poll the server for updates every so often ? Or when the client launches and creates a connection to the server, the server could dynamically generate a new Message Queue for that Client Connection, which the client could then poll for updates?
There are several push technologies available to you, like ActiveMQ (as you mentioned), or XMPP. But if you only have 3 or 4 clients to concern yourself with, polling would be the simplest solution. It doesn't scale well, but that isn't really a concern in your case, unless your server is an 8086 or something 8-)
You may want to take a look at StreamHub Push Server - its a popular Comet server written in Java that has a .NET Client SDK for receiving updates from the server in C#. It also has a Java Client SDK and the usual Ajax/Comet web browser support giving you more flexibility in the future to push data to web, Java and C# clients.

Categories

Resources