A data source connection pool adaptive adjustment method using an intelligent model

By employing a three-level water level acquisition mechanism and an intelligent dynamic prediction model, the dynamic adjustment problem of the data source connection pool was solved, enabling the perception of upstream and downstream conditions and the full-link adjustment, thus preventing system avalanche and improving the accuracy and reliability of the adjustment.

CN122601740BActive Publication Date: 2026-11-24北京科杰科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610704275.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-05-21
Publication Date
2026-11-24
Estimated Expiration
2046-05-21

AI Technical Summary

Technical Problem

In existing technologies, the dynamic adjustment method of data source connection pools suffers from information silos and a lack of global perspective. This leads to the connection pool blindly expanding when traffic surges or database performance degrades, causing database CPU spikes, rampant slow queries, and thread blocking, resulting in service avalanche.

Method used

A three-level water level acquisition mechanism is adopted, integrating downstream water level, local water level and upstream water level data to construct an intelligent dynamic prediction model for the connection pool. A lightweight exponential weighted regression model is used to predict the real-time optimal number of connections, and combined with avalanche index and threshold access control, the risk can be dynamically adjusted and optimized.

Benefits of technology

It improves the accuracy and reliability of connection pool regulation, can identify risks in advance, avoid the database's passive response lag, realize early warning and proactive prevention, avoid system avalanche, and maintain system high performance and stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122601740B_ABST
    Figure CN122601740B_ABST
Patent Text Reader

Abstract

This invention discloses an adaptive adjustment method for a data source connection pool using an intelligent model, belonging to the field of database analysis technology. This invention utilizes a three-level water level acquisition mechanism to collect data at different water levels to construct an intelligent dynamic prediction model for the connection pool, predicting the real-time optimal number of connections. After predicting the real-time optimal number of connections, the total number of occupied connections for services other than the current service is queried from the database. The downstream overload risk of the current service is calculated using the total number of occupied connections and the real-time optimal number of connections. The upstream backlog risk is calculated using the backlog of requests and the maximum queuing capacity of the upstream gateway of the current service. The downstream overload risk and the upstream backlog risk are fused to obtain an avalanche index. A three-level threshold access control is set for the avalanche index to determine whether the connection pool of the current service has an avalanche risk. When the connection pool is safe, an adjustment strategy is generated using the real-time optimal number of connections.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database analysis technology, specifically to an adaptive adjustment method for data source connection pools using an intelligent model. Background Technology

[0002] With the rapid popularization of distributed architecture, microservice architecture, and high-concurrency internet services, databases, as the core storage component of systems, face increasingly severe access pressure. Data source connection pools, as key middleware between application services and databases, are responsible for managing the creation, reuse, destruction, and allocation of database connections. Their proper configuration directly determines system throughput, response speed, and stability. Traditional mainstream connection pools mostly adopt a static configuration approach, keeping parameters such as the maximum and minimum number of connections constant during business operations. With the rapid development of computer technology, dynamic adjustment strategies for various parameters of connection pools have gradually emerged to cope with traffic fluctuations and improve resource utilization. However, existing dynamic adjustment generally suffers from core defects such as information silos and a lack of a global perspective: the adjustment is based solely on the local state of the connection pool itself, without being aware of the pressure on the upstream gateway, the degree of request backlog, the actual load on the database, or the connection usage of other services. The isolation between upstream and downstream states and the inability to make collaborative judgments lead to significant risks in dynamic adjustment: when there is a sudden surge in traffic, a decline in database performance, or multiple services competing for resources, the connection pool still blindly expands, continuously requesting connections from the database, quickly exhausting the total number of database connections, causing database CPU spikes, rampant slow queries, thread blocking, and ultimately triggering a cascading service avalanche, resulting in large-scale business interruptions. Therefore, there is an urgent need for an adaptive adjustment method for connection pools that breaks down information silos and integrates the status of the entire upstream and downstream chain, so as to achieve risk prevention and control while dynamically adjusting parameters, and fundamentally avoid the avalanche problem. Summary of the Invention

[0003] The purpose of this invention is to provide an adaptive adjustment method for data source connection pools using an intelligent model, in order to solve the problems raised in the prior art.

[0004] To achieve the above objectives, the present invention provides the following technical solution: An adaptive adjustment method for data source connection pools utilizing an intelligent model, the method comprising the following steps: S100. Set up a three-level water level acquisition mechanism in the data source connection pool. The three-level water level acquisition mechanism collects the actual database load, connection pool status and business characteristics, and business entry pressure and tolerance respectively. Furthermore, the three-level water level acquisition mechanism includes downstream water level, local water level, and upstream water level. The downstream water level is responsible for the actual database load, which includes CPU utilization, number of active threads, and cumulative number of slow queries. The local water level is responsible for the connection pool status and business characteristics, which include the number of active connections, waiting queue length, and average query SQL time. The upstream water level is responsible for the business entry pressure and tolerance, which includes requests per second, gateway response time, and backlog of requests.

