Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to define the service consumption strategy of the development environment

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to define the service consumption strategy of the development environment". The content is simple and clear, and I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "how to define the service consumption strategy of the development environment".

With regard to the rpc framework, briefly introduce the ribbon of springcloud.

In the registration discovery mechanism of springcloud, when it is found that the provider has multiple nodes, one of the nodes will be selected through the specified load policy of the ribbon module, which is called load balancing.

Ribbon implements many kinds of load policies by default. First, we briefly talk about these commonly used policies, and finally we focus on how to define an efficient load policy for the dev environment.

Ribbon Code jar package:

The code about the load balancing algorithm is in

Com.netflix.ribbon ribbon-loadbalancer 2.2.5

The load balancing strategies implemented by ribbon by default are:

RoundRobinRule (rotational training strategy): when node1,node2,node3 is available for available services, ribbon will store these three nodes in the cache, and then consume the three nodes sequentially when consuming. This policy is also the default policy of ribbon.

BestAvailableRule (Best available Policy): when node1,node2,node3 is available for available services, ribbon will store these three nodes in the cache, and then call three nodes in turn. If the node is ignored and skipped, try to request the node again. If the instantaneous concurrency of the node is minimized, the services of the node will be used.

RandomRule (random strategy): when the available service has node1,node2,node3, ribbon will store these three nodes in the cache, and then randomly fetch a node to provide the call. The random algorithm is also very simple, take the total number of available nodes, then use rand.next (total number of available nodes) to get an integer value less than the total number, and then take a service from the available node list to call.

ZoneAvoidanceRule (Baidu translation: zone avoidance strategy): in the upper layer of the available node cluster, if there is a computer room cluster, such as the program is deployed in Aliyun's East China node and Beijing node, you can use this strategy. He will first help you filter out an available zone, and then select an available node (this strategy should be rarely used. If it is used, the operation and maintenance staff will do this. At present, our program is only in East China 2 of Aliyun.

There are many other strategies that you can choose to use.

Here comes the point.

Do developers feel that when developing micro-service programs, efficiency becomes very low. It takes about ten minutes for the program to start. If you are not careful, you will temporarily change the port and the system will run out of memory. This is actually very painful for programmers.

Let me first talk about the problems we encountered before:

The developer needs to start all the backends, one registry, five back-end microservices, and two front ends (if you develop one, start one). In this way, the local development machine needs to start at least seven programs (each development programmer has full git permission on the server side).

The leader is a little sensitive that each programmer has full code permissions.

The developer diss me, the program eats memory and causes computer stutters.

The service of the local development machine is accidentally registered with the public development environment, but the local code will have individual bug, and the service of the development environment will become very weird, and it will be bad for a while, which makes the product manager always diss the whole development team on the grounds of product instability.

In fact, this problem has been proved to affect the efficiency of developers, and they are doing some useless work. So I was thinking that if we solve this problem.

First: write a startup script file. One click to start all the programs, the time has been reduced to three minutes, although the time has been reduced, but for the developer's computer stutter, the leader's sensitive problem has not been solved.

Second: the development environment deploys a complete set of services, and programmers develop their own programs. The services of all local development machines are registered with the public development environment. At this point, the development environment is a cluster environment. But the local code is unstable, and if another colleague invokes your service, it can easily affect the progress of other colleagues. At this time, there are two kinds of consumers: development environment and developers. There are three kinds of providers: development environment, current developers, and other developers. So for the development environment, his consumption priority is the development environment "developers." For developers, their consumption priority is the services provided by current developers "services provided by the development environment" services provided by other developers. This can achieve the effect that when you use the app,web system of the test environment, it always consumes the services of the development environment. It is relatively stable. For developers who want to debug a service written by themselves, they only need to start the corresponding point service. When the service is called locally, it is found that the registry only consumes the service of the development environment. If the registry has multiple service nodes, priority is given to the ip service in the local development environment. If the service is not changed, other colleagues in the service are also registered locally, but relatively speaking, it is more reliable to consume the service in the development environment, so take the development environment service.

This reduces startup time and leads sensitive things because the program consumes more memory.

Specific code implementation:

Declare a policy

To implement the rule class, it mainly inherits the AbstractLoadBalancerRule class.

The above is all the contents of the article "how to define the service consumption strategy of the development environment". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report