Method for controlling the number of concurrent connections

By using inter-server communication and semaphore pool management, and employing control instances for concurrency control, the problem of existing concurrency control methods being unable to balance reliability and accuracy is solved, thus achieving efficient and reliable concurrency management.

CN117478747BActive Publication Date: 2026-11-24中国邮政储蓄银行股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311416487.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-27
Publication Date
2026-11-24
Estimated Expiration
2043-10-27

AI Technical Summary

Technical Problem

Existing concurrency control methods cannot simultaneously ensure both the reliability and accuracy of concurrency control, resulting in complex operation and maintenance, high costs, and control failures.

Method used

Concurrency control is achieved using a control instance. Through communication between the first and second servers, the control instance determines whether the concurrency is less than a preset value and manages the concurrency in a semaphore pool, thus avoiding reliance on third-party distributed caching components.

Benefits of technology

It enables unified control of concurrency for the same type of service, improving the accuracy and reliability of concurrency control and reducing operational complexity and cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117478747B_ABST
    Figure CN117478747B_ABST
Patent Text Reader

Abstract

This application provides a method for controlling concurrency. The method includes: when a target instance configured on a first server receives a target message from a target client, the target instance configured on the first server determines its IP address based on the target message; the target instance configured on the first server sends a request message to a target instance configured on a second server based on the IP address of the target instance configured on a second server; and when the target instance configured on the first server receives first feedback information from the target instance configured on the second server, the target instance configured on the first server sends second feedback information to the target client and executes a service of the target type. This method solves the problem that existing concurrency control methods cannot simultaneously ensure both reliability and accuracy in concurrency control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of concurrency control, and more specifically, to a method for controlling concurrency. Background Technology

[0002] The existing concurrency control mechanisms are as follows:

[0003] 1) Multiple instances to be controlled execute the same service. These instances utilize Redis counters within the Redis component for concurrency control. When an instance receives a request for the same type of service, the Redis component increments the counter by 1. When the instance finishes executing the service, the Redis component decrements the counter by 1. This achieves control over the concurrency of the same type of service. Multiple instances to be controlled achieve unified control over the concurrency of the same type of service through the Redis component. This method provides high precision in concurrency control. However, it relies on third-party components such as Redis. Redis is a third-party distributed caching component that requires dedicated resources for deployment, resulting in complex operation and maintenance, high costs, and the vulnerability of Redis clusters to failures, such as unavailability due to split-brain attacks, leading to low reliability of concurrency control.

[0004] 2) When multiple instances of the same service are executed, separate control is used. The maximum concurrency of the same service on each instance of the same service is equal to the maximum concurrency of the same service divided by the number of instances of the same service. In other words, the maximum concurrency of the same service is evenly distributed among the instances of the same service, and each instance of the same service controls its own concurrency. When the load is unbalanced among the instances of the same service, some instances of the same service may be idle while others have concurrency limits. That is, the maximum allowed concurrency of the same service may not be reached, but some instances of the same service have concurrency limits. This method does not require a third-party distributed caching component, avoids the failure of concurrency control, and has high reliability. However, this method cannot achieve unified control of the concurrency of the same type of service, and the accuracy of concurrency control is low.

[0005] In summary, the existing concurrency control methods have the following problems:

[0006] It is impossible to simultaneously ensure both the reliability and accuracy of concurrent control. Summary of the Invention

[0007] The main objective of this application is to provide a method for controlling concurrency, so as to at least solve the problem that existing concurrency control methods cannot simultaneously ensure both the reliability and accuracy of concurrency control.

[0008] To achieve the above objectives, according to one aspect of this application, a concurrency control method is provided. A first server is configured with multiple instances to be controlled, one of which is used to execute at least one type of service. A second server is configured with multiple control instances. The first server is communicatively connected to multiple clients, and the first server is communicatively connected to the second server. The method is applied to the first server. The method includes: when a target instance to be controlled configured on the first server receives a target message from a target client, the target instance to be controlled configured on the first server determines the IP address of a target control instance based on the target message. The target instance to be controlled is any one of the multiple instances to be controlled, the target client is any one of the multiple clients, the target message is a message representing a request to execute a service of a target type, and the target type is any one of multiple types. One control instance configured on the second server has one IP address, and the target control instance is one of the multiple control instances. The target control instance corresponds to the service of the target type. Each control instance is used to determine whether the concurrency of a service of the target type at the current time is less than the corresponding preset concurrency. Each service of the target type corresponds to one preset concurrency. The target control instance configured by the first server sends a request message to the target control instance configured by the second server according to the IP address of the target control instance configured by the second server. The request message indicates a request to determine whether the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency. When the target control instance configured by the first server receives the first feedback message from the target control instance configured by the second server, the target control instance configured by the first server sends a second feedback message to the target client and executes the service of the target type. The first feedback message indicates that the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency, and the second feedback message indicates that the execution of the service of the target type is allowed.