[0005] By collecting metrics from downstream, local, and upstream levels, the system covers the entire link from user requests to database execution, moving beyond just looking at the connection pool itself and avoiding misjudgments due to focusing on only a part. Downstream monitoring tracks database CPU, active threads, and slow queries, directly reflecting database capacity; local monitoring tracks active connections, wait queues, and SQL execution time, accurately reflecting connection pool bottlenecks; and upstream monitoring tracks QPS, response time, and backlogged requests, proactively detecting business traffic impacts. These three levels of data collectively constitute the "perception layer" of the adjustment process, ensuring that subsequent predictions, risk calculations, and strategy outputs are based on real and comprehensive on-site data, improving the accuracy and reliability of the entire adjustment process.

[0006] S200. Preprocess all collected data, including spatiotemporal alignment, null imputation, and abrupt smoothing, and construct periodic feature structures. Furthermore, the specific steps for constructing the periodic feature structure are as follows: S201, the spatiotemporal alignment means aligning all collected data to a uniform time granularity using the sliding window mean method; the null value filling means filling missing values ​​that occur during the data collection process using the forward filling method. The mutation smoothing process specifically involves: calculating the standard deviation and mean of all collected data, then calculating the difference between each data point and the mean, identifying data points with a difference exceeding three times the standard deviation as outliers, and using a filter to remove outliers. S202. After preprocessing all the data, construct a periodic feature structure for all the collected data as follows: and t represents the number of seconds since 00:00:00 of the current time; 86400 represents the total number of seconds in a whole day; the periodic feature structure is used as input to the connection pool intelligent dynamic prediction model, allowing the model to automatically perceive the morning and evening peak patterns. Adding a 24-hour periodic structure allows the model to learn patterns such as morning and evening peaks, low points, and scheduled tasks, preparing in advance before traffic arrives and avoiding reactive delays.

[0007] S300: Utilizes different water level data collected by a three-level water level acquisition mechanism to construct an intelligent dynamic prediction model for the connection pool, predicting the real-time optimal number of connections for the connection pool. Furthermore, the specific steps for predicting the real-time optimal number of connections in the connection pool are as follows: S301. A lightweight exponentially weighted regression model is used to construct an intelligent dynamic prediction model for the connection pool. The optimal number of connections in real-time is defined in this model as: P opt (t+1)=L t +α×T t +γ×f(U qps (t), R running (t)); In the formula, P opt (t+1) represents the predicted optimal number of connections the connection pool should be configured for in the real-time next cycle; L t T represents the actual effective concurrency at the current moment, α represents the trend smoothing coefficient, and T represents the actual effective concurrency at the current moment. t γ represents the upstream flow trend slope, γ represents the downstream load penalty factor, and f(U) qps (t), R running (t) represents the correction function, U qps (t) represents the number of requests per second, R running (t) represents the number of active threads; combined with actual effective concurrency, traffic trends, downstream load penalties, and correction functions, the output is not a fixed value, but a dynamic optimal value that fits the business needs of the next second.

[0008] S302. The actual effective concurrency = number of active connections + waiting queue length. The actual effective concurrency reflects the real demand gap. The upstream traffic trend slope is calculated based on the number of requests per second in adjacent periods, specifically: U qps (t-1) represents the number of requests per second in the previous cycle, and Δt represents the time difference between adjacent cycles; The correction function is specifically defined as: f = min(U qps (t) × response time base value, maximum number of database connections), input U in the correction function qps (t) Calculate the theoretical upper limit of connectivity, then input R running (t), using the theoretical connection limit minus the number of active threads R running (t) yields the final allowed number of connections. The correction function min(calculated value, maximum number of database connections) ensures that the number of connections exceeds the database's capacity, thus preventing the database from becoming overloaded from the outset.

[0009] S400: After predicting the real-time optimal number of connections in the connection pool, query the database to find the total number of occupied connections for services other than the current service. Calculate the downstream overload risk of the current service using the total number of occupied connections and the real-time optimal number of connections. Calculate the upstream backlog risk using the backlog of requests and the maximum queuing capacity of the upstream gateway of the current service. Combine the downstream overload risk and the upstream backlog risk to obtain the avalanche index. Furthermore, the specific steps for fusing downstream overload risk and upstream backlog risk to obtain the avalanche index are as follows: S401. Calculate the downstream overload risk by querying and statistically analyzing the total number of connections currently occupied by other service applications in the database. ; In the formula, F D Indicates downstream overload risk, P other Indicates the total number of connections already used, R max P represents the maximum number of database connections. opt It indicates the real-time optimal number of connections; it not only looks at the current service, but also counts the connections occupied by other services, accurately judging whether the database is close to saturation and whether there is a risk of being "snapped up".

