In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the example analysis of connection pooling in programming development. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
What is connection pooling?
The technology of creating and managing connection buffer pool is essentially resource reuse, which can improve performance without frequent connection creation and destruction.
Voice-over: database connection pooling, service connection pooling, all connection pooling.
Connection pooling plays an extremely important role in the micro-service hierarchical architecture.
As shown above:
The upper dashed wireframe is a web cluster.
The lower dashed wireframe, which is the service cluster
A green box that represents a connection established upstream and downstream
The blue box represents the connection pool
In this example, a caller establishes two connections with a service node, and the service cluster has three clusters, so the connection pool has a total of six connections, from C1 to c6.
For the upper caller, apart from receiving and sending connection messages from the connection pool to access downstream services, what other technical points in the Internet architecture are related to the connection pool?
I. failover and Service Discovery
As shown above:
Failover, if the old service node S1 fails, the C1 and c2 connections fail and will be removed from the connection pool, and subsequent requests will not be sent to the failed node
Service discovery: if the new service node S4 is online and the c7 and c8 connections are established, it will be added to the connection pool, and subsequent requests will be sent to the new node
Dynamically delete connections and add connections, which is called dynamic connection pooling.
Service discovery, how to sense the new node S4 online? For details, see "changed the configuration, do not want to restart, how to do it?"
Second, load balancing
By using the polling strategy and using the connections in the connection pool one by one, the load balance of access to downstream services can be realized.
Load balancing can also be achieved by using a completely random strategy.
As shown above:
Give each connection the same weight, take the connection to access the downstream, use a random algorithm, fall to which grid and which connection, or the above example:
N = random ()% 6 + 1
When
N = [1prime2], visit S1
N = [3pr 4], visit S2
N = [5pr 6], visit S3
The width of the three intervals is the same, that is, the probability of falling to a certain service is equal, and the load is balanced.
So, what if the service capacity of the service node is different, some are strong and some are weak?
Third, static weight load balancing
As shown above:
Configure each service with a different weight. When the connection pool is initialized, the interval size of different services is different, and the probability of falling to a certain grid is also different when the connection is accessed downstream:
N = random ()% 16 + 1
When
N = [1prime2], visit S1
N = [3pyr6], visit S2
N = [7pr 16], visit S3
The width of the three intervals is proportional to the weight of the service, that is, the probability of falling to a service is equal to the weight.
Voiceover: nginx supports this game, but the static weight is too rough.
So, what if the service capabilities of service nodes are different, but it is difficult to identify them with static weights?
Fourth, dynamic weight load balancing
As shown in the figure above: when the connection pool is initialized, assign a dynamic weight to the connection.
Voiceover: the service no longer needs to be configured.
The load is still distributed as before, but:
Connection processing timed out and dynamic weight decreased
Connection processing is successful, dynamic weight increases
This is the end of the article on "sample analysis of connection pooling in programming development". I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.