[0009] Optionally, the target instance to be controlled configured by the first server determines the IP address of the target control instance based on the target packet, including: the target instance to be controlled configured by the first server obtains the target type from the packet body of the target packet; the target instance to be controlled configured by the first server determines the target concurrency ID based on the target type using preset rules, wherein the preset rules are any one of the following: value mapping, range mapping, conditional mapping, numerical modulo, HASH modulo, string truncation, formatted string, user-defined function, rule concatenation, the target concurrency ID is one of multiple concurrency IDs, and the target concurrency ID corresponds to a service of the target type, and one concurrency ID corresponds to one service of the type; the target instance to be controlled configured by the first server obtains a list of control instances. The system determines the number of control instances based on the control instance list, which contains the IP addresses of multiple control instances configured by the second server, arranged in a preset order. The number of control instances is the number of IP addresses contained in the control instance list. The target instance to be controlled configured by the first server obtains a target hash value, which is the hash value of the target concurrency ID. The target instance to be controlled configured by the first server determines the target remainder according to the formula B = H % A, where H is the target hash value, A is the number of control instances, and B is the target remainder. The target instance to be controlled configured by the first server determines the IP address of the target remainder in the control instance list as the IP address of the target control instance configured by the second server.

[0010] Optionally, before the target instance to be controlled configured by the first server obtains the list of control instances, the method further includes: the target instance to be controlled configured by the first server registering the IP addresses of multiple control instances to the list of control instances in a preset order; the target instance to be controlled configured by the first server determining whether the control instance corresponding to each IP address in the list of control instances has failed; and, if the control instance corresponding to at least one IP address in the list of control instances fails, updating the IP address of the failed control instance to the corresponding backup IP address of the control instance, wherein each IP address of the control instance in the list of control instances corresponds to a backup IP address of the control instance.

[0011] Optionally, after the target instance to be controlled configured by the first server sends request information to the target control instance configured by the second server according to the IP address of the target control instance configured by the second server, the method further includes: when the target instance to be controlled configured by the first server receives third feedback information from the target control instance configured by the second server, it sends fourth feedback information to the target client, wherein the third feedback information indicates that the concurrency of the target type service at the current time is greater than or equal to the corresponding preset concurrency, and the fourth feedback information indicates that the execution of the target type service is prohibited.

[0012] Optionally, after the target instance to be controlled configured by the first server sends request information to the target control instance configured by the second server according to the IP address of the target control instance configured by the second server, the method further includes: the target instance to be controlled configured by the first server obtaining a first request time, the first request time being the difference between the current time and the time when the request information is sent to the target control instance configured by the second server; if the first request time is greater than a first preset time, the target instance to be controlled configured by the first server sends the second feedback information to the target client and executes the service of the target type.

[0013] According to one aspect of this application, a concurrency control method is provided. A first server is configured with multiple instances to be controlled, one instance to be controlled being used to execute at least one type of service. A second server is configured with multiple control instances. The first server is communicatively connected to multiple clients, and the first server is communicatively connected to the second server. The method is applied to the second server. The method includes: when a target control instance configured on the second server receives a request message sent by a target instance to be controlled on the first server, the target control instance configured on the second server acquires the value of a target semaphore. The target instance to be controlled is one of the multiple instances to be controlled. The target instance to be controlled on the first server is used to receive a target message from a target client. The target client is any one of the multiple clients. The target message is a message representing a request to execute a service of a target type. The target type is any one of the multiple types. The target control instance is one of the multiple control instances, and the target... A control instance corresponds to the service of the target type. The request information indicates a request to determine whether the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency. One type of service corresponds to one preset concurrency. One control instance is used to determine whether the concurrency of one type of service at the current time is less than the corresponding preset concurrency. The target semaphore is one of multiple semaphores in a semaphore pool, and the target semaphore corresponds to the service of the target type. One semaphore corresponds to one type of service. The initial value of the semaphore is equal to the corresponding preset concurrency. The target control instance configured by the second server determines whether the value of the target semaphore is greater than 0. If the value of the target semaphore is greater than 0, the target control instance configured by the second server decrements the value of the target semaphore by 1 and sends first feedback information to the target instance to be controlled configured by the first server. The first feedback information indicates that the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency.

[0014] Optionally, after the target control instance configured on the second server decrements the value of the target semaphore by 1 and sends first feedback information to the target instance to be controlled configured on the first server when the target semaphore is greater than 0, the method further includes: the target control instance configured on the second server generating a first target serial number, sending the first target serial number to the target instance to be controlled configured on the first server, and adding the first target serial number to a first queue, wherein the first target serial number is one of multiple serial numbers, and the first target serial number corresponds to a target request combination, wherein the target request combination is one of multiple request combinations, and the target... The target request combination includes the target control instance and the time when the target control instance sends the request information. One request combination includes one control instance and the time when the control instance sends the request information. When the target control instance configured by the second server receives the fifth feedback information from the target instance to be controlled configured by the first server, the target control instance configured by the second server increments the value of the target semaphore by 1 and adds the first target serial number to the second queue. The fifth feedback information includes the first target serial number and indicates that the target type service of the target client has been completed.

[0015] Optionally, the method further includes: the target control instance configured by the second server performing a first acquisition step to acquire a second target serial number from the first queue, the second target serial number being one of a plurality of serial numbers in the first queue; the target control instance configured by the second server performing a second acquisition step to acquire a second request time, the second request time being the difference between the current time and the time when the second target serial number was generated; the target control instance configured by the second server performing a first determination step to determine whether the second request time is greater than a second preset time; the target control instance configured by the second server performing a first processing step to increment the value of the target semaphore by 1 and delete the second target serial number from the first queue if the second request time is greater than the second preset time; the target control instance configured by the second server repeatedly performing the first acquisition step, the second acquisition step, the first determination step, and the first processing step at least once until the processing of all the serial numbers in the first queue is completed.