[0010] S402. The upstream backlog risk is calculated using the number of backlogged requests and the maximum queuing capacity of the current service's upstream gateway. Specifically: ; In the formula, F U Indicates upstream inventory backlog risk, U queue U represents the number of backlogged requests. max Indicates the maximum queuing capacity of the upstream gateway; S403. Dynamic fusion weights of W are configured for downstream overload risk and upstream backlog risk, respectively. db and W up W db =F D / (F D +F U ), W up =F U / (F D +F U The avalanche index is obtained by fusing downstream overload risk and upstream backlog risk using a fusion weighting method. ; In the formula, ASI represents the avalanche index. Higher weights are automatically assigned to the more risky party, making the avalanche index more aligned with the actual hazard level rather than being a simple average. It transforms the abstract question of "whether the system will crash" into calculable, alarmable, and trend-trackable values, achieving risk transparency. It can calculate the avalanche probability before the connection pool is exhausted and the database freezes, enabling pre-warning rather than post-repair.

[0011] S500. Set a three-level threshold gate for the avalanche index, and use the three-level threshold gate to judge the avalanche index, so as to determine whether there is an avalanche risk in the connection pool of the current service; Further, the specific steps of judging the avalanche index by using the three-level threshold gate are: S501. The preset three-level threshold gate is (A1, A2), where A2 > A1, A1 represents the safety threshold, and A2 represents the risk threshold; when ASI ≤ A1, it is determined that the connection pool of the current service is safe, and the real-time optimal connection number is directly adopted; when A1 < ASI ≤ A2, it is determined that there is a risk in the connection pool of the current service, and an early warning is issued, the real-time optimal connection number is not directly adopted, and secondary optimization is performed; when ASI > A2, it is determined that the connection pool of the current service is about to avalanche, which is a high-risk situation, the real-time optimal connection number is rejected, and avalanche optimization is performed. The three levels of safety → early warning → high risk use different strategies for different risk levels, taking into account both performance and safety, and avoiding resource waste caused by conservative configuration and failures caused by aggressive configuration.

[0012] S600. When the connection pool is safe, use the real-time optimal connection number to generate an adjustment strategy; set up a secondary optimization mechanism, and when there is a risk in the connection pool, use the secondary optimization mechanism to optimize the real-time optimal connection number and output a safe connection number; Further, the specific steps of generating the adjustment strategy by using the real-time optimal connection number are: S601. Input the real-time optimal connection number into the PID controller to smoothly issue the configuration, specifically as follows: ΔP = K p × (P opt - P current ) + K i × ∫ (P opt - P current ) dt In the formula, ΔP represents the adjusted connection number, K p represents the proportional coefficient, K i represents the integral coefficient, and P current represents the current configured maximum capacity limit; Use the adjusted connection number to form an adjustment strategy and issue it to the connection pool; S602. The secondary optimization mechanism specifically involves introducing a security attenuation factor β, and using this factor to perform secondary optimization on the real-time optimal number of connections to obtain the theoretical number of secure connections. The formula is as follows: The=P current +β×(P opt -P current ); In the formula, The represents the theoretical number of secure connections; the minimum number of idle connections in the connection pool is collected, and the minimum value between the minimum number of idle connections and the theoretical number of secure connections is selected as the output number of secure connections. The security attenuation factor is calculated using the total number of occupied connections, the current maximum configured capacity limit, and the maximum number of database connections, specifically: ; In the formula, ρ safe represents the global safety water level coefficient, which is set to a fixed value by the staff, with a range of (0.75, 0.85); k represents the reaction sensitivity index; 0.2 is used as the minimum limit of the safety decay factor, allowing 20% ​​of the model adjustment range to be retained even if the system is extremely dangerous, to prevent the system from completely freezing; the range of the safety decay factor is [0.2, 1]. The number of secure connections is input into the PID controller and the configuration is smoothly distributed to obtain the adjusted number of connections after secondary optimization. This constitutes the adjustment strategy and is then distributed to the connection pool.

