Encryption machine connection management method and system

By randomly arranging and dynamically detecting the encryption machine connection pool, the problems of single point of failure and resource waste in traditional encryption machine connection management are solved, achieving load balancing and efficient resource utilization, and improving the reliability and performance of the system.

CN121887384APending Publication Date: 2026-04-17FUJIAN CENTM INFORMATION
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
FUJIAN CENTM INFORMATION
Filing Date
2025-12-22
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Traditional encryption machine connection management suffers from single point of failure risk, low resource utilization, and unbalanced load, leading to system interruptions and resource waste.

Method used

By obtaining the original connection pool, randomly arranging the sub-connection pools, traversing and detecting idle connections, prioritizing the use of idle connections to process transaction requests, and creating new connections when there are no idle connections, combined with timeout detection and fault isolation mechanisms, load balancing and resource optimization are achieved.

Benefits of technology

It improves the utilization rate of encryption machine connection resources, reduces the risk of single point of overload, shortens transaction response time, and ensures the reliability and efficiency of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121887384A_ABST
    Figure CN121887384A_ABST
Patent Text Reader

Abstract

The invention discloses an encryption machine connection management method and system. The method comprises the steps that in response to a transaction request, an original connection pool is acquired, the original connection pool comprises at least two sub-connection pools, and each sub-connection pool comprises all connections on the same encryption machine; randomly arranging the at least two sub-connection pools to obtain a target connection pool; traversing and detecting whether idle connection exists in the sub-connection pools in the target connection pool or not; and if the idle connection exists in the currently traversed current sub-connection pool, acquiring the idle connection from the current sub-connection pool, and processing the transaction request based on the idle connection. According to the invention, the existing connection can be effectively reused, so that the utilization rate of connection resources and the overall performance of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of connection management technology, and in particular to a method and system for managing encryption machine connections. Background Technology

[0002] In the financial payment field, the Hardware Security Module (HSM), often referred to as a cryptographic device, is a core security device that performs sensitive cryptographic operations. Its connection management faces the following shortcomings.

[0003] First, traditional connectivity management faces the risk of a single point of failure. Without sufficient redundancy, any failure of a single HSM or its connectivity management component can lead to a complete system outage, resulting in severe business disruptions and financial losses.

[0004] Secondly, connection resource utilization is low. Traditional connection management methods often fail to effectively reuse and optimize HSM connection resources, leading to unnecessary resource waste. For example, HSM has limited connection carrying capacity, and the connection status check interval may be long. This can cause connection resources to be quickly exhausted under improper connection management, thereby affecting the establishment of new connections and the overall service availability.

[0005] Finally, there is the issue of load imbalance. In a multi-encryption machine deployment environment, requests may be unevenly distributed across different devices, causing some HSMs to be overloaded while others remain idle, thus failing to fully utilize the overall performance of the cluster. Summary of the Invention

[0006] The technical problem to be solved by the present invention is to provide a management method and system for encryption machine connections, which can effectively reuse existing connections, thereby improving the utilization rate of connection resources and the overall performance of the system.

[0007] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows: A method for managing encryption machine connections includes: In response to a transaction request, an original connection pool is obtained, the original connection pool comprising at least two sub-connection pools, each of the sub-connection pools comprising all connections on the same encryption machine; The at least two sub-connection pools are randomly arranged to obtain the target connection pool; Iterate through and check if there are any idle connections in the sub-connection pools of the target connection pool; If there is an idle connection in the current sub-connection pool, then the idle connection is obtained from the current sub-connection pool, and the transaction request is processed based on the idle connection.

[0008] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is as follows: A management system for encrypted machine connections includes a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, it implements the various steps of the aforementioned management method for encrypted machine connections.

[0009] The beneficial effects of this invention are as follows: Upon responding to a transaction request, the original connection pool is obtained, where each sub-connection pool corresponds to all connections of a single encryption machine. Connections are divided according to the physical devices of the encryption machines, providing a foundation for subsequent load balancing and achieving fault isolation. The sub-connection pools are randomly arranged to generate the target connection pool. Randomization breaks the fixed-order access pattern, preventing concentrated requests from accessing specific encryption machines, thereby reducing the risk of single-point overload and achieving dynamic load balancing among multiple devices. The sub-connection pools in the target connection pool are traversed and checked for idle connections. By dynamically checking the connection status rather than relying on a fixed allocation strategy, the actual usage of connection resources can be adapted in real time, prioritizing the reuse of idle connections to reduce the overhead of creating new connections and improve resource utilization. When an idle connection is detected in the current sub-connection pool, that connection is used directly to process the request, prioritizing the use of existing resources, reducing the load on the encryption machine, and shortening the response time of transaction requests. Attached Figure Description

[0010] Figure 1 A flowchart of a method for managing encryption machine connections according to the present invention; Figure 2 This is a flowchart of a method for creating an initial connection pool according to the present invention; Figure 3 This is a schematic diagram of an encryption machine configuration file according to the present invention; Figure 4 This is a schematic diagram of the architecture of a primitive connection pool according to the present invention; Figure 5 This is a schematic diagram illustrating the connection between an application system of the present invention and multiple encryption machines; Figure 6 This is a flowchart of a method for obtaining an encryption machine connection according to the present invention; Figure 7 This is a flowchart of a dynamic adjustment method for a sub-connection pool according to the present invention; Figure 8 This is a schematic diagram of the structure of a management system for connecting an encryption machine according to the present invention; Label Explanation: 100. A management system for connecting to an encryption machine; 101. A memory; 102. A processor. Detailed Implementation

