Explain how to simply build high availability service cluster under. net core

Time:2019-10-13

When it comes to cluster services, it is believed that for ordinary developers, complex things must come to mind, such as zeekeeper, reverse proxy service gateway and a series of construction and configuration, etc. In general, a team with certain experience and planning is needed to apply them. In this article, you can see another cluster building scheme under. net core, which is very convenient to build highly available cluster services through Beetlex.

Sketch

Beetlex’s Web API cluster application does not rely on third-party services, but is completed by Beetlex itself; it mainly achieves clustered service load access through the combination of Client and policy monitoring services. Here is the service structure:

Once the client acquires the cluster policy from the configuration center, it will do the load processing separately from the configuration center; in the process of running, it will get the update policy from the configuration center regularly, even if the configuration center is not available, it will not affect the overall service processing. The following is the policy management of the configuration center:

Different URLs can be loaded with different weight configurations through the management center. By default, one can be configured.*To handle all loads; when reaching a certain scale, policies can be configured according to certain URL rules. In addition to configuring policies, the center also provides service resource monitoring, which makes weight adjustment more convenient.

application

Next, a simple example is given to illustrate how to build highly available web API cluster services through Beetlex.

Create A. net core console project

QuoteBeetlex.FastHttpApi

Write a simpleHelloWorldWebapi services


 class Program
  {
    private static BeetleX.FastHttpApi.HttpApiServer mApiServer;

    static void Main(string[] args)
    {
      mApiServer = new BeetleX.FastHttpApi.HttpApiServer();
      mApiServer.Debug();
      mApiServer.Register(typeof(Program).Assembly);
      mApiServer.Open();
      Console.Write(mApiServer.BaseServer);
      Console.Read();
    }
  }
  [Controller]
  public class Home
  {
    /// <summary>
    /// Hello Word
    /// </summary>
    /// <param name="name">string: you name</param>
    /// <returns>string</returns>
    [Get(Route = "{name}")]
    [DefaultJsonResultFilter]
    public object Hello(string name)
    {
      return new { Hello = "hello " + name, Time = DateTime.Now };
    }
  }

Visit the browser after running

Create Client calls

It’s also about building a console program and then referencing itBeetleX.FastHttpApiDefine access interfaces


  public interface IDataService
  {
    [Get(Route = "hello/{name}")]
    string Hello(string name);
  }

Create call interface proxy

HttpClusterApi = new BeetleX.FastHttpApi.Clients.HttpClusterApi();
DataService = HttpClusterApi.Create<IDataService>();
Await HttpCluster Api. LoadNodeSource ("default", "http://localhost:8080"); and //load default nodes in configuration services

Calling service


var result = DataService.Hello("henry");

Cluster Center Configuration

Such a clustered service will be completed. Some people may ask that this is clearly a single service. How can it be a highly available service cluster? Next, we do a series of pressure testing and seamlessly add services through the configuration center to deal with the processing of testing.

Configuration load

High-availability cluster is our goal, but it is impossible to have such demand in practice at once, often the demand for cluster services will slowly emerge at the random growth of business; Next, we will conduct a stress test on the single service above, open 40 threads for stress test, because deployment service is only two cores, so we will overwhelm resources at once. Now.

Next, a new node service is needed to support concurrent processing. At this time, only a new service is needed to deploy and add nodes in the configuration center.

With the addition of new services, concurrency changes from 1W to 3W, and this adjustment does not need to adjust any procedures at all! Because the resources of the two servers are very tight, so add another service to cope with concurrency, but this time the added service weight is only half of the previous two servers.

From the test results, we can see that the last added service bears the corresponding concurrent processing according to the setting of weight.

Through the above examples, you will find that theBeetlexBuilding highly available web API cluster services is a very simple matter.

Project address: https://github.com/IKende/FastHttpApi

Cluster Policy Management Project Address: https://github.com/IKende/Cluster Configuration

The above is the whole content of this article. I hope it will be helpful to everyone’s study, and I hope you will support developpaer more.