[0013] S700: Construct an avalanche optimization strategy; when it is determined that the connection pool of the current service is about to experience an avalanche, execute avalanche optimization. Furthermore, the avalanche optimization specifically includes: Instead of directly discarding the real-time optimal number of connections, we optimize the current maximum capacity limit using the avalanche exponent, with the formula: Py=P current ×(1-e×(ASI-0.7) / 0.3), where e represents the contraction strength coefficient, Py represents the optimized maximum capacity limit of the current configuration, and the calculation result is rounded down; the maximum value of the minimum idle number of connections in the connection pool and the optimized maximum capacity limit of the current configuration is selected as the number of connections to be contracted urgently, P. shrink ; When P shrink ≥P current In this case, no adjustments will be made, but a high-risk alarm log will be recorded. When P shrink <P current At this time, the number of connections in the connection pool is directly set to the number of connections for emergency contraction, without using a PID controller.

[0014] In high-risk situations, the predicted value is discarded directly, and connections are quickly reduced to immediately alleviate database pressure and break the chain of "connection exhaustion → database blocking → service avalanche". After reduction, core services are still available and there will be no complete system crash, minimizing business losses. The reduction range is automatically calculated based on the Avalanche Index (ASI), and the greater the risk, the more it is reduced, resulting in precise hemostasis.

[0015] Compared with the prior art, the beneficial effects of the present invention are: 1. This invention employs a three-tiered data collection mechanism—downstream water level, local water level, and upstream water level—to simultaneously collect three core data categories: actual database load, connection pool operating status, and business entry pressure, covering the entire link from the request entry point to the underlying database. Compared to traditional methods that only monitor the connection pool's own status, this invention provides a comprehensive understanding of key indicators such as connection occupancy, request queuing, database pressure, slow queries, and active threads. This provides complete, accurate, and unbiased data support for connection number adjustment, preventing adjustment errors caused by incomplete data from the outset and significantly improving the reliability of adjustment decisions.

[0016] 2. This invention integrates downstream overload risk and upstream backlog risk, and calculates the Avalanche Index (ASI) through dynamic weighting. This transforms the abstract risk of system collapse into an intuitive numerical value, making the risk calculable, comparable, and monitorable. Compared to traditional methods that rely on a single indicator to judge risk, this invention more accurately reflects the overall probability of service failure, identifies hidden risks in advance, and provides an objective basis for subsequent tiered handling, shifting from "passive fault handling" to "proactive risk prevention and control."

[0017] 3. This invention sets three threshold levels: safe, early warning, and high-risk, and implements differentiated strategies for different avalanche indices: in the safe state, the optimal number of connections is used directly to ensure performance; in the early warning state, secondary optimization is initiated to reduce risk; in the high-risk state, avalanche optimization is directly executed for emergency loss mitigation. This tiered response mechanism avoids both a one-size-fits-all conservative configuration that limits business performance and aggressive configuration that causes system failures, finding the optimal balance between "high performance" and "high stability," adapting to complex scenarios such as sudden traffic changes, business peaks, and database fluctuations. Attached Figure Description

[0018] Figure 1 This is a schematic diagram illustrating the steps of an adaptive adjustment method for a data source connection pool using an intelligent model, according to the present invention. Detailed Implementation

[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0020] Example: Figure 1 As shown, the present invention provides a technical solution. An adaptive adjustment method for data source connection pools utilizing an intelligent model, the method comprising the following steps: S100. Set up a three-level water level acquisition mechanism in the data source connection pool. The three-level water level acquisition mechanism collects the actual database load, connection pool status and business characteristics, and business entry pressure and tolerance respectively. The three-level water level acquisition mechanism includes downstream water level, local water level, and upstream water level. The downstream water level is responsible for the actual database load, which includes CPU utilization, number of active threads, and cumulative number of slow queries. The local water level is responsible for the connection pool status and business characteristics, which include the number of active connections, waiting queue length, and average query SQL time. The upstream water level is responsible for the business entry pressure and tolerance, which includes requests per second, gateway response time, and backlog of requests.

[0021] By collecting metrics from downstream, local, and upstream levels, the system covers the entire link from user requests to database execution, moving beyond just looking at the connection pool itself and avoiding misjudgments due to focusing on only a part. Downstream monitoring tracks database CPU, active threads, and slow queries, directly reflecting database capacity; local monitoring tracks active connections, wait queues, and SQL execution time, accurately reflecting connection pool bottlenecks; and upstream monitoring tracks QPS, response time, and backlogged requests, proactively detecting business traffic impacts. These three levels of data collectively constitute the "perception layer" of the adjustment process, ensuring that subsequent predictions, risk calculations, and strategy outputs are based on real and comprehensive on-site data, improving the accuracy and reliability of the entire adjustment process.