[0011] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.

[0012] Embodiments of the present invention provide a method for managing encryption machine connections, comprising: In response to a transaction request, an original connection pool is obtained, the original connection pool comprising at least two sub-connection pools, each of the sub-connection pools comprising all connections on the same encryption machine; The at least two sub-connection pools are randomly arranged to obtain the target connection pool; Iterate through and check if there are any idle connections in the sub-connection pools of the target connection pool; If there is an idle connection in the current sub-connection pool, then the idle connection is obtained from the current sub-connection pool, and the transaction request is processed based on the idle connection.

[0013] As described above, the beneficial effects of this invention are as follows: When responding to a transaction request, the original connection pool is obtained, where each sub-connection pool corresponds to all connections of a single encryption machine. Connections are divided according to the physical devices of the encryption machines, providing a foundation for subsequent load balancing and achieving fault isolation. The sub-connection pools are randomly arranged to generate the target connection pool. Randomization breaks the fixed-order access pattern, preventing concentrated requests from accessing specific encryption machines, thereby reducing the risk of single-point overload and achieving dynamic load balancing among multiple devices. The sub-connection pools in the target connection pool are traversed and checked for idle connections. By dynamically checking the connection status rather than relying on a fixed allocation strategy, the actual usage of connection resources can be adapted in real time, prioritizing the reuse of idle connections to reduce the overhead of creating new connections and improve resource utilization. When an idle connection is detected in the current sub-connection pool, that connection is used directly to process the request, prioritizing the use of existing resources, reducing the load pressure on the encryption machine, and shortening the response time of the transaction request.

[0014] Furthermore, it also includes: If none of the sub-connection pools in the target connection pool have idle connections, a new connection is created in the last traversed sub-connection pool, and the transaction request is processed based on the new connection.

[0015] As described above, when all sub-connection pools are found to have no free connections, the last traversed sub-connection pool is selected as the creation node. This last sub-connection pool belongs to a specific encryption machine within the randomly arranged target connection pool, avoiding load imbalance caused by adding connections to a single encryption machine. By creating a new connection in this last sub-connection pool, the load balancing characteristic brought by random arrangement is maintained, while also achieving dynamic expansion of connection resources. The creation of a new connection is directly related to the processing requirements of the current transaction request, ensuring that a valid connection can be established in a timely manner even when resources are scarce, avoiding transaction failures or timeouts due to connection pool overload.

[0016] Furthermore, traversing and detecting whether there are idle connections in the sub-connection pools of the target connection pool list includes: If there is an idle connection in the current sub-connection pool being traversed, a preset encryption machine status query instruction is sent based on the idle connection, and the availability of the idle connection is verified according to the response information received corresponding to the encryption machine status query instruction. If the idle connection is available, the idle connection is obtained from the current sub-connection pool, and the transaction request is processed based on the idle connection; If the idle connection is unavailable, it is removed from the current sub-connection pool, and the process continues to traverse other sub-connection pools in the target connection pool.

[0017] As described above, sending a preset encryption machine status query command triggers real-time communication with the underlying hardware device. The command response information accurately determines whether the current connection has the capability to process transactions normally. This verification method based on dynamic response reflects real-time availability better than static connection status marking. When verification finds an unavailability, a removal operation is immediately performed, preventing subsequent transactions from continuing to use invalid connections and causing processing failures. Furthermore, by dynamically maintaining the health of the connection pool, the overall effectiveness of connection resources is improved. The entire process is completed before transaction request processing, ensuring the timeliness of the transaction process and fundamentally resolving the risk of business interruption caused by invalid connections in the connection pool.

[0018] Furthermore, the number of idle connections in each of the sub-connection pools is obtained according to a preset period; If the number of idle connections is detected to be greater than the number of configured connections in the corresponding sub-connection pool, then the excess idle connections are removed from the corresponding sub-connection pool. If the number of idle connections is detected to be less than the configured number of connections in the corresponding sub-connection pool, then the total number of connections in the corresponding sub-connection pool is obtained, and a new connection is created in the corresponding sub-connection pool when the total number of connections is less than the preset maximum number of connections.

[0019] As described above, firstly, obtaining the number of idle connections in each sub-connection pool allows for real-time monitoring of the resource status of each encryption machine, providing a data foundation for subsequent adjustments. When the number of idle connections exceeds the configured limit, removing redundant connections avoids resource waste and reduces performance issues caused by excessive idle connections consuming system resources. When there are insufficient idle connections, by checking whether the total number of connections has not reached the maximum limit, new connections are created within the allowed range, ensuring the minimum available resources of the connection pool while preventing system overload due to unlimited creation. By combining the dual judgment of the number of idle connections and the total number of connections, dynamic control of the connection pool size is achieved during system operation, enabling the system to automatically optimize the connection pool status based on real-time feedback without downtime, thus improving system operation and maintenance efficiency.