[0016] Optionally, the method includes: the target control instance configured by the second server performing a third acquisition step to acquire a third target serial number from the second queue, wherein the third target serial number is one of a plurality of serial numbers in the second queue; the target control instance configured by the second server performing a second determination step to determine whether the third target serial number exists in the first queue; the target control instance configured by the second server performing a second processing step to delete the third target serial number from the first queue and the third target serial number from the second queue if the third target serial number exists in the first queue; and the target control instance configured by the second server repeating the third acquisition step, the second determination step, and the second processing step at least once until the processing of all the serial numbers in the second queue is completed.

[0017] Optionally, after the target control instance configured by the second server performs the second determining step and determines whether the third target serial number exists in the first queue, the method includes: the target control instance configured by the second server performs a third processing step, in which case, if the third target serial number does not exist in the first queue, the value of the target semaphore is decremented by 1 and the third target serial number is added to the first queue.

[0018] Compared to existing concurrency control methods that use third-party distributed caching components, this application uses a control instance for concurrency control. This eliminates the need for a third-party distributed caching component, preventing concurrency control failures and ensuring reliability. Furthermore, unlike existing methods that distribute the maximum concurrency of the same service equally among all controlled instances, each instance controls its own concurrency. In this application, each controlled instance sends a request to determine whether the concurrency of the same type of service is less than the corresponding preset concurrency to the same control instance. This means the same control instance controls the concurrency of the same type of service. If the concurrency of the same type of service is less than the preset concurrency, the controlled instance is allowed to execute service requests of that type. This achieves unified control of the concurrency of the same type of service, ensuring concurrency control accuracy and solving the problem that existing concurrency control methods cannot simultaneously guarantee both reliability and accuracy. Attached Figure Description

[0019] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0020] Figure 1 This paper illustrates a method for controlling the number of concurrent users running on a first server, according to an embodiment of this application.

[0021] Figure 2 This illustrates another method for controlling the number of concurrent users running on a first server, provided in an embodiment of this application.

[0022] Figure 3 A flowchart illustrating a method for controlling the concurrency of a second server according to an embodiment of this application is shown.

[0023] Figure 4 A flowchart illustrating another method for controlling the concurrency of a second server according to an embodiment of this application is shown.

[0024] Figure 5 A flowchart illustrating another method for controlling the number of concurrent users running on a second server, according to an embodiment of this application, is shown. Detailed Implementation

[0025] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0026] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0028] As described in the background section, existing concurrent control methods cannot simultaneously ensure both the reliability and accuracy of concurrent control. To address this issue, embodiments of this application provide a concurrent control method.

[0029] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0030] This embodiment provides a method for controlling the concurrency of a first server. The first server is configured with multiple instances to be controlled, and each instance to be controlled is used to execute at least one type of service. The second server is configured with multiple control instances. The first server is communicatively connected to multiple clients, and the first server is communicatively connected to the second server. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0031] Figure 1 This is a flowchart of a method for controlling concurrency according to an embodiment of this application. For example... Figure 1 As shown, the method includes the following steps:

[0032] Step S101: When the target instance to be controlled configured by the first server receives a target message from the target client, the target instance to be controlled configured by the first server determines the IP address of the target control instance based on the target message.

[0033] Wherein, the target instance to be controlled is any one of the multiple instances to be controlled, the target client is any one of the multiple clients, the target message is a message representing a request to execute a service of the target type, the target type is any one of the multiple types, the control instance configured by the second server has an IP address, the target control instance is one of the multiple control instances, and the target control instance corresponds to the service of the target type, one control instance is used to determine whether the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency, and one service of the target type corresponds to one preset concurrency;

[0034] Step S102: The target instance to be controlled configured by the first server sends a request message to the target control instance configured by the second server according to the IP address of the target control instance configured by the second server.

[0035] The aforementioned request information indicates a request to determine whether the number of concurrent users of the aforementioned target type service at the current time is less than the corresponding preset number of concurrent users.

[0036] Specifically, in some implementations, there are two types of services, denoted as A and B respectively. The preset concurrency of service type A is 20, meaning that the concurrency of service type A cannot exceed 20. The preset concurrency of service type B is 20, meaning that the concurrency of service type B cannot exceed 30.

[0037] Specifically, in some implementations, there are two types of services, denoted as A and B. The preset concurrency for service type A is 20, meaning the concurrency of service type A cannot exceed 20. The preset concurrency for service type B is 20, meaning the concurrency of service type B cannot exceed 30. There are two instances to be controlled, denoted as C and D, and two control instances, denoted as E and F. Control instance E is used to control the concurrency of service type A, and control instance F is used to control the concurrency of service type B. There are two clients, denoted as G and H. When client G requests instance C to execute service type A, instance C requests control instance E to determine whether the concurrency of service type A at the current time is less than 20. When client H requests instance D to execute service type A, instance D also requests control instance E to determine whether the concurrency of service type A at the current time is less than 20. The control of the concurrency of service type B is similar, that is, the same control instance is used to control the concurrency of the same type of service.

[0038] In step S103, when the target instance to be controlled configured by the first server receives the first feedback information from the target control instance configured by the second server, the target instance to be controlled configured by the first server sends the second feedback information to the target client and executes the target type service.

[0039] The first feedback information indicates that the number of concurrent users of the target type service at the current time is less than the corresponding preset number of concurrent users, and the second feedback information indicates that the execution of the target type service is allowed.

[0040] Specifically, such as Figure 2 As shown, if the target instance to be controlled configured by the first server is determined to be without rate limiting, that is, if the second feedback information of the target instance is received and it is determined that the concurrency of the target type service is less than or equal to the corresponding preset concurrency, the target instance to be controlled configured by the first server requests access, that is, the target instance to be controlled sends feedback to the target client that the target instance to be controlled is allowed to execute the target type service, and executes the target type service.