[0022] S200. Preprocess all collected data, including spatiotemporal alignment, null imputation, and abrupt smoothing, and construct periodic feature structures. The specific steps for constructing the periodic feature structure are as follows: S201, the spatiotemporal alignment means aligning all collected data to a uniform time granularity using the sliding window mean method; the null value filling means filling missing values ​​that occur during the data collection process using the forward filling method. The mutation smoothing process specifically involves: calculating the standard deviation and mean of all collected data, then calculating the difference between each data point and the mean, identifying data points with a difference exceeding three times the standard deviation as outliers, and using a filter to remove outliers. S202. After preprocessing all the data, construct a periodic feature structure for all the collected data as follows: and t represents the number of seconds since 00:00:00 of the current time; 86400 represents the total number of seconds in a whole day; the periodic feature structure is used as input to the connection pool intelligent dynamic prediction model, allowing the model to automatically perceive the morning and evening peak patterns. Adding a 24-hour periodic structure allows the model to learn patterns such as morning and evening peaks, low points, and scheduled tasks, preparing in advance before traffic arrives and avoiding reactive delays.

[0023] S300: Utilizes different water level data collected by a three-level water level acquisition mechanism to construct an intelligent dynamic prediction model for the connection pool, predicting the real-time optimal number of connections for the connection pool. The specific steps for predicting the real-time optimal number of connections for the connection pool are as follows: S301. A lightweight exponentially weighted regression model is used to construct an intelligent dynamic prediction model for the connection pool. The optimal number of connections in real-time is defined in this model as: P opt (t+1)=L t +α×T t +γ×f(U qps (t), R running (t)); In the formula, P opt (t+1) represents the predicted optimal number of connections the connection pool should be configured for in the real-time next cycle; L t T represents the actual effective concurrency at the current moment, α represents the trend smoothing coefficient, and T represents the actual effective concurrency at the current moment. t γ represents the upstream flow trend slope, γ represents the downstream load penalty factor, and f(U) qps (t), R running (t) represents the correction function, U qps (t) represents the number of requests per second, R running (t) represents the number of active threads; combined with actual effective concurrency, traffic trends, downstream load penalties, and correction functions, the output is not a fixed value, but a dynamic optimal value that fits the business needs of the next second.

[0024] S302. The actual effective concurrency = number of active connections + waiting queue length. The actual effective concurrency reflects the real demand gap. The upstream traffic trend slope is calculated based on the number of requests per second in adjacent periods, specifically: U qps (t-1) represents the number of requests per second in the previous cycle, and Δt represents the time difference between adjacent cycles; The correction function is specifically defined as: f = min(U qps (t) × response time base value, maximum number of database connections), input U in the correction function qps (t) Calculate the theoretical upper limit of connectivity, then input R running(t), using the theoretical connection limit minus the number of active threads R running (t) yields the final allowed number of connections. The correction function min(calculated value, maximum number of database connections) ensures that the number of connections exceeds the database's capacity, thus preventing the database from becoming overloaded from the outset.

[0025] S400: After predicting the real-time optimal number of connections in the connection pool, query the database to find the total number of occupied connections for services other than the current service. Calculate the downstream overload risk of the current service using the total number of occupied connections and the real-time optimal number of connections. Calculate the upstream backlog risk using the backlog of requests and the maximum queuing capacity of the upstream gateway of the current service. Combine the downstream overload risk and the upstream backlog risk to obtain the avalanche index. The specific steps for fusing downstream overload risk and upstream backlog risk to obtain the avalanche index are as follows: S401. Calculate the downstream overload risk by querying and statistically analyzing the total number of connections currently occupied by other service applications in the database. ; In the formula, F D Indicates downstream overload risk, P other Indicates the total number of connections already used, R max P represents the maximum number of database connections. opt It indicates the real-time optimal number of connections; it not only looks at the current service, but also counts the connections occupied by other services, accurately judging whether the database is close to saturation and whether there is a risk of being "snapped up".

[0026] S402. The upstream backlog risk is calculated using the number of backlogged requests and the maximum queuing capacity of the current service's upstream gateway. Specifically: ; In the formula, F U Indicates upstream inventory backlog risk, U queue U represents the number of backlogged requests. max Indicates the maximum queuing capacity of the upstream gateway; S403. Dynamic fusion weights of W are configured for downstream overload risk and upstream backlog risk, respectively. db and W up W db =F D / (F D +F U ), W up =F U / (F D +F U The avalanche index is obtained by fusing downstream overload risk and upstream backlog risk using a fusion weighting method. ; In the formula, ASI represents the avalanche index. By automatically assigning a larger weight to the higher-risk party, the avalanche index is made more aligned with the real danger level, rather than being a simple average. This transforms the abstract question of "whether the system will crash" into a computable, alertable, and trend-traceable value, achieving risk transparency. The avalanche probability can be calculated before the connection pool is exhausted or the database freezes, enabling pre-event early warning rather than post-event repair.