[0020] Furthermore, it also includes: If the creation of the new connection fails, the sub-connection pool will be configured as unavailable. The process of traversing and detecting whether there are idle connections in the sub-connection pools of the target connection pool includes: Skip the sub-connection pools that are configured to be unavailable during traversal.

[0021] As described above, firstly, by marking failed sub-connection pools as unavailable, faulty nodes are actively isolated, preventing subsequent transaction requests from attempting to access the unavailable encryption machine, thereby reducing system resource consumption caused by invalid connection attempts. Secondly, unavailable sub-connection pools are forcibly skipped during the traversal and detection process, which improves connection pool traversal efficiency and prevents response delays caused by repeated detection of failed nodes. By marking unavailable states and skipping traversal, the system's reliability is ensured while optimizing the global scheduling efficiency of connection resources.

[0022] Furthermore, before obtaining the original connection pool, the following is also included: Obtain the hardware configuration parameters of all encryption machines, including encryption machine address information and encryption machine connection information; Generate an encryption machine configuration file based on the hardware configuration parameters; Based on the encryption machine configuration file, sub-connection pools corresponding to the hardware configuration parameters of each encryption machine are created to obtain the original connection pool.

[0023] As described above, the system first obtains hardware configuration parameters such as the encryption machine address and connection information to ensure that the connection configuration information perfectly matches the physical devices, avoiding connection anomalies caused by manual configuration errors. Then, a standardized encryption machine configuration file is generated, converting heterogeneous hardware parameters into a unified format, providing data support for the subsequent automated creation of connection pools. Finally, based on the configuration file, a dedicated sub-connection pool is independently created for each encryption machine, achieving a one-to-one correspondence between physical devices and logical connection pools, and laying the foundation for load balancing through the subsequent random arrangement of sub-connection pools. This hierarchical configuration mechanism allows the system to dynamically adapt to the hardware environment of different encryption machine clusters. When adding or replacing encryption machines, only the configuration file needs to be updated to complete the connection pool reconstruction, significantly improving the system's maintainability and scalability.

[0024] Furthermore, it also includes: Obtain the timeout thresholds for the at least two sub-connection pools; When the time to acquire an idle connection or create a new connection exceeds the timeout threshold, the operation of acquiring an idle connection or creating a new connection is terminated, and a timeout message is returned.

[0025] As described above, the timeout threshold for acquiring sub-connection pools provides a time benchmark for subsequent operations, enabling the system to set differentiated timeout judgment criteria based on the configuration differences of specific sub-connection pools. When the operation time exceeds the threshold, the connection acquisition or creation process is proactively terminated, avoiding thread blocking and system resource consumption caused by long waiting times. Simultaneously, returning a timeout message triggers the system to execute an exception handling procedure, preventing cascading problems caused by a single connection pool failure. This dual control mechanism ensures the timeliness of connection management operations and enhances the system's fault tolerance for abnormal scenarios through the timeout feedback mechanism.

[0026] Furthermore, it also includes: If the transaction request is successfully processed, the idle connection is returned to the corresponding sub-connection pool. If the transaction request fails to process, the idle connection is marked as a failed connection and removed from the corresponding sub-connection pool.

[0027] As described above, when a transaction request is successfully processed, returning idle connections to the corresponding sub-connection pool ensures the cyclical reuse of valid connections, avoiding the overhead of repeatedly creating new connections. Conversely, when a transaction request fails, the mechanism of marking idle connections as invalid and removing them promptly identifies and eliminates abnormal connections, preventing them from continuing to occupy system resources. These two differentiated processing methods ensure both the effective utilization of normal connection resources and eliminate the risk of cascading errors caused by invalid connections, thus maintaining the stability and reliability of the connection pool from its root cause.

[0028] Furthermore, it also includes: The idle time of idle connections in each of the sub-connection pools is detected according to a preset period; If the idle time of the idle connection is detected to exceed a preset idle time threshold, the idle connection will be removed from the corresponding sub-connection pool.

[0029] As described above, the idle time of idle connections in the sub-connection pool is detected according to a preset period. This periodic detection mechanism ensures the timeliness of resource status updates and avoids resource stagnation caused by excessively long detection intervals. When the idle time of an idle connection exceeds a preset threshold, the connection is automatically removed. This threshold balances connection reuse efficiency with resource release requirements, preventing long-term unused idle connections from continuously occupying encryption machine resources. Through the synergistic effect of the preset period and the idle time threshold, the availability of valid connections in the connection pool is guaranteed, while the systematic cleanup of invalid or inefficient connections is achieved, thereby improving the overall utilization efficiency of connection resources.

[0030] Another embodiment of the present invention provides a management system for encrypted machine connections, including a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, it implements the various steps in the above-described method for managing encrypted machine connections.

[0031] The embodiments of the present invention provide a method and system for managing encryption machine connections, applicable to scenarios with multiple encryption machines. It can effectively reuse existing encryption machine connections, thereby improving the utilization rate of encryption machine connection resources and the overall performance of the system. Specific embodiments are described below: Please refer to Figures 1 to 6 One embodiment of the present invention is as follows: like Figure 1 As shown, a management method for encryption machine connection includes steps S10-S40.

[0032] S10. In response to the transaction request, obtain the original connection pool, which includes at least two sub-connection pools, each of which includes all connections on the same encryption machine.