[0041] Through the above embodiments, compared with the concurrency control method of the prior art that uses a third-party distributed caching component for concurrency control, this application uses a control instance for concurrency control, which does not require a third-party distributed caching component, avoids the occurrence of concurrency control failure, and ensures the reliability of concurrency control. Compared with the concurrency control method of the prior art that evenly distributes the maximum concurrency of the same service to each instance to be controlled, and each instance to be controlled controls its own concurrency, in this application, each instance to be controlled sends a request to determine whether the concurrency of the same type of service is less than the corresponding preset concurrency to the same control instance. That is, the same control instance is used to control the concurrency of the same type of service. If the concurrency of the same type of service is less than the corresponding preset concurrency, the instance to be controlled is allowed to execute the service request of this type. This achieves unified control of the concurrency of the same type of service, ensures the accuracy of concurrency control, and solves the problem that the concurrency control method of the prior art cannot take into account both the reliability and accuracy of concurrency control.

[0042] The above step S101 can be implemented as follows:

[0043] Step S1011, the target instance to be controlled configured by the first server obtains the target type from the message body of the target message;

[0044] In step S1012, the target instance to be controlled configured on the first server determines the target concurrency ID according to the target type and using preset rules. The preset rules are any one of the following: value mapping, range mapping, condition mapping, numerical modulo, HASH modulo, string truncation, formatted string, user-defined function, and rule concatenation. The target concurrency ID is one of multiple concurrency IDs, and the target concurrency ID corresponds to the service of the target type. One of the concurrency IDs corresponds to one of the services of the type.

[0045] Specifically, such as Figure 2 As shown, when the target instance to be controlled configured on the first server receives the target message from the target client, the target instance to be controlled configured on the first server performs rate limiting ID calculation, that is, determines the target concurrency ID.

[0046] Step S1013: The target instance to be controlled configured on the first server obtains a list of control instances and determines the number of control instances based on the list of control instances. The list of control instances contains the IP addresses of multiple control instances configured on the second server, and the IP addresses in the list of control instances are arranged in a preset order. The number of control instances is the number of IP addresses contained in the list of control instances.

[0047] Step S1014: The target instance to be controlled configured on the first server obtains the target hash value, where the target hash value is the hash value of the target concurrency ID.

[0048] Step S1015: The target instance to be controlled configured on the first server is determined according to the formula B = H % A, where H is the target hash value, A is the number of control instances, and B is the target remainder.

[0049] In step S1016, the target instance to be controlled configured by the first server determines the IP address of the target remainder in the control instance list as the IP address of the target control instance configured by the second server.

[0050] Specifically, such as Figure 2 As shown, during the hash consistency call process, the concurrency ID is used for hash modulo operation. The remainder obtained by the same concurrency ID is the same, that is, the IP address of the control instance determined by the same concurrency ID is the same. Furthermore, one concurrency ID corresponds to one type of service, which ensures that the request information to determine whether the concurrency of the same type of service at the current time is less than the corresponding preset concurrency is sent to the same control instance. In other words, the same control instance is used to control the concurrency of the same type of service, thereby realizing unified control of the concurrency of the same type of service and improving the concurrency control accuracy.

[0051] To further ensure the reliability of concurrency control, before the target instance to be controlled obtains the list of controlled instances in step S1013, the method further includes:

[0052] The first server configured above registers the IP addresses of multiple control instances to the control instance list in the preset order.

[0053] Specifically, such as Figure 2 As shown, during the process of obtaining the IP address of the control instance, if the control instance is included in the microservice framework management, the target control instance configured by the first server obtains the IP addresses of multiple control instances from the registry center of the microservice framework; otherwise, it obtains the IP addresses of multiple control instances from the configuration information of the first server. During the process of IP address sorting and IP address registration, the target control instance configured by the first server registers the IP addresses of multiple control instances to the control instance list in the above-mentioned preset order.

[0054] Specifically, such as Figure 2As shown, in some implementations, the IP addresses in the registry of the microservice framework are "192.168.1.110", "192.168.1.111", "192.168.1.112" and "192.168.1.113".

[0055] The target instance to be controlled configured on the first server determines whether the control instance corresponding to each IP address in the control instance list has failed.

[0056] If at least one of the control instances corresponding to the IP address in the control instance list fails, the IP address of the failed control instance will be updated to the IP address of the corresponding backup control instance. Each IP address of the control instance in the control instance list corresponds to a backup control instance IP address.

[0057] Specifically, such as Figure 2 As shown, during the service status maintenance process, the target instance to be controlled configured on the first server determines whether each control instance in the control instance list has failed. If at least one control instance in the control instance list has failed, the IP address of the failed control instance is updated to the IP address of the corresponding backup control instance.

[0058] Specifically, compared to existing technologies like Redis, which require dedicated resources for deployment, are complex to operate and maintain, have high costs, and are prone to failure (e.g., unavailability due to split-brain), concurrency control also becomes unavailable. Control instances are a group of service processes that do not require additional resources for deployment, reducing deployment and operation complexity, lowering usage costs, and making them less prone to failure. Furthermore, to further ensure the reliability of concurrency control, a backup control instance deployment method is used. Each control instance in the control instance list corresponds to a backup control instance's IP address. When a control instance corresponding to an IP address in the control instance list fails, it automatically migrates to the backup control instance, ensuring that concurrency control does not fail and thus further guaranteeing its reliability.