[0027] S500: Set up a three-level threshold gate for the avalanche index, and use the three-level threshold gate to judge the avalanche index to determine whether the connection pool of the current service has an avalanche risk; The specific steps of using the three-level threshold gate to judge the avalanche index are as follows: S501: Preset the three-level threshold gate as (A1, A2), where A2>A1, A1 represents the safety threshold, and A2 represents the risk threshold; when ASI≤A1, determine that the connection pool of the current service is safe, and directly adopt the real-time optimal number of connections; when A1<ASI≤A2, determine that the connection pool of the current service is at risk, issue an early warning, do not directly adopt the real-time optimal number of connections, and perform secondary optimization; when ASI>A2, determine that the connection pool of the current service is about to avalanche, which is a high-risk situation, reject the real-time optimal number of connections, and perform avalanche optimization. The three levels of safety, early warning, and high risk use different strategies for different risk levels, balancing performance and safety, and avoiding resource waste caused by conservative configurations and failures caused by aggressive configurations.

[0028] S600: When the connection pool is safe, use the real-time optimal number of connections to generate an adjustment strategy; set up a secondary optimization mechanism, and when the connection pool is at risk, use the secondary optimization mechanism to optimize the real-time optimal number of connections and output the safe number of connections; The specific steps of using the real-time optimal number of connections to generate an adjustment strategy are as follows: S601: Input the real-time optimal number of connections into the PID controller to smoothly deliver the configuration, specifically: ΔP=K p ×(P opt -P current )+K i ×∫(P opt -P current )dt In the formula, ΔP represents the adjusted number of connections, K p represents the proportional coefficient, K i represents the integral coefficient, P current represents the current configured maximum capacity limit; Use the adjusted number of connections to form an adjustment strategy and deliver it to the connection pool; S602. The secondary optimization mechanism specifically involves introducing a security attenuation factor β, and using this factor to perform secondary optimization on the real-time optimal number of connections to obtain the theoretical number of secure connections. The formula is as follows: The=P current +β×(P opt -P current ); In the formula, The represents the theoretical number of secure connections; the minimum number of idle connections in the connection pool is collected, and the minimum value between the minimum number of idle connections and the theoretical number of secure connections is selected as the output number of secure connections. The security attenuation factor is calculated using the total number of occupied connections, the current maximum configured capacity limit, and the maximum number of database connections, specifically: ; In the formula, ρ safe represents the global safety water level coefficient, which is set to a fixed value by the staff, with a range of (0.75, 0.85); k represents the reaction sensitivity index; 0.2 is used as the minimum limit of the safety decay factor, allowing 20% ​​of the model adjustment range to be retained even if the system is extremely dangerous, to prevent the system from completely freezing; the range of the safety decay factor is [0.2, 1]. The number of secure connections is input into the PID controller and the configuration is smoothly distributed to obtain the adjusted number of connections after secondary optimization. This constitutes the adjustment strategy and is then distributed to the connection pool.

[0029] S700: Construct an avalanche optimization strategy; when it is determined that the connection pool of the current service is about to experience an avalanche, execute avalanche optimization. The avalanche optimization specifically refers to: Instead of directly discarding the real-time optimal number of connections, we optimize the current maximum capacity limit using the avalanche exponent, with the formula: Py=P current ×(1-e×(ASI-0.7) / 0.3), where e represents the contraction strength coefficient, Py represents the optimized maximum capacity limit of the current configuration, and the calculation result is rounded down; the maximum value of the minimum idle number of connections in the connection pool and the optimized maximum capacity limit of the current configuration is selected as the number of connections to be contracted urgently, P. shrink ; When P shrink ≥P current In this case, no adjustments will be made, but a high-risk alarm log will be recorded. When P shrink <P current At this time, the number of connections in the connection pool is directly set to the number of connections for emergency contraction, without using a PID controller.

[0030] In high-risk situations, the predicted value is discarded directly, and connections are quickly reduced to immediately alleviate database pressure and break the chain of "connection exhaustion → database blocking → service avalanche". After reduction, core services are still available and there will be no complete system crash, minimizing business losses. The reduction range is automatically calculated based on the Avalanche Index (ASI), and the greater the risk, the more it is reduced, resulting in precise hemostasis. Example:

[0031] This embodiment uses order service under a microservice architecture as the business scenario, and the database is MySQL 8.0, with the following parameters set: Maximum number of database connections R max =1000; Current service connection pool current configuration limit P current =80; Minimum number of idle connections P in the connection pool min =10; Upstream gateway maximum queuing capacity U max =500; Global safety water level coefficient ρ safe =0.8; The lower limit of the safety attenuation factor is 0.2; Level 3 threshold access control: A1=0.3, A2=0.7; Sampling period Δt = 5s; A three-level water level data collection mechanism has been activated, collecting full-link indicators every 5 seconds: Downstream water level CPU utilization is 65%, active threads are 180, and cumulative slow queries are 12. Local active connections: 62; wait queue length: 14; average SQL execution time: 220ms; actual effective concurrency: L. t =62+14=76; The upstream water level currently has a QPS of 280, the previous cycle's QPS was 240, the gateway response time is 310ms, and the backlog of requests is 110; all collected data is preprocessed. Upstream flow trend slope T t =(280-240) / 5=8; The correction function f = min(280 × 0.3, 1000) = 84; Substituting into the prediction formula (taking α=0.5, γ=0.4), P opt (t+1)=76+0.5×8+0.4×84=113.6→rounded to 114, that is: the optimal number of connections for the next cycle is 114.

[0032] Query the total number of connections used by other services, P other =780; Downstream overload risk F D=(780+114) / 1000=0.894; Upstream backlog risk F U =110 / 500=0.22; Dynamic fusion weight W db =0.894 / (0.894+0.22)≈0.803, W up =0.22 / (0.894+0.22)≈0.197; The Avalanche Index (ASI) is calculated as follows: ASI = (0.894² + 0.22²) / (0.894 + 0.22) ≈ 0.761 ASI=0.761>A2=0.7; Since it has been determined to be high-risk, skip the normal adjustment and secondary optimization and enter the S700 avalanche optimization.

[0033] The current capacity is shrunk according to the avalanche index, with a shrinkage force coefficient e=1.0, Py=80×(1-1.0×(0.761-0.7) / 0.3)=80×(1-0.203)≈63.76→rounded to 63; Calculate the number of emergency contraction connections P shrink =max(P min Py) = max(10, 63) = 63; Execution strategy P shrink =66<P current =80, directly set the maximum number of connections in the connection pool to 63, without using PID smoothing, and it will take effect immediately.

[0034] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered in all respects as exemplary and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.

Claims

1. A data source connection pool adaptive adjustment method utilizing an intelligent model, characterized in that: The method comprises the following steps: S100: Set up a three-level water level collection mechanism in the data source connection pool, and collect the real database load, connection pool status and business characteristics, and business entry pressure and tolerance respectively through the three-level water level collection mechanism; The three-level water level collection mechanism includes three levels: downstream water level, local water level and upstream water level. The downstream water level is responsible for the real database load, which includes CPU usage, number of active threads, and cumulative number of slow queries. The local water level is responsible for the connection pool status and business characteristics, which include the number of active connections, length of the waiting queue, and average query SQL time consumption. The upstream water level is responsible for the business entry pressure and tolerance, which include the number of requests per second, gateway response time, and number of backlogged requests; S200: Preprocess all collected data, including spatiotemporal alignment, null value filling, and mutation smoothing, and construct a periodic feature structure; S300: Construct an intelligent dynamic connection pool prediction model by using different water level data collected by the three-level water level collection mechanism, to predict the real-time optimal number of connections of the connection pool; S400: After predicting the real-time optimal number of connections of the connection pool, query the total number of occupied connections of other services except the current service through the database, and calculate the downstream overload risk of the current service by using the total number of occupied connections and the real-time optimal number of connections; calculate the upstream backlog risk by using the number of backlogged requests and the maximum queuing capacity of the upstream gateway of the current service; fuse the downstream overload risk and the upstream backlog risk to obtain an avalanche index; The specific step of fusing the downstream overload risk and the upstream backlog risk to obtain the avalanche index is as follows: Dynamic fusion weights of W are configured to address both downstream overload risk and upstream backlog risk. db and W up W db =F D / (F D +F U ), W up =F U / (F D +F U ); Utilizing fusion weights to mitigate downstream overload risk F D and upstream backlog risk F U The avalanche index is obtained by fusion, specifically: ; In the formula, ASI represents the avalanche index; S500: Set a three-level threshold gate for the avalanche index, and use the three-level threshold gate to judge the avalanche index, so as to determine whether the connection pool of the current service has an avalanche risk; S600: When the connection pool is safe, generate an adjustment strategy by using the real-time optimal number of connections; set up a secondary optimization mechanism, and when the connection pool has a risk, use the secondary optimization mechanism to optimize the real-time optimal number of connections and output a safe number of connections; S700: Construct an avalanche optimization strategy, and execute avalanche optimization when it is determined that an avalanche is about to occur in the connection pool of the current service.