[0033] Specifically, such as Figure 2 As shown, before step S10, the method further includes steps S1010-S1030.

[0034] S1010. Obtain the hardware configuration parameters of all encryption machines, including encryption machine address information and encryption machine connection information.

[0035] The encryption machine address information includes the encryption machine's network address and port number, which can be obtained from the device management interface using automated data collection tools to ensure that the connection information completely matches the actual encryption machine. The encryption machine connection information includes the configured number of connections and timeout thresholds. The configured number of connections includes the minimum number of idle connections, the maximum number of idle connections, and the maximum number of connections, which can be configured according to the encryption machine's hardware resources and the actual application scenario.

[0036] S1020: Generate the encryption machine configuration file based on the hardware configuration parameters.

[0037] The encryption machine configuration file refers to a text file that converts the collected encryption machine hardware parameters into a standardized format. Specifically, it can be stored in JSON format to unify the parameter expression of different encryption machines.

[0038] In a specific application scenario, the system has three encryption machines (HSMs): HSM1, HSM2, and HSM3. HSM1 has a network address of 192.168.1.101 and port 8081; HSM2 has a network address of 192.168.1.102 and port 8082; and HSM3 has a network address of 192.168.1.103 and port 8083. Furthermore, the timeout threshold for all three machines is 5000 seconds, the maximum number of connections is 100, the minimum number of idle connections is 10, and the maximum number of idle connections is 50. Based on these hardware configuration parameters, an encryption machine configuration file HSMList is generated as follows: Figure 3 As shown, ip represents the network address, port represents the port number, connect_timeout represents the timeout threshold, max_connections represents the maximum number of connections, min_idle_connections represents the minimum number of idle connections, and max_idle_connections represents the maximum number of idle connections.

[0039] S1030. Based on the encryption machine configuration file, create sub-connection pools corresponding to the hardware configuration parameters of each encryption machine to obtain the original connection pool.

[0040] A sub-connection pool refers to an independent set of connection resources established for a single encryption machine. Each sub-connection pool corresponds to the connection resources of only one encryption machine. Encryption machines with the same hardware specifications have the same encryption machine connection information in their corresponding sub-connection pools. If the encryption machines have different hardware specifications, sub-connection pools are created according to the encryption machine connection information corresponding to the actual performance of the encryption machines. The original connection pool refers to a set divided according to the encryption machine connection resource set. The original connection pool contains at least two sub-connection pools, and each sub-connection pool contains multiple connections corresponding to the encryption machine.

[0041] In a specific application scenario, the encryption machine configuration file contains hardware configuration parameters for n encryption machines. The initial connection pool created based on this configuration file is as follows: Figure 4 As shown, the original connection pool includes n sub-connection pools, namely pool1, pool2, ..., pooln, where n is a positive integer greater than or equal to 2. The application system implements a multi-encryption machine connection architecture based on this original connection pool as follows: Figure 5 As shown.

[0042] like Figure 6 As shown, in step S20, at least two sub-connection pools are randomly arranged to obtain the target connection pool.

[0043] Random arrangement refers to shuffling the access order of the sub-connection pools. Specifically, it can be implemented using the Fisher-Yates shuffling algorithm to eliminate resource imbalance caused by fixed access patterns.

[0044] S30. Traverse and check if there are any idle connections in the sub-connection pools of the target connection pool.

[0045] The traversal detection refers to sequentially checking each sub-connection pool for idle connections according to the random arrangement in step S20 above. Idle connections are connections in an allocable state, which can be marked by connection status identifiers, thereby enabling rapid identification and reuse of connection resources.

[0046] Specifically, step S30 includes steps S301-S302.

[0047] S301. If there is an idle connection in the current sub-connection pool that is being traversed, a preset encryption machine status query instruction is sent based on the idle connection, and the availability of the idle connection is verified according to the response information corresponding to the encryption machine status query instruction received. If the idle connection is available, step S40 is executed; if the idle connection is not available, step S302 is executed.

[0048] The encryption machine status query command refers to a standardized set of commands used to detect the operating status of the encryption machine. This command interaction confirms the real-time communication capability between the encryption machine and the connection channel. Verifying the availability of an idle connection based on the response information involves performing a validity check on the response data returned by the encryption machine. This can be achieved by parsing the status codes in the response message to determine whether the connection is in a state where it can normally process transaction requests.

[0049] In a specific application scenario, the encryption machine status query command can adopt either the system information query command or the status query command from the standardized command set. The system information query command is used to request the return of the encryption machine's system version information. Its request and response data volume is small, and it does not involve time-consuming encryption and decryption operations. It can verify the encryption machine's operating status without causing significant performance consumption. The command format (input field) and response format (output field) are shown in Tables 1 and 2.

[0050] Table 1. Response information for system information query commands and normal responses.

[0051] Table 2 Response Information for System Information Query Commands and Anomaly Responses

[0052] The input field indicates that the command is 1 byte long, of type hexadecimal (H), and has a value of 0x00. The output field (normal response) indicates that the response code is 1 byte long, of type ASCII (A), and has a value of A. This continues with the version, protocol, and revision date. The output field (error response) indicates that the response code is 1 byte long, of type ASCII (A), and has a value of E; it also records the error code to indicate the type of error.

