简体   繁体   中英

Web role scaling in windows azure

I have implemented a websocket server as part of WebRole.cs and so far it works, users can connect to the server using the website's URL and the specified endpoint. Now let's say I have 50,000 users who want to connect to the websocket server, I will require more instances of that web role to handle the load.

My question is, if there are multiple web role instances, does this result in multiple web socket servers as well? ie Will users still connect using just a single URL/IP and all be connected to each other (eg when broadcasting a message), or will users need to enter a different IP to connect to different websocket servers (one for each instance) and only be connected to users on the same server/instance?

EDIT: Specific problem

So if on connect a user gets added to:

private static List<UserContext> Users = new List<UserContext>();

In WebRole.cs. And I have a broadcast method:

private static void Broadcast(String message)
        {
            foreach (UserContext uc in Users)
            {
                uc.Send(message);
                Console.WriteLine("Broadcasting to: " + Users.IndexOf(uc));
            }
        }

Will the message be broadcast to all users on the website, or will each instance have its own list of users and therefore only broadcast to users connected to a particular instance?

While Simon is right about the fact that the load balancer will handle all requests (you don't need to worry about which instance you'll need to connect to), there are other things that you'll need to take into account. From your question I understand that you want to broadcast messages for example.

Let's assume you scaled your application to 2 instances:

  • Instance 1
  • Instance 2

The load balancer will take care that all requests to yourapp.cloudapp.net go to one of these instances (round robin). Now let's say users A, B and C are routed to Instance 1 and users D, E and F to Instance 2:

  • Instance 1: user A, user B, user C
  • Instance 2: user D, user E, user F

So let's assume user A does something in your application and you want to broadcast this to all your users. Instance 1 will only see 2 other connected users: user B and C and will send the message to those users. The issue here is that you also want to send the message to user D, E and F, even though these are on a different instance.

That's why your WebSocket/broadcast/... framework (like SignalR) will need to use something like a service bus which is accessible from all instances. Take a look at how SignalR solves this issue by using Windows Azure Service Bus or redis .

The website URL that you are connecting to is actually the URL of the load balancer, not the specific instance (same with the public IP, which is a virtual IP in the load balancer). As you add more instances, the load balancer will direct the traffic to the underlying instances (via round-robin). You should never have to worry about anything other than the public URL and IP address (the exception is virtual networks, where the load balancer is not used).

Alchemy UserContext has Endpoint ClientAddress. A single server will only have the source addresses for users that are connect to it, not the other server. You would have to broadcast from both servers. So if you broadcast() on all servers, you will catch all users. Be careful though of duplicates. A single user will probably exist on multiple servers as the NLB doesn't do sticky sessions. Make sure that your client code can handle the same message from multiple servers

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