2. The data source connection pool adaptive adjustment method using an intelligent model according to claim 1, characterized in that: The specific steps for predicting the real-time optimal number of connections of the connection pool in S300 are as follows: S301: Construct an intelligent dynamic connection pool prediction model by adopting a lightweight exponential weighted regression model, and define the real-time optimal number of connections in the intelligent dynamic connection pool prediction model as: P opt (t+1)=L t +α×T t +γ×f(U qps (t),R running (t)); In the formula, P opt (t+1) represents the predicted optimal number of connections the connection pool should be configured for in the real-time next cycle; L t T represents the actual effective concurrency at the current moment, α represents the trend smoothing coefficient, and T represents the actual effective concurrency at the current moment. t γ represents the upstream flow trend slope, γ represents the downstream load penalty factor, and f(U) qps (t), R running (t) represents the correction function, U qps (t) represents the number of requests per second, R running (t) represents the number of active threads; S302, the actual effective concurrency = number of active connections + waiting queue length, and the upstream traffic trend slope is calculated based on the number of requests per second in adjacent periods, specifically: U qps (t-1) represents the number of requests per second in the previous cycle, and Δt represents the time difference between adjacent cycles; The correction function is specifically defined as: f = min(U qps (t) × response time base value, maximum number of database connections), input U in the correction function qps (t) Calculate the theoretical upper limit of connectivity, then input R running (t), using the theoretical connection limit minus the number of active threads R running (t) yields the final number of allowed connections.

3. The adaptive adjustment method for data source connection pools using an intelligent model according to claim 1, characterized in that: The specific step of setting the three-level threshold gate in S500 is as follows: The preset three-level threshold gate is (A1, A2), where A2 > A1, A1 represents a safety threshold, and A2 represents a risk threshold. When ASI ≤ A1, it is judged that the connection pool of the current service is safe, and the real-time optimal number of connections is directly adopted. When A1 < ASI ≤ A2, it is judged that the connection pool of the current service has a risk, an early warning is issued, the real-time optimal number of connections is not directly adopted, and secondary optimization is performed. When ASI > A2, it is judged that the connection pool of the current service is about to avalanche, which is a high-risk situation, the real-time optimal number of connections is rejected, and avalanche optimization is performed.

4. The adaptive adjustment method for data source connection pools using an intelligent model according to claim 2, characterized in that: The S600 uses the real-time optimal connection number generation and adjustment strategy as follows: The optimal number of connections in real time is input into the PID controller for smooth configuration distribution, specifically as follows: △P=K p × (P opt -P current )+K i ×∫(P opt -P current )dt In the formula, △P represents the number of adjusted connections, and K p K represents the proportionality coefficient. i P represents the integral coefficient. current This indicates the current maximum capacity limit; the adjustment strategy is formulated by adjusting the number of connections and then sent to the connection pool.

5. The adaptive adjustment method for data source connection pools using an intelligent model according to claim 4, characterized in that: The secondary optimization mechanism in S600 is specifically as follows: Introducing a safety attenuation factor β, the theoretical safe connection number is obtained by secondary optimization of the real-time optimal connection number using the safety attenuation factor. The minimum idle connection number of the connection pool is collected, and the minimum value between the minimum idle connection number and the theoretical safe connection number is selected as the output safe connection number. The security attenuation factor is calculated using the total number of occupied connections, the current maximum configured capacity limit, and the maximum number of database connections, specifically: ; In the formula, ρ safe represents the global safety water level coefficient, set as a fixed value by staff, with a range of (0.75, 0.85); k represents the reaction sensitivity index; 0.2 is used as the minimum limit for the safety attenuation factor, with a range of [0.2, 1]; P other R indicates the total number of connections already in use. max This indicates the maximum number of database connections. The number of secure connections is input into the PID controller and the configuration is smoothly distributed to obtain the adjusted number of connections after secondary optimization. This constitutes the adjustment strategy and is then distributed to the connection pool.

6. The data source connection pool adaptive adjustment method using an intelligent model according to claim 4, characterized in that: The avalanche optimization in the S700 specifically refers to: Instead of directly discarding the real-time optimal number of connections, the system optimizes the current maximum capacity limit using the avalanche index, selecting the maximum value of the minimum idle connections in the connection pool and the optimized current maximum capacity limit as the emergency shrinkage connection number P. shrink ; When P shrink ≥P current In this case, no adjustments will be made, but a high-risk alarm log will be recorded. When P shrink <P current At this time, the number of connections in the connection pool is directly set to the number of connections for emergency contraction, without using a PID controller.

Citation Information

Patent Citations

  • Connection management method and device for multiple data sources, storage medium and electronic equipment

    CN117478746A

  • Parking lot entrance and exit control system based on Internet of Things

    CN121122022A