[0053] The status query command is used to return detailed status information of the encryption machine. The command format and response format are as follows: The instruction format includes a message header, command code, mode flag, termination separator, and message trailer. The message header is a variable-length ASCII character and is returned to the host as is. The command code is a 2-byte ASCII character with a value of "NO". The mode flag is a 2-byte hexadecimal character used to specify the mode of the returned information; for example, 00: return status information, 01~FF: reserved for future expansion. The termination separator is a 1-byte control character with a value of X'19' (optional, appears only if a message trailer exists). The message trailer is a variable-length ASCII character, with a maximum of 32 characters (optional).

[0054] The response format includes a message header, response code, error code, termination separator, and message trailer. The response code is a 2-byte ASCII character with a value of "NP". The error code is a 2-byte number (N), for example, 00: no error, 13: LMK error (requires reporting to administrator), 15: input data error. Status information fields in mode "00" can include I / O buffer size, Ethernet type, number of TCP sockets, firmware number, DSP match, and DSP firmware number. The I / O buffer size is a 1-byte number representing the buffer size (0=2K, 1=8K, 2=16K, 3=32K). The Ethernet type is a 1-byte number representing the connection type (0=UDP, 1=TCP). The number of TCP sockets is a 1-byte number representing the number of sockets set. The firmware number is a 9-byte ASCII character in the format XXXX-XXXX. The DSP match is a 1-byte number (0=No, 1=Yes). The DSP firmware number is a 4-byte ASCII character.

[0055] Based on the above description, one of the above instructions is sent through an idle connection, and the status code in the returned response message is parsed to verify whether the connection is in a state where it can normally process transaction requests. If the status is a normal response (e.g., response code "A" or error code "00" indicates normal), then step 302 is executed. If the status code is an abnormal response (e.g., response code "E" or error code "LMK error" indicates abnormal), then step 303 is executed.

[0056] S302. Remove idle connections from the current sub-connection pool and continue traversing other sub-connection pools in the target connection pool.

[0057] In one alternative implementation, if there are multiple idle connections in the current sub-connection pool, the process continues to traverse other sub-connection pools in the target connection pool only when all idle connections in the current sub-connection pool are unavailable.

[0058] In a specific application scenario, the target connection pool has three sub-connection pools: pool1, pool2, and pool3, which are traversed in the following order: pool2, pool1, and pool3. Currently, when traversing to pool2, there is one idle connection. A system status query command is sent based on this idle connection. If the response message has a status code of E, it indicates that the idle connection is unavailable, so the traversal continues to pool1.

[0059] S40. If there is an idle connection in the current sub-connection pool, then obtain the idle connection from the current sub-connection pool and process the transaction request based on the idle connection.

[0060] In a specific application scenario, steps S10-S40 are as follows: When a transaction request arrives, the system first obtains the pre-established original connection pool, which contains three sub-connection pools: pool1, pool2, and pool3. Each sub-connection pool strictly corresponds to all connections of a specific encryption machine. This physical isolation design avoids chaotic cross-device connection management. The three sub-connection pools of the original connection pool are then randomly sorted, for example, the sub-connection pools of the three encryption machines are arranged in the order of pool2-pool1-pool3, breaking the fixed access order between devices. The system checks the sub-connection pools one by one in a random sequence. When an encryption machine has an idle connection, it means that the encryption machine is currently capable of processing the request immediately without establishing a new connection. Therefore, the system immediately allocates the idle connection of that encryption machine for use. This mechanism helps avoid forming local hotspots on specific encryption machines, ensuring that requests are evenly distributed across different encryption machines. For example, the first round of requests may preferentially use the HSM2 connection, and the next request may switch to the HSM3 connection, effectively distributing the device load pressure. It can also maximize the reuse rate of existing connections, thereby reducing latency and improving overall resource utilization efficiency.

[0061] The method also includes steps S50-S60.

[0062] S50. If the transaction request is successfully processed, the idle connection is returned to the corresponding sub-connection pool.

[0063] S60. If the transaction request processing fails, the idle connection is marked as a failed connection and removed from the corresponding sub-connection pool.

[0064] Idle connection relinquishment refers to re-inserting idle connections that have completed transaction processing and have not experienced any anomalies into the available queue of their respective sub-connection pools. This can be achieved through connection state reset and queue insertion operations, maintaining the reusability of normal connection resources. Failed connection removal refers to marking and destroying connections that experienced response timeouts, data verification failures, or encryption machine error codes during transaction processing. This can be achieved by triggering a connection pool update process through an anomaly detection mechanism, preventing failed connections from continuously consuming system resources.

[0065] In a specific application scenario, after a transaction request is successfully executed via an idle connection, the connection manager restores the connection's state attributes to their initial values ​​and adds it back to the available connection queue of its sub-connection pool, allowing subsequent transaction requests to directly reuse the connection. When a transaction request fails, the connection manager determines whether the connection is invalid based on preset error type identification rules. For example, if the encryption machine returns a hardware fault code or three consecutive data verification errors occur, the connection is immediately removed from the sub-connection pool and its network session is closed to prevent it from being reassigned to other transaction requests. By dynamically adjusting the connection state and resource distribution within the pool, only available connections are retained in the sub-connection pool, thereby improving resource utilization.

