Heterogeneous (dubbo compatible) SOA System Architecture (. net) optimization and upgrade, dubbosoa

Source: Internet
Author: User

Heterogeneous (dubbo compatible) SOA System Architecture (. net) optimization and upgrade, dubbosoa

As mentioned in the previous article, our heterogeneous (dubbo compatible) SOA system architecture has solved many technical pain points and is still relatively complete. It has also been successfully promoted.

However, as a developer of the project, I am aware of the problems with my own products, but there is still a small distance from my satisfaction.

During the promotion, I entered the development of the next version to improve it.

The original version is 1.0. Now the version is upgraded to 1.1 and has been developed and released (internal). The main content of this upgrade is as follows:

1. Corrected some bug2 and simplified the use of SOA to enhance IOC, decoupling object associativity use the company's internal Nuget to manage SOA and related dependencies to simplify method calls and method parameters (as far as possible, only necessary parameters are retained) 3. Performance Improvement, cpu and thread resource usage decrease as appropriate efficient asynchronous threads, reduce application startup time efficient object reuse saves memory and cpu consumption 4. improve stability and increase Failover (faulty nodes will be removed from the Server Load balancer list, to avoid a large number of errors caused by exceptions in the zookeeper service due to delayed notification) Optimize the detection and maintenance of the zookeeper connection status (connection interruption and timely reconnection) adding an elegant server deprecation Mechanism 5. Enhanced configuration adds many optional configurations to meet business and performance requirements. You can individually configure a single service. 6. Enhanced logs are applied to almost every component and every service in SOA. you can configure individual logs to enable all the logs. You can also choose to enable some logs. The development and testing work is more than three months, of course, some infrastructure work is included here, and its significance is not only the benefit of SOA, such as internal Nuget, log, IOC container optimization, I. Example 1 of using the console as a server in version 1.1. Use Nuget to install Fang. all references to SOA (including ZooKeeper and Thrift) can be done with one click. 2. There are still a lot of things to install. Without Nuget, it will crash people. 3. Don't be too many components (dll) scared, most of the dll files are very small and are independent functions. Note: we can see that the above is the beginning of September, and the development completion time is actually middle November; that is to say, the design was completed in early September and the basic goal has been completed and debugged, and then the bug and optimization has been continuously modified for more than two months, looking closer and closer to your goal. 4. The server code is very simple.
Class Program {static IContainer _ container; static void Main (string [] args) {IContainer container = _ container = new SimpleContainer (). SOALoadSettings (); // load appSettings to configure CreateHelloWorld (container); // HelloWorld service container. SOAStart (); // start all service consoles. readLine ();} /// <summary> /// HelloWorld service /// </summary> /// <param name = "container"> </param> private static void CreateHelloWorld (IContainer container) {string serviceName = "com. fang. helloWorld $ Iface "; // service name var service = new HelloWorldImp (); // service implementation logic container. SOAProvider <HelloWorldService. iface> (serviceName, service); // register a service }}

Haha, that's easy.

What's more than simplicity? Is it very smooth?

You are not mistaken. Just a few lines of code in the above area will complete the release of the SOA service.

5. Something less than Version 1.0

5.1 The ZKInit method is missing

This is a major change. In the past, we had to connect zooKeeper to "publish" the service.

Now there is no such premise. The zooKeeper connection is asynchronized and needs to be obtained from the IOC container when zooKeeper is needed. If the container does not exist, connect zooKeeper asynchronously and save it to the IOC container, it can be obtained at any time when necessary in the future.

5.2 added the container (IOC container)

This is also a major change. Now the SOA configuration depends on the container. All the actual parameters are obtained from the container. When the program is initialized, the default value is injected into the container for each parameter, to overwrite the default value

The SOALoadSettings above is the container extension method used to load the data of SOA-related nodes in etettings into the container.

In fact, almost all SOA components, runtime objects, and object caches are implemented using this container.

In Version 5.3, ZKConsumer's position was ruthlessly abandoned.

In Version 1.0, ZKConsumer is almost the only class for direct interaction between. net SOA.

Later, with the improvement of the SOA system, I found that ZKConsumer could not afford this role and abandoned it, enabling IContainer (container Interface) that is "unrelated" to SOA)

This will be a future trend. We "don't need to remember" every system's personalized business terms (classes). We use the IContainer generic object extension method to define simple APIs.

We use a system method to reference the system's Nuget package (dll), reference the system's namespace, and then find the system's Api (Extension Method) under IContainer) to use

When a system is started, the container is configured for the system. You can configure the container by using the file or by using the code.

5.4 Some people may say that there are still a few configuration items, which all default values cannot be used. Those configurations can be configured in the appSettings, and each service can be configured separately, A bunch of IContainer extension methods are provided to configure the code after adding all the configurations in the 1.0 example as follows:
Private static void CreateHelloWorld (IContainer container) {string serviceName = "com. fang. helloWorld $ Iface "; // service name var service = new HelloWorldImp (); // service implementation logic string serviceIp =" 192.168.109.166 "; // The Publishing service uses ip int servicePort = 5000; // port string group = "kg" for publishing services; // Application group string serviceVersion = "1.0.0"; // service version int serviceTimeOut = 5000; // service timeout threshold (unit: Millisecond) int alertElapsed = 3000; // service execution time monitoring alarm threshold (unit: Millisecond) int alertFailure = 10; // number of errors per minute monitoring alarm threshold container. SOAServiceHost (serviceIp, servicePort, serviceName ). SOAServiceGroup (group, serviceName ). SOAServiceVersion (serviceVersion, serviceName ). SOAServiceTimeout (serviceTimeOut, serviceName ). SOAAlertelapsed (alertElapsed, serviceName ). SOAAlertfailure (alertFailure, serviceName); container. SOAProvider <HelloWorldService. iface> (serviceName, service); // register the service}

Some people say that your code is more degraded to Version 1.0?

1. Not every service has so many personalized configurations and provides simple APIs with required parameters to improve user experience.

Second, the configuration is diversified, and the code configuration is no longer the best choice, and fewer code must be written.

Ii. Log configuration 1. Log configuration is one of the main contents of this upgrade. A container Extension Method SOALog can be used to record all SOA logs. The code after adding the log is as follows:
Static void Main (string [] args) {IContainer container = _ container = new SimpleContainer (). SOALoadSettings () // load the appSettings configuration. SOALog (); // enable all logs CreateHelloWorld (container); // HelloWorld service container. SOAStart (); // start all service consoles. readLine ();}

2. Enable the default log function as follows:

This is a local test service that I have been running since the 15th day. The log file is a little large, but the log performance is relatively reliable, full logs have almost no impact on the execution time of high concurrency. for each service, separate logs are generated by default based on talent files. Of course, files can be output to the console or database without being recorded, in this case, you need to configure a log factory to the container, which is beyond the scope of this article. 3. Can you enable only some logs, A bunch of log configuration methods (container extension method) are provided. SOALog is just their commander-in-chief. There is always one suitable for you with so many log configurations. Iii. Example 1 of Version 1.1 client: directly add the code (nuget installation references the same server)
Public class HelloWorldTest {static IContainer _ container; public static void Test () {IContainer container = _ container = new SimpleContainer (). SOALoadSettings () // load the appSettings configuration. SOALog (); Subcribe (container); // subscribe to com. fang. helloWorld string str = null; do {str = Console. readLine (); if (string. equals (str, "Exit", StringComparison. currentCultureIgnoreCase) return; Console. writeLine ("callService" ); CallService (); // call service} while (true);} private static void Subcribe (IContainer container) {string serviceName = "com. fang. helloWorld $ Iface "; // service name string serviceGroup =" kg "; // Service Group container. SOAConsumer <HelloWorldService. iface> (serviceName, serviceGroup, zooKeeper);} private static void CallService () {if (_ container = null) return; string results = null; using (var resource = _ container. SOAS Ervice <HelloWorldService. iface> () {if (resource = null) return results; HelloWorldService. iface service = resource. service; if (service = null) {Console. writeLine ("service is null"); return results;} else {var socket = resource. socket; Console. writeLine (string. concat (socket. host, ":", socket. port. toString (), "");} try {results = service. sayHello ("Word");} catch (Exception ex) {var Socket = resource. Socket; if (socket! = Null) Console. writeLine (string. concat (socket. host, ":", socket. port. toString (), "error"); Console. writeLine (ex. message );}}}}

Note: The 1.1 client is still full of container extension methods and simple APIs. Like the server, you can use the container to configure the personalized parameters of the service (this will not be expanded here)

 

2. The execution result is as follows:

CallService192.168.109.166: 3459 Hello everyone: 3458 Hello wordCallService192.168.109.166: 3457 Hello wordCallService192.168.109.166: 3456 Hello wordCallService192.168.109.166: 3459 Hello everyone: 3458 Hello everyone: 3457 Hello word

I run 4 services locally and provide services by polling

5. Imagine that the content of this upgrade will be displayed before the version in the future. I am satisfied with the version, and its performance and stability are no longer lost in the dubbox of java. But I still have the urge to continue optimization, I also sorted out a few features that have not yet been implemented, but I'm looking forward to it. 1. Full container configuration support is just like dubbo. Configure them in spring containers. 2. DI support encapsulates Service Factory Aop service interface, direct the DI service interface object to the desired place, And the execution method first obtains a real object, end of execution method recycling 3. Multiple Fault tolerance algorithms and multiple Server Load balancer algorithms are available for configuration. When I finish other urgent tasks, I will prepare to start the development of the next version.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.