[0059] Following step S102, the method further includes:

[0060] Upon receiving the third feedback information from the target control instance configured on the first server, the target instance to be controlled sends a fourth feedback information to the target client. The third feedback information indicates that the concurrent number of services of the target type at the current time is greater than or equal to the corresponding preset concurrent number, and the fourth feedback information indicates that the execution of services of the target type is prohibited.

[0061] Specifically, such as Figure 2 As shown, when the target instance to be controlled configured by the first server determines that rate limiting is required, i.e., when the third feedback information of the target instance to be controlled is received, if the concurrency of the target type service is determined to be greater than or equal to the corresponding preset concurrency, the target instance to be controlled configured by the first server returns a system busy message to the target client, that is, the target instance to be controlled configured by the first server sends feedback to the target client to prohibit the target instance to be controlled from executing the target type service.

[0062] Following step S102, the method further includes:

[0063] The target instance to be controlled configured on the first server obtains the first request time, which is the difference between the current time and the time when the request information is sent to the target instance to be controlled configured on the second server.

[0064] If the first request time is longer than the first preset time, the target instance to be controlled configured by the first server sends the second feedback information to the target client and executes the service of the target type.

[0065] Specifically, if the concurrency control request times out (i.e., the first request time exceeds the first preset time), the concurrency is handled as if it were not limited. The target instance to be controlled configured on the first server sends feedback to the target client, allowing the target instance to execute the target type service, and the target type service is executed.

[0066] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0067] This embodiment provides a method for controlling the concurrency of a second server. A first server is configured with multiple instances to be controlled, each instance being used to execute at least one type of service. A second server is configured with multiple control instances. The first server is communicatively connected to multiple clients, and the first server is communicatively connected to the second server. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0068] Figure 3 This is a flowchart of a method for controlling concurrency according to an embodiment of this application. For example... Figure 3 As shown, the method includes the following steps:

[0069] Step S201: When the target control instance configured by the second server receives the request information sent by the target instance to be controlled configured by the first server, the target control instance configured by the second server obtains the value of the target semaphore.

[0070] Wherein, the target instance to be controlled is one of a plurality of such instances to be controlled, the target instance to be controlled configured by the first server is used to receive target messages from target clients, the target client is any one of a plurality of such clients, the target message is a message representing a request to execute a service of a target type, the target type is any one of a plurality of such types, the target control instance is one of a plurality of such control instances, and the target control instance corresponds to a service of the target type, the request information represents a request to determine whether the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency, one such type of service corresponds to one such preset concurrency, one such control instance is used to determine whether the concurrency of one such type of service at the current time is less than the corresponding such preset concurrency, the target semaphore is one of a plurality of semaphores in the semaphore pool, and the target semaphore corresponds to a service of the target type, one such semaphore corresponds to one such type of service, and the initial value of the semaphore is equal to the corresponding such preset concurrency;

[0071] Step S202: The target control instance configured on the second server determines whether the target semaphore is greater than 0.

[0072] In step S203, when the target semaphore is greater than 0, the target control instance configured by the second server decrements the value of the target semaphore by 1 and sends first feedback information to the target control instance configured by the first server.

[0073] The first feedback information indicates that the number of concurrent users of the target type service at the current time is less than the corresponding preset number of concurrent users.

[0074] Specifically, in some implementations, there are two types of services, denoted as A and B. Service type A has a preset concurrency of 20, meaning the concurrency of service type A cannot exceed 20. Service type B has a preset concurrency of 20, meaning the concurrency of service type B cannot exceed 30. There are two instances to be controlled, denoted as C and D, and two control instances, denoted as E and F. Control instance E controls the concurrency of service type A, and control instance F controls the concurrency of service type B. There are two clients, denoted as G and H, and two semaphores, denoted as V and W. Service type A corresponds to semaphore V, with an initial value of 20. Service type B corresponds to semaphore W, with an initial value of 30. When client G requests instance C to execute service of type A, instance C requests control instance E to determine whether the current concurrency of service of type A is less than 20. Control instance E then determines whether the value of semaphore V is greater than 0. If so, it determines that the current concurrency of service of type A is less than 20. When client H requests instance D to execute service of type A, instance D similarly requests control instance E to determine whether the current concurrency of service of type A is less than 20. Control instance E then determines whether the value of semaphore V is greater than 0. If so, it determines that the current concurrency of service of type A is less than 20. The control of the concurrency of service of type B is similar, that is, the same control instance is used to control the concurrency of the same type of service.

[0075] Specifically, such as Figure 4 As shown, when the target control instance configured on the second server determines that the concurrency of the target type service does not exceed the corresponding concurrency, it is necessary to register the concurrency, decrement the value of the target semaphore by 1, that is, call sem_trywait to perform a P operation on the target semaphore and return a response, that is, send the first feedback information to the target instance to be controlled configured on the first server. Through the semaphore pool, the registration of the concurrency is transformed into a P operation on the semaphore.

[0076] Through the above embodiments, compared with the concurrency control method of the prior art that uses a third-party distributed caching component for concurrency control, this application uses a control instance for concurrency control, which does not require a third-party distributed caching component, avoids the occurrence of concurrency control failure, and ensures the reliability of concurrency control. Compared with the concurrency control method of the prior art that evenly distributes the maximum concurrency of the same service to each instance to be controlled, and each instance to be controlled controls its own concurrency, in this application, each instance to be controlled sends a request to determine whether the concurrency of the same type of service is less than the corresponding preset concurrency to the same control instance. That is, the same control instance controls the concurrency of the same type of service. When the same control instance determines that the value of the same semaphore is greater than 0, it determines that the concurrency of the same type of service is less than the corresponding preset concurrency, and allows the instance to be controlled to execute this type of service request. This achieves unified control of the concurrency of the same type of service, ensures the accuracy of concurrency control, and solves the problem that the concurrency control method of the prior art cannot simultaneously take into account the reliability and accuracy of concurrency control.

