Skip to main content

VM and load balancer, direct server return, availability set and virtual network on Windows Azure

In today post we will talk about how we can configure a load balancer, direct server return, availability set and virtual network when working with virtual machine on Windows Azure.
For virtual machines we cannot talk about load balancer without talking about endpoints. Endpoints give you the possibility to specify the port (endpoint) that can be public accessed. For each endpoint you need to specify the public port, private port and protocol (TCP,UDP). The private and public port can be very useful when you want to redirect specific calls to different ports. If you don’t specify the endpoints for a virtual machine, the machine cannot be accessed from outside (for example when you host a web page and you need to have port 80 open).  
For web and worker roles this load balancer is out of the box support. We could say that it is the same think for virtual machines also, but you need to make some custom configuration. You will need to specify that you will use the load balancer functionality when you create an endpoint. Once you create an endpoint that is load balanced, the only think that you will need is to specify to the second, 3rd … machine from that will be included in the load balancer the endpoint that use a load balancer set (“Add an endpoint to an existing load-balancer set”).
Direct server return is another feature of endpoints. It can be very useful when you have want each machine to response to the client directly, without the load balancer routing. In this way, once a client start to communicate with a machine, the connection will stick with only that virtual machine (stick connections) – useful when you have a DB on machines or you have an in-memory session that is not shared between machines.
Virtual network give you the possibility to create a private network formed from virtual machines from Windows Azure. When you need to share content between machines, this will be the best approach. Even if you have machines that are under the same subscription, you will not be able to access them using their private IP or name. You have almost the same access level from one machine to another as you would have machines under different subscription.
Because of this when you need to communicate between machines that are behind the same DNS name of public IP this will be the best approach. For example you will not be able to access a specific instance that is behind a load balancer to update content or call specific endpoints.
A virtual network can be created very easily from the Network tab. You have a lot of options from custom DNS names for specific machines to custom address spaces. Once a virtual network is created you can very easily create new virtual machines to it.
Remarks: You should take into account that you cannot add an existing virtual machine to a new virtual network. A fix for this problem is to stop and delete the machine without deleting the disk itself and recreate a new machine based on that disk
Not last, let’s talk a little about availability set. This is a pretty interesting setting. When you create two or more machines for the same purpose you don’t want the resources of the machine (memory, processor, and store) to be in the same rack. Why? If the rack will stop working that you will have both machines down and the load balancer will not be able to help you. In this case when you create a availability set you will have the guarantee that the machines under the same availability set will not be under the same rack. This will give you the availability of 99.95% that is offered by SLA.
The feature that I enjoy the most is the load balancer in combination with endpoints. It is a great feature that can help you a lot.


Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…

GET call of REST API that contains '/'-slash character in the value of a parameter

Let’s assume that we have the following scenario: I have a public HTTP endpoint and I need to post some content using GET command. One of the parameters contains special characters like “\” and “/”. If the endpoint is an ApiController than you may have problems if you encode the parameter using the http encoder.
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = baseUrl; Task<HttpResponseMessage> response = httpClient.GetAsync(string.Format("api/foo/{0}", "qwert/qwerqwer"))); response.Wait(); response.Result.EnsureSuccessStatusCode(); } One possible solution would be to encode the query parameter using UrlTokenEncode method of HttpServerUtility class and GetBytes method ofUTF8. In this way you would get the array of bytes of the parameter and encode them as a url token.
The following code show to you how you could write the encode and decode methods.