[0066] In a specific application scenario, to achieve effective management of the sub-connection pool, this application defines a generic connection pool interface, the specific structure of which is public interface HsmConnectionPool <t>This interface extends Serializable. It contains the following abstract methods: getHsmConnection(), which retrieves an available connection from the child connection pool; returnHsmConnection(T conn), which returns a used connection to the child connection pool for later reuse; and invalidateHsmConnection(T conn), which removes a connection that has failed due to a fault or other reason from the pool.

[0067] Therefore, in step S40, an available idle connection can be obtained from the current sub-connection pool using getHsmConnection(). In step S50, the used idle connection can be returned to the sub-connection pool using returnHsmConnection(T conn). In step S60, the invalidated connection can be removed from the corresponding sub-connection pool using invalidateHsmConnection(T conn).

[0068] Specifically, the method further includes step S70.

[0069] S70. If none of the sub-connection pools in the target connection pool have idle connections, a new connection is created in the last traversed sub-connection pool, and the transaction request is processed based on the new connection.

[0070] The last sub-connection pool refers to the last sub-connection pool traversed in the randomly arranged target connection pool. This can be implemented using a linked list or array structure to store the order. Creating a new connection means establishing a new communication link with the encryption machine within the corresponding sub-connection pool. This can be achieved by initiating a connection request by calling the encryption machine's interface. The creation of new connections is limited by the maximum number of connections allowed in the sub-connection pool to prevent excessive resource consumption.

[0071] In a specific application scenario, step S70 above is as follows: The system checks the sub-connection pools one by one in a random sequence. When it finds that there are no idle connections in all encryption machines, the system falls back to the end connection pool as the target node for creating a new connection. Before creating a new connection in the end connection pool, it needs to determine whether the total number of connections in the end connection pool is greater than the maximum number of connections. If not, it attempts to create a new connection; if so, it returns a connection acquisition failure message. If the first attempt to create a new connection fails, it can repeatedly attempt to create a new connection within a limited time and a limited number of attempts. In this way, it ensures that even in extreme cases (such as when all HSMs are under high load), it can still attempt to acquire a connection, although it may need to wait for existing connections to be released or for new connections to be created, thus guaranteeing the continuous availability of the service.

[0072] The encryption machine connection management method of this application achieves load balancing of multiple encryption machine connections through "random sorting + idle priority" and effectively improves resource utilization. This method is a deep optimization for the characteristics of HSM connections (high connection establishment cost and limited connection resources). It not only achieves random distribution of load, but more importantly, by prioritizing the reuse of existing idle connections, it significantly reduces the overhead of establishing new connections, thereby reducing latency and improving the overall utilization of connection resources.

[0073] Please refer to Figure 7 Another embodiment of the present invention is as follows: A method for managing encryption machine connections, which differs from Embodiment 1 in that it is capable of monitoring and managing the connection status of sub-connection pools.

[0074] Specifically, such as Figure 7 As shown, the method further includes steps S80-S110.

[0075] S80. Obtain the number of idle connections in each sub-connection pool according to a preset period.

[0076] The preset period refers to a fixed time interval set by the system, which can be implemented using a timer triggering mechanism. Periodic checks ensure the real-time update of the connection pool status.

[0077] S90. If the number of idle connections is detected to be greater than the number of configured connections in the corresponding sub-connection pool, the excess idle connections are removed from the corresponding sub-connection pool.

[0078] Specifically, when the number of idle connections is detected to be greater than the maximum number of idle connections in the configured number of connections, the excess idle connections are removed from the sub-connection pool corresponding to that number of idle connections.

[0079] S110. If the number of idle connections is less than the configured number of connections in the corresponding sub-connection pool, the total number of connections in the corresponding sub-connection pool is obtained, and a new connection is created in the corresponding sub-connection pool when the total number of connections is less than the preset maximum number of connections.

[0080] Specifically, when the number of idle connections is less than the minimum number of idle connections in the configured number of connections and the total number of connections is less than the minimum number of connections, a new connection is created in the sub-connection pool corresponding to the number of idle connections.

[0081] Specifically, the method further includes step S120.

[0082] S120. If the creation of a new connection fails, the sub-connection pool is configured to be unavailable.

[0083] Specifically, configuring a sub-connection pool as unavailable means marking a sub-connection pool that failed to create a connection as disabled by setting a status identifier. This can be achieved using a boolean variable or an enumeration type field, for example, by setting the isAvailable property value to false in the sub-connection pool data structure.

[0084] After a sub-connection pool is configured as unavailable, if a recovery command is received for that sub-connection pool, the following steps a-c are executed. Step a: Check all unavailable sub-connection pools. Step d: In these unavailable sub-connection pools, attempt to create new connections with the configured connection count again, and check the validity of the new connections. Step c: If the new connection is successfully created and valid, configure the sub-connection pool to which the new connection belongs as available.

[0085] Step S30 further includes: skipping child connection pools configured as unavailable during traversal. Skipping during traversal refers to automatically filtering unavailable nodes during the child connection pool traversal detection process. This can be achieved by adding conditional statements to the traversal logic, such as adding an `if(pool.isAvailable)` condition.