[0077] Following step S203, the method further includes:

[0078] Step S301: The target control instance configured on the second server generates a first target serial number, sends the first target serial number to the target instance to be controlled configured on the first server, and adds the first target serial number to a first queue. The first target serial number is one of multiple serial numbers and corresponds to a target request combination. The target request combination is one of multiple request combinations and includes the target control instance and the time when the target control instance sends the request information. One request combination includes one control instance and the time when the control instance sends the request information.

[0079] In step S302, when the target control instance configured by the second server receives the fifth feedback information from the target control instance configured by the first server, the target control instance configured by the second server increments the value of the target semaphore by 1 and adds the first target serial number to the second queue. The fifth feedback information includes the first target serial number and indicates that the target type service of the target client has been completed.

[0080] In this embodiment, as Figure 4As shown, when the target control instance configured on the second server determines that the concurrency of the target type service has not exceeded the corresponding concurrency, it is necessary to register the concurrency and decrement the value of the target semaphore by 1. That is, the sem_trywait() function is called to perform a P operation on the target semaphore, and the first target serial number is added to the first queue. When the target control instance configured on the second server determines that the target type service of the target client has been completed, it is necessary to release the concurrency and decrement the value of the target semaphore by 1. That is, the sem_post() function is called to perform a V operation on the target semaphore, and the first target serial number is added to the second queue.

[0081] To ensure the reliability of concurrency control, the above methods also include:

[0082] The target control instance configured on the second server executes the first acquisition step to obtain a second target serial number from the first queue. The second target serial number is one of the multiple serial numbers in the first queue.

[0083] The target control instance configured on the second server executes the second acquisition step to acquire the second request time, which is the difference between the current time and the time when the second target serial number was generated.

[0084] The target control instance configured on the second server above performs the first determining step to determine whether the second request time is greater than the second preset time;

[0085] The target control instance configured on the second server executes the first processing step: if the second request time is greater than the second preset time, the value of the target semaphore is decremented by 1, and the second target serial number is deleted from the first queue.

[0086] The target control instance configured on the second server repeatedly executes the first acquisition step, the second acquisition step, the first determination step, and the first processing step at least once, until the processing of all the serial numbers in the first queue is completed.

[0087] Specifically, if the instance configured on the second server encounters an anomaly while executing the service of the target type, it may occupy the target semaphore for an extended period, affecting the reliability of concurrency control. Figure 5As shown, during the process of the target control instance configured by the second server processing the first queue, the target control instance configured by the second server reads the second target serial number in the first queue and determines whether the generation time of the second target serial number has expired (whether the second request time is greater than the second preset time). If it has expired, the second target serial number is deleted and the value of the target semaphore is incremented by 1, that is, the sem_post() function is called to perform a V operation on the target semaphore, so as to avoid a certain instance to be controlled by the second server occupying the target semaphore for a long time, so as to ensure the reliability of the concurrency control.

[0088] Specifically, the generation time of the serial number reflects the execution time of the target type of the request information in the request combination corresponding to the serial number. If the generation time of the serial number is too long, it means that the execution time of the target type of the request information in the request combination corresponding to the serial number is too long. The generation time of the serial number reflects that the instance to be controlled in the request combination corresponding to the serial number has an anomaly.

[0089] The above methods include:

[0090] Step S401, the target control instance configured by the second server performs the third acquisition step, and obtains the third target serial number from the second queue. The third target serial number is one of the multiple serial numbers in the second queue.

[0091] Step S402, the target control instance configured by the second server performs a second determination step to determine whether the third target serial number exists in the first queue;

[0092] Step S403: The target control instance configured on the second server executes the second processing step. If the third target serial number exists in the first queue, the third target serial number is deleted from the first queue and the third target serial number is also deleted from the second queue.

[0093] In step S404, the target control instance configured on the second server repeatedly executes the third acquisition step, the second determination step, and the second processing step at least once, until the processing of all the serial numbers in the second queue is completed.

[0094] Specifically, such as Figure 5As shown, when the target control instance configured by the second server processes the second queue, it reads the third target serial number in the second queue and determines whether there is a third target serial number in the first queue. If there is, it means that the generation time of the third target serial number has not timed out and the execution time of the target type of the request information request in the request combination corresponding to the third target serial number has not timed out. Then, the third target serial number in the first queue is deleted, and the third target serial number in the second queue is also deleted.

[0095] Following step S402 above, the method further includes:

[0096] The target control instance configured on the second server executes the third processing step: if the third target serial number is not present in the first queue, the value of the target semaphore is decremented by 1, and the third target serial number is added to the first queue.

[0097] In this embodiment, as Figure 5 As shown, it is determined whether there is a third target sequence number in the first queue. If not, it means that the generation time of the third target sequence number has timed out, and the execution time of the target type of the request information in the request combination corresponding to the third target sequence number has timed out. Since the generation time of the third target sequence number has timed out, the third target sequence number will be deleted from the first queue, and the value of the target semaphore will be incremented by 1 (a V operation is performed on the target semaphore). Therefore, for a request information of the instance to be controlled in the request combination corresponding to the third target sequence number, the value of the target semaphore is incremented by 1 twice (two V operations are performed). At this time, the value of the target semaphore is decremented by 1, and the sem_trywait() function is called to perform a P operation on the value of the target semaphore, and the third target sequence number is added to the first queue.