[0086] In a specific application scenario, when a new connection creation failure is detected in a sub-connection pool, a status marking operation is immediately triggered to mark the pool as unavailable. At this time, the set of available sub-connection pools maintained by the system will be dynamically updated. During subsequent transaction request processing, when performing connection pool traversal operations, unavailable sub-connection pools will be automatically excluded through a pre-defined filtering mechanism. This mechanism allows the system to immediately stop initiating connection requests to the encryption machine when encountering a failure, and instead concentrate resources on connection detection to other available encryption machines.

[0087] Specifically, the method further includes steps S130-S140.

[0088] S130. Obtain the timeout thresholds for at least two sub-connection pools.

[0089] The timeout threshold refers to the maximum pre-set operation waiting time for each sub-connection pool. This can be implemented using a dynamic configuration strategy or a fixed value, such as dynamically adjusting the threshold range based on the encryption machine's response speed or network conditions. This threshold limits the duration of connection acquisition or creation operations, preventing system threads from being blocked due to infinite waiting.

[0090] S140. When the time to acquire an idle connection or create a new connection exceeds the timeout threshold, terminate the operation of acquiring an idle connection or creating a new connection, and return a timeout message.

[0091] Terminate operation and return timeout message. This means that when the operation takes longer than the threshold, the current process is actively interrupted. This can be achieved by triggering an interrupt signal or closing the connection handle, such as forcibly releasing the occupied system resources and generating a message containing an error code.

[0092] Specifically, the method further includes steps S150-S160.

[0093] S150, Detect the idle time of idle connections in each sub-connection pool according to a preset period.

[0094] Idle time refers to the duration during which an idle connection is not used. Specifically, it can be achieved by recording the timestamp of the last time the connection was used and calculating the current time difference, which is used to quantify the state of the connection not being utilized.

[0095] S160. If the idle time of an idle connection is detected to exceed a preset idle time threshold, the idle connection is removed from the corresponding sub-connection pool.

[0096] In a specific application scenario, a detection mechanism is triggered at preset intervals to calculate the idle time of all idle connections in the sub-connection pool. When the idle time of an idle connection exceeds a preset threshold, a connection removal operation is automatically triggered. This process dynamically maintains the number of valid connections in the connection pool, preventing long-term unused idle connections from continuously occupying encryption machine resources. For example, when the detection period arrives, the idle connections in the sub-connection pool are traversed, and each one's timestamp is compared with the threshold; if it exceeds the threshold, a removal operation is performed. Thus, only idle connections with actual usage value are retained in the connection pool, reducing the occupation of invalid resources.

[0097] Based on steps S80-S160 above, this application ensures that the application will not be blocked indefinitely when the HSM response is slow or unresponsive, but will receive timeout notifications in a timely manner and take appropriate measures by handling timeout connections. This application implements an automatic failover mechanism by configuring an unavailable sub-connection pool, which can quickly switch traffic to healthy devices when an HSM or connection failure is detected. This application implements abnormal state recovery; the system can attempt to automatically recover from various abnormal states, minimizing service interruption time. These monitoring and anomaly handling mechanisms provide the system with real-time insights into connection health and enable rapid action when problems are detected, minimizing service interruption.

[0098] This application supports flexible configuration management, allowing users to dynamically configure key parameters of multiple encryption machines' sub-connection pools, such as the maximum number of connections, the minimum number of idle connections, and connection timeout. In other words, this application allows modification of key parameters of sub-connection pools during system runtime, such as adjusting connection pool capacity or timeout, without restarting the service, greatly improving operational flexibility and efficiency. In actual operation, the load, network conditions, and application requirements of HSMs are constantly changing. Static configuration in these dynamic environments may lead to performance bottlenecks or suboptimal states. This application, by allowing dynamic adjustment of the configured connection count at runtime, enables the system to automatically optimize its behavior based on real-time feedback, without downtime or manual intervention. This not only improves system resilience but also effectively reduces operational costs and supports dynamic scaling. This dynamic adaptive capability is key to building highly available and highly scalable distributed systems. By deeply integrating configuration management with real-time monitoring, this application achieves system self-optimization in complex and dynamic environments, greatly improving system reliability and operational efficiency.

[0099] Please refer to Figure 8 Another embodiment of the present invention is as follows: A management system 100 for encrypted machine connections includes a memory 101, a processor 102, and a computer program stored on the memory 101 and running on the processor 102. When the processor 102 executes the computer program, it implements the various steps of the encrypted machine connection management method of the above embodiment.

[0100] In a specific application scenario, the processor adopts a layered architecture design, which includes: Interface layer: Defines standardized connection pool interfaces to ensure the system's universality and scalability, and supports future adaptation to different types of HSMs or connection protocols; Implementation layer: Provides the specific implementation of the basic functions of the connection pool and carries the core business logic of the system; Extension layer: Used to support extended implementations of specific protocols or HSM types, such as adapting to HSM-specific APIs from different vendors; Management level: Provides comprehensive configuration and monitoring functions, making it easier for system administrators to manage and optimize the system.

[0101] When the processor executes the computer program, it implements a method for managing encryption machine connections according to the above embodiments based on the following modules: Connection Pool Management Module: Responsible for the full lifecycle management of HSM connections, including connection acquisition, return, validity detection, and automatic recycling. This module is based on a generic interface design, supporting flexible configuration of parameters such as maximum number of connections, minimum number of idle connections, and connection timeout. It also introduces object pooling technology and a validity detection mechanism based on specific HSM commands to ensure efficient connection reuse and reliable resource release.