[0098] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0099] As can be seen from the above description, the embodiments of this application achieve the following technical effects:

[0100] 1) In the concurrency control method of the target instance to be controlled configured on the first server in this application, compared with the concurrency control method of the prior art that uses a third-party distributed caching component for concurrency control, this application uses a control instance for concurrency control, which does not require a third-party distributed caching component, avoids the occurrence of concurrency control failure, and ensures the reliability of concurrency control. Compared with the concurrency control method of the prior art that evenly distributes the maximum concurrency of the same service to each instance to be controlled, and each instance to be controlled controls its own concurrency, each instance to be controlled in this application sends a request to determine whether the concurrency of the same type of service is less than the corresponding preset concurrency to the same control instance. That is, the same control instance is used to control the concurrency of the same type of service. If the concurrency of the same type of service is less than the corresponding preset concurrency, the instance to be controlled is allowed to execute the service request of this type. This realizes unified control of the concurrency of the same type of service, ensures the accuracy of concurrency control, and solves the problem that the concurrency control method of the prior art cannot take into account both the reliability and accuracy of concurrency control.

[0101] 2) In the concurrency control method of the target control instance configured on the second server in this application, compared with the concurrency control method of the prior art that uses a third-party distributed caching component for concurrency control, this application uses the control instance for concurrency control, which does not require a third-party distributed caching component, avoids the occurrence of concurrency control failure, and ensures the reliability of concurrency control. Compared with the concurrency control method of the prior art that evenly distributes the maximum concurrency of the same service to each instance to be controlled, and each instance to be controlled controls its own concurrency, each instance to be controlled in this application requests confirmation. Requests regarding whether the concurrency of services of the same type is less than the corresponding preset concurrency are sent to the same control instance. In other words, the same control instance controls the concurrency of services of the same type. When the same control instance determines that the value of the same semaphore is greater than 0, it determines that the concurrency of services of the same type is less than the corresponding preset concurrency, and allows the instance to be controlled to execute service requests of this type. This achieves unified control over the concurrency of services of the same type, ensures the accuracy of concurrency control, and solves the problem that existing concurrency control methods cannot simultaneously ensure both the reliability and accuracy of concurrency control.

[0102] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A concurrency control method, characterized in that, A first server is configured with multiple instances to be controlled, each instance being used to execute at least one type of service. A second server is configured with multiple control instances. The first server communicates with multiple clients, and the first server also communicates with the second server. The method is applied to the first server, and the method includes: When the target instance to be controlled configured by the first server receives a target message from the target client, the target instance to be controlled configured by the first server determines the IP address of the target control instance based on the target message. The target instance to be controlled is any one of the multiple instances to be controlled, the target client is any one of the multiple clients, the target message is a message representing a request to execute a service of a target type, the target type is any one of the multiple types, the control instance configured by the second server has one IP address, the target control instance is one of the multiple control instances, and the target control instance corresponds to the service of the target type. One control instance is used to determine whether the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency. One service of the target type corresponds to one preset concurrency. The target instance to be controlled configured by the first server sends a request message to the target control instance configured by the second server according to the IP address of the target control instance configured by the second server. The request message indicates that the concurrent number of the target type service at the current time is less than the corresponding preset concurrent number. When the target instance to be controlled configured by the first server receives the first feedback information from the target control instance configured by the second server, the target instance to be controlled configured by the first server sends the second feedback information to the target client and executes the service of the target type. The first feedback information indicates that the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency, and the second feedback information indicates that the execution of the service of the target type is allowed.

2. The method according to claim 1, characterized in that, The target instance to be controlled, configured by the first server, determines the IP address of the target control instance based on the target message, including: The target instance configured by the first server obtains the target type from the message body of the target message; The target instance to be controlled configured on the first server determines the target concurrency ID according to the target type and using preset rules. The preset rules are any one of the following: value mapping, range mapping, condition mapping, numerical modulo, HASH modulo, string truncation, formatted string, user-defined function, and rule cascading. The target concurrency ID is one of multiple concurrency IDs, and the target concurrency ID corresponds to a service of the target type. One concurrency ID corresponds to one service of the type. The first server configures the target instance to be controlled to obtain a list of control instances, and determines the number of control instances based on the list of control instances. The list of control instances contains the IP addresses of multiple control instances configured by the second server, and the IP addresses in the list of control instances are arranged in a preset order. The number of control instances is the number of IP addresses contained in the list of control instances. The target instance to be controlled, configured by the first server, obtains the target hash value, wherein the target hash value is the hash value of the target concurrency ID; The target instance to be controlled configured in the first server determines the target remainder according to the formula B = H % A, where H is the target hash value, A is the number of control instances, and B is the target remainder; The first server configures the target instance to be controlled to determine the IP address of the target remainder in the list of control instances as the IP address of the target control instance configured by the second server.

3. The method according to claim 2, characterized in that, Before the target instance to be controlled, configured in the first server, obtains the list of controlled instances, the method further includes: The first server configures the target instance to be controlled to register the IP addresses of multiple control instances to the control instance list in the preset order; The first server configures the target instance to be controlled to determine whether the control instance corresponding to each IP address in the control instance list has failed; If the control instance corresponding to at least one IP address in the control instance list fails, the IP address of the failed control instance will be updated to the IP address of the corresponding backup control instance, where each IP address of the control instance in the control instance list corresponds to a backup control instance IP address.

4. The method according to claim 1, characterized in that, After the target instance to be controlled configured on the first server sends request information to the target control instance configured on the second server according to the IP address of the target control instance configured on the second server, the method further includes: When the target instance configured by the first server receives the third feedback information from the target control instance configured by the second server, it sends a fourth feedback information to the target client. The third feedback information indicates that the concurrency of the target type service at the current time is greater than or equal to the corresponding preset concurrency, and the fourth feedback information indicates that the execution of the target type service is prohibited.

5. The method according to claim 1, characterized in that, After the target instance to be controlled configured on the first server sends request information to the target control instance configured on the second server according to the IP address of the target control instance configured on the second server, the method further includes: The target instance to be controlled configured by the first server obtains a first request time, which is the difference between the current time and the time when the request information is sent to the target instance to be controlled configured by the second server. If the first request time is greater than the first preset time, the target instance to be controlled configured by the first server sends the second feedback information to the target client and executes the service of the target type.

6. A concurrency control method, characterized in that, A first server is configured with multiple instances to be controlled, each instance being used to execute at least one type of service. A second server is configured with multiple control instances. The first server communicates with multiple clients, and the first server also communicates with the second server. The method is applied to the second server, and the method includes: When the target control instance configured by the second server receives the request information sent by the target instance to be controlled configured by the first server, the target control instance configured by the second server acquires the value of the target semaphore. The target instance to be controlled is one of a plurality of instances to be controlled. The target instance to be controlled configured by the first server is used to receive the target message from the target client. The target client is any one of a plurality of clients. The target message is a message representing a request to execute a service of a target type. The target type is any one of a plurality of types. The target control instance is one of a plurality of control instances, and the target control instance corresponds to the service of the target type. The request information represents a request to determine whether the concurrency of the service of the target type at the current time is less than the corresponding preset concurrency. One type of service corresponds to one preset concurrency. One control instance is used to determine whether the concurrency of one type of service at the current time is less than the corresponding preset concurrency. The target semaphore is one of a plurality of semaphores in the semaphore pool, and the target semaphore corresponds to the service of the target type. One semaphore corresponds to one type of service. The initial value of the semaphore is equal to the corresponding preset concurrency. The target control instance configured in the second server determines whether the value of the target semaphore is greater than 0; When the target control instance configured by the second server has a target semaphore value greater than 0, it decrements the target semaphore value by 1 and sends a first feedback message to the target control instance configured by the first server. The first feedback message indicates that the number of concurrent services of the target type at the current time is less than the corresponding preset number of concurrent services.

7. The method according to claim 6, characterized in that, After the target control instance configured on the second server decrements the value of the target semaphore by 1 when the target semaphore is greater than 0, and sends first feedback information to the target control instance configured on the first server, the method further includes: The target control instance configured by the second server generates a first target serial number, sends the first target serial number to the target instance to be controlled configured by the first server, and adds the first target serial number to a first queue. The first target serial number is one of multiple serial numbers and corresponds to a target request combination. The target request combination is one of multiple request combinations and includes the target control instance and the time when the target control instance sends the request information. One request combination includes one control instance and the time when the control instance sends the request information. When the target control instance configured by the second server receives the fifth feedback information from the target instance to be controlled configured by the first server, the target control instance configured by the second server increments the value of the target semaphore by 1 and adds the first target serial number to the second queue. The fifth feedback information includes the first target serial number and indicates that the target type service of the target client has been completed.

8. The method according to claim 7, characterized in that, The method further includes: The target control instance configured by the second server performs the first acquisition step, acquiring a second target serial number from the first queue, wherein the second target serial number is one of the multiple serial numbers in the first queue; The target control instance configured in the second server executes the second acquisition step to acquire the second request time, which is the difference between the current time and the time when the second target serial number was generated; The target control instance configured in the second server performs a first determining step to determine whether the second request time is greater than a second preset time; The target control instance configured on the second server executes the first processing step: if the second request time is greater than the second preset time, the value of the target semaphore is incremented by 1, and the second target serial number is deleted from the first queue. The target control instance configured by the second server repeatedly executes the first acquisition step, the second acquisition step, the first determination step, and the first processing step at least once, until the processing of all the serial numbers in the first queue is completed.

9. The method according to claim 7, characterized in that, The method includes: The target control instance configured by the second server performs a third acquisition step, acquiring a third target serial number from the second queue, wherein the third target serial number is one of the multiple serial numbers in the second queue; The target control instance configured by the second server performs a second determination step to determine whether the third target serial number exists in the first queue; The target control instance configured on the second server executes a second processing step: if the third target serial number exists in the first queue, the third target serial number is deleted from the first queue and the third target serial number is also deleted from the second queue. The target control instance configured by the second server repeatedly executes the third acquisition step, the second determination step, and the second processing step at least once, until the processing of all the serial numbers in the second queue is completed.

10. The method according to claim 9, characterized in that, In the second determination step performed by the target control instance configured on the second server, after determining whether the third target serial number exists in the first queue, the method includes: The target control instance configured by the second server executes a third processing step: if the third target serial number does not exist in the first queue, the value of the target semaphore is decremented by 1, and the third target serial number is added to the first queue.

Citation Information

Patent Citations

  • Resource data acquisition method and device, computer equipment and storage medium

    CN110727499A

  • Example control method and device, equipment, storage medium and program product

    CN112506583A