[0102] Load balancing module: Employs a composite strategy to intelligently distribute requests, ensuring load balancing across multiple encrypted machine connection pools. This module integrates automatic failover capabilities, automatically routing requests to healthy nodes when an HSM (Host Streaming Service) anomaly is detected, guaranteeing service continuity. Its core innovation lies in using a "random shuffling + idle priority" strategy, which avoids localized hotspots while maximizing the reuse of existing connections and reducing the overhead of establishing new connections.

[0103] Monitoring and Management Module: This module monitors the real-time status of all HSM connections and system performance metrics, including response time, throughput, and number of connections, and performs connection validity checks and processing. It provides real-time status insights for the system and is crucial data support for automatic fault detection and recovery.

[0104] Configuration management module: Supports flexible configuration of multiple encrypted machine addresses and various parameters of sub-connection pools, and has the ability to dynamically adjust at runtime, such as modifying the connection pool size or timeout in real time without restarting the service. This module supports integration with enterprise-level development frameworks such as Spring, reducing integration and operational complexity.

[0105] In addition, the exception handling mechanism, as a fundamental capability that runs through all modules, provides functions such as connection acquisition timeout control, automatic fault switching and recovery, ensuring that the system still has high robustness and rapid recovery capability when HSM service or network is abnormal.

[0106] This application utilizes a layered design to facilitate modularity and isolate faults, preventing errors in one module from easily propagating to the entire system and thus improving overall system stability. A comprehensive exception handling mechanism directly addresses various potential failure scenarios, from the connectivity layer to the system layer, ensuring rapid fault detection, isolation, and recovery. This combination of architecture and mechanism collectively constructs a highly robust system capable of withstanding complex failure modes.

[0107] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.< / t>

Claims

1. A management method for encryption machine connections, characterized in that, include: In response to a transaction request, an original connection pool is obtained, the original connection pool comprising at least two sub-connection pools, each of the sub-connection pools comprising all connections on the same encryption machine; The at least two sub-connection pools are randomly arranged to obtain the target connection pool; Iterate through and check if there are any idle connections in the sub-connection pools of the target connection pool; If there is an idle connection in the current sub-connection pool, then the idle connection is obtained from the current sub-connection pool, and the transaction request is processed based on the idle connection.

2. The method according to claim 1, characterized in that, Also includes: If none of the sub-connection pools in the target connection pool have idle connections, a new connection is created in the last traversed sub-connection pool, and the transaction request is processed based on the new connection.

3. The method according to claim 1, characterized in that, Iterating through the sub-connection pools in the target connection pool list to check if there are any idle connections includes: If there is an idle connection in the current sub-connection pool being traversed, a preset encryption machine status query instruction is sent based on the idle connection, and the availability of the idle connection is verified according to the response information received corresponding to the encryption machine status query instruction. If the idle connection is available, the idle connection is obtained from the current sub-connection pool, and the transaction request is processed based on the idle connection; If the idle connection is unavailable, it is removed from the current sub-connection pool, and the process continues to traverse other sub-connection pools in the target connection pool.

4. The method according to claim 1, characterized in that, Also includes: The number of idle connections in each of the sub-connection pools is obtained according to a preset period. If the number of idle connections is detected to be greater than the number of configured connections in the corresponding sub-connection pool, then the excess idle connections are removed from the corresponding sub-connection pool. If the number of idle connections is detected to be less than the configured number of connections in the corresponding sub-connection pool, then the total number of connections in the corresponding sub-connection pool is obtained, and a new connection is created in the corresponding sub-connection pool when the total number of connections is less than the preset maximum number of connections.

5. The method according to claim 4, characterized in that, Also includes: If the creation of the new connection fails, the sub-connection pool will be configured as unavailable. The process of traversing and detecting whether there are idle connections in the sub-connection pools of the target connection pool includes: Skip the sub-connection pools that are configured to be unavailable during traversal.

6. The method according to claim 1, characterized in that, Before obtaining the original connection pool, the following is also included: Obtain the hardware configuration parameters of all encryption machines, including encryption machine address information and encryption machine connection information; Generate an encryption machine configuration file based on the hardware configuration parameters; Based on the encryption machine configuration file, sub-connection pools corresponding to the hardware configuration parameters of each encryption machine are created to obtain the original connection pool.

7. The method according to claim 2, characterized in that, Also includes: Obtain the timeout thresholds for the at least two sub-connection pools; When the time to acquire an idle connection or create a new connection exceeds the timeout threshold, the operation of acquiring an idle connection or creating a new connection is terminated, and a timeout message is returned.

8. The method according to claim 1, characterized in that, Also includes: If the transaction request is successfully processed, the idle connection is returned to the corresponding sub-connection pool. If the transaction request fails to process, the idle connection is marked as a failed connection and removed from the corresponding sub-connection pool.

9. The method according to claim 1, characterized in that, Also includes: The idle time of idle connections in each of the sub-connection pools is detected according to a preset period; If the idle time of the idle connection is detected to exceed a preset idle time threshold, the idle connection will be removed from the corresponding sub-connection pool.

10. A management system for connecting encryption machines, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor, when executing the computer program, implements the steps of the method as described in any one of claims 1-9.