A frequency control method and related apparatus
Patent Information
- Application Number
- CN202410475491.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-19
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2044-04-19
AI Technical Summary
[0003]相关技术虽然也提供了频率控制方法,但是这种频率控制方法在机器宕机或网络故障时会导致服务端不可用,服务稳定性差
[0086] As can be seen from the above technical solution, upon receiving an access request, the access request, including its identifier, can be obtained. Then, the access request is routed to the target server in the server-side distributed cluster according to the routing strategy. The server-side distributed cluster includes multiple servers. Typically, these servers will not simultaneously fail or experience network failures. The routing strategy can route the access request to a suitable server within the server-side distributed cluster (i.e., the target server), ensuring that the target server is functioning correctly and preventing server failures or network failures from affecting the frequency control service. In this way, the normally functioning target server can accumulate the current cumulative frequency value based on the request identifier and generate a control strategy based on the cumulative frequency value and control generation rules. Subsequently, the client can retrieve the control strategy from the target server and then process the access request according to the control strategy, thus achieving normal frequency control service. Compared with the frequency control methods provided by related technologies, the server in this application is deployed in a server-side distributed cluster mode. When performing frequency control on access requests, the access request can be routed to the corresponding target server based on the routing strategy. If one server fails, it can be routed to another server, resulting in good service stability.
Smart Images

Figure CN118400380B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a frequency control method and related apparatus. Background Technology
[0002] In recent years, fintech has developed rapidly, and emerging financial business models such as scenario-based finance and open banking are flourishing. While bringing tremendous growth to various banking businesses, this has also brought significant security threats and challenges. In the areas of bank compliance risk management and high-availability technical architecture, frequency control services, as a fundamental capability, are playing an increasingly important role in security protection.
[0003] While related technologies also provide frequency control methods, these methods can lead to server unavailability and poor service stability when machines crash or networks fail. Summary of the Invention
[0004] To address the aforementioned technical issues, this application provides a frequency control method and related apparatus, which are deployed and implemented using a server-side distributed cluster model. When performing frequency control on access requests, access requests can be routed to the corresponding target server based on a routing strategy. If a server fails, the request can be routed to another server, resulting in good service stability.
[0005] In a first aspect, embodiments of this application provide a frequency control method, the method comprising:
[0006] Obtain an access request, wherein the access request includes a request identifier;
[0007] The access request is routed to the target server in the server-side distributed cluster according to the routing strategy. The target server is used to accumulate the frequency based on the request identifier to obtain the current accumulated frequency value, and generate a control strategy based on the accumulated frequency value and the control generation rules.
[0008] The control policy is retrieved from the target server.
[0009] The access request is controlled and processed according to the control policy.
[0010] In one possible implementation, routing the access request to the target server in the server-side distributed cluster according to the routing strategy includes:
[0011] Push the access request to the request buffer queue;
[0012] The access request is read from the request buffer queue and routed to the target server according to the routing strategy.
[0013] In one possible implementation, the step of pulling the control policy from the target server includes:
[0014] The control policy is retrieved from the target server and written to the policy buffer queue;
[0015] The step of controlling the access request according to the control policy includes:
[0016] The control policy is read from the policy buffer queue, and the access request is controlled according to the control policy.
[0017] Secondly, embodiments of this application provide a frequency control method, the method comprising:
[0018] Obtain the access request uploaded by the client. The access request includes a request identifier and is routed by the client to the target server in the server-side distributed cluster according to the routing strategy.
[0019] The current cumulative frequency value is obtained by accumulating the frequency based on the request identifier, and the pre-configured control generation rules are read.
[0020] A control strategy is generated based on the cumulative frequency value and the control generation rules;
[0021] The control policy is then sent to the client.
[0022] In one possible implementation, the step of obtaining the current accumulated frequency value based on the request identifier includes:
[0023] The first memory node is obtained based on the request identifier;
[0024] The current cumulative frequency value is obtained by accumulating the existing cumulative frequency value stored in the first memory node.
[0025] In one possible implementation, the method further includes:
[0026] If the second memory node is not updated within a preset time, the second memory node will be allocated to other request identifiers.
[0027] In one possible implementation, the step of obtaining the current accumulated frequency value based on the request identifier includes:
[0028] Based on the request identifier and business scenario, the target accumulation method is determined from multiple accumulation methods;
[0029] The current cumulative frequency value is obtained by accumulating the frequency according to the target accumulation method.
[0030] In one possible implementation, generating the control strategy based on the cumulative frequency value and the control generation rule includes:
[0031] The cumulative frequency value is compared with the frequency control threshold to obtain the comparison result;
[0032] The control strategy is generated based on the comparison results and the control generation rules.
[0033] In one possible implementation, the method further includes:
[0034] The analysis results were obtained by analyzing visitors with different access frequencies.
[0035] If, based on the analysis results, it is determined that an access party exceeding the target frequency is an abnormal access party, then the target frequency is determined as the frequency control threshold.
[0036] In one possible implementation, the method further includes:
[0037] The control strategy is stored in shared memory;
[0038] The step of sending the control policy to the client includes:
[0039] The control policy is read from the shared memory and then sent to the client.
[0040] In one possible implementation, the method further includes:
[0041] Synchronize the control policy to persistent storage;
[0042] After the target server is powered off or restarted, the control policy is restored from the persistent storage to the shared memory.
[0043] Thirdly, embodiments of this application provide a frequency control device, the device comprising:
[0044] An acquisition unit is used to acquire an access request, wherein the access request includes a request identifier;
[0045] The routing unit is used to route the access request to the target server in the server-side distributed cluster according to the routing strategy. The target server is used to accumulate the frequency based on the request identifier to obtain the current accumulated frequency value, and generate a control strategy according to the accumulated frequency value and the control generation rules.
[0046] A pull unit is used to pull the control policy from the target server.
[0047] The processing unit is used to control and process the access request according to the control policy.
[0048] In one possible implementation, the routing unit is used for:
[0049] Push the access request to the request buffer queue;
[0050] The access request is read from the request buffer queue and routed to the target server according to the routing strategy.
[0051] In one possible implementation, the pull unit is used for:
[0052] The control policy is retrieved from the target server and written to the policy buffer queue;
[0053] The processing unit is used for:
[0054] The control policy is read from the policy buffer queue, and the access request is controlled according to the control policy.
[0055] Fourthly, embodiments of this application provide a frequency control device, the device comprising:
[0056] The acquisition unit is used to acquire the access request uploaded by the client. The access request includes a request identifier and is routed by the client to the target server in the server-side distributed cluster according to the routing strategy.
[0057] The accumulation unit is used to accumulate frequencies based on the request identifier to obtain the current accumulated frequency value;
[0058] The acquisition unit is also used to read pre-configured control generation rules;
[0059] The generation unit is used to generate a control strategy based on the cumulative frequency value and the control generation rules;
[0060] The distribution unit is used to distribute the control policy to the client.
[0061] In one possible implementation, the accumulation unit is used for:
[0062] The first memory node is obtained based on the request identifier;
[0063] The current cumulative frequency value is obtained by accumulating the existing cumulative frequency value stored in the first memory node.
[0064] In one possible implementation, the apparatus further includes an allocation unit, the allocation unit being configured to:
[0065] If the second memory node is not updated within a preset time, the second memory node will be allocated to other request identifiers.
[0066] In one possible implementation, the accumulation unit is used for:
[0067] Based on the request identifier and business scenario, the target accumulation method is determined from multiple accumulation methods;
[0068] The current cumulative frequency value is obtained by accumulating the frequency according to the target accumulation method.
[0069] In one possible implementation, the generating unit is used for:
[0070] The cumulative frequency value is compared with the frequency control threshold to obtain the comparison result;
[0071] The control strategy is generated based on the comparison results and the control generation rules.
[0072] In one possible implementation, the device further includes an analysis unit and a determination unit:
[0073] The analysis unit is used to analyze visitors with different access frequencies and obtain analysis results.
[0074] The determining unit is configured to determine the target frequency as the frequency control threshold if, based on the analysis results, an access party exceeding the target frequency is determined to be an abnormal access party.
[0075] In one possible implementation, the device further includes a storage unit:
[0076] The storage unit is used to store the control strategy in shared memory;
[0077] The sending unit is used to read the control policy from the shared memory and send the control policy to the client.
[0078] In one possible implementation, the device further includes a synchronization unit and a recovery unit:
[0079] The synchronization unit is used to synchronize the control strategy to persistent storage;
[0080] The recovery unit is used to restore the control policy from the persistent storage to the shared memory after the target server is powered off or restarted.
[0081] Fifthly, embodiments of this application provide a computer device, the device including a processor and a memory:
[0082] The memory is used to store program code and transmit the program code to the processor;
[0083] The processor is configured to execute the method described in any of the first aspects according to the instructions in the program code.
[0084] In a sixth aspect, embodiments of this application provide a computer-readable storage medium for storing program code, which, when executed by a processor, implements the method described in any of the first aspects.
[0085] In a seventh aspect, embodiments of this application provide a computer program product, the computer program product including program code, which, when executed by a processor, implements the method described in any of the first aspects.
[0086] As can be seen from the above technical solution, upon receiving an access request, the access request, including its identifier, can be obtained. Then, the access request is routed to the target server in the server-side distributed cluster according to the routing strategy. The server-side distributed cluster includes multiple servers. Typically, these servers will not simultaneously fail or experience network failures. The routing strategy can route the access request to a suitable server within the server-side distributed cluster (i.e., the target server), ensuring that the target server is functioning correctly and preventing server failures or network failures from affecting the frequency control service. In this way, the normally functioning target server can accumulate the current cumulative frequency value based on the request identifier and generate a control strategy based on the cumulative frequency value and control generation rules. Subsequently, the client can retrieve the control strategy from the target server and then process the access request according to the control strategy, thus achieving normal frequency control service. Compared with the frequency control methods provided by related technologies, the server in this application is deployed in a server-side distributed cluster mode. When performing frequency control on access requests, the access request can be routed to the corresponding target server based on the routing strategy. If one server fails, it can be routed to another server, resulting in good service stability. Attached Figure Description
[0087] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0088] Figure 1 A signaling interaction diagram of a frequency control method provided in an embodiment of this application;
[0089] Figure 2An example diagram illustrating the allocation process of an access request within a rolling time window, provided as an embodiment of this application;
[0090] Figure 3 An example diagram illustrating the allocation process of an access request within a sliding time window, provided as an embodiment of this application;
[0091] Figure 4 An example diagram illustrating the overall architecture of a frequency control method provided in an embodiment of this application;
[0092] Figure 5 A structural diagram of a frequency control device provided in an embodiment of this application;
[0093] Figure 6 This is a structural diagram of another frequency control device provided in an embodiment of this application. Detailed Implementation
[0094] 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 are within the scope of protection of the present application.
[0095] To better understand the methods provided in the embodiments of this application, the terms used in the embodiments of this application will first be explained:
[0096] Shared memory:
[0097] Shared memory (shm) is an inter-process communication (IPC) method that allows multiple programs on a single server to share a given memory region. Because memory copying (memcpy) operations during data replication consume significant memory bandwidth and CPU resources, shared memory eliminates the need for data copying between client and server processes, making it the most efficient IPC method.
[0098] System V shared memory is a commonly used shared memory implementation mechanism. It enables inter-process shared memory communication by mapping files in the special file system shm, with each shared memory region corresponding to a file in the special file system shm.
[0099] Multidimensional hash table:
[0100] Hash tables are a commonly used data structure that accesses records by mapping key values to locations in the table, thus speeding up lookups. However, most hash table data structures are unsuitable for server caching due to their instability. The main problem with hash tables is handling collisions, and multidimensional hash tables are one implementation method for this. A multidimensional hash table can be considered a multidimensional array, typically with 10 to 100 rows, a variable number of columns, and a fixed element size.
[0101] Linux lock-free programming:
[0102] When programming in a multithreaded or multiprocessing environment, mutex locks are needed to ensure the correctness of operations on global variables when performing addition, subtraction, or other operations on them. Locking inevitably incurs a performance penalty.
[0103] Linux provides a set of functions that guarantee atomicity for addition, subtraction, AND, OR, XOR, etc., as follows:
[0104] type_sync_fetch_and_add(type*ptr, type value);
[0105] type_sync_fetch_and_sub(type*ptr, type value);
[0106] type_sync_fetch_and_or(type*ptr, type value);
[0107] type_sync_fetch_and_and(type*ptr, type value);
[0108] type_sync_fetch_and_xor(type*ptr, type value);
[0109] In recent years, fintech has developed rapidly, and emerging financial business models such as scenario-based finance and open banking are flourishing. While bringing tremendous growth to various banking businesses, this has also brought significant security threats and challenges. In the areas of bank compliance risk management and high-availability technical architecture, frequency control services, as a fundamental capability, are playing an increasingly important role in security protection.
[0110] For example, in today's internet environment, attackers may use brute-force attacks or malicious scanning to target a bank's business systems, attempting to detect vulnerabilities and steal core customer data. To counter these massive amounts of unauthorized requests and build the first line of defense against risk, a stable frequency control service is both urgent and crucial.
[0111] For example, banking systems are gradually shifting from monolithic architecture to microservice architecture. Microservice architecture divides a single program into many small modules that call each other. With billions of requests daily, this complex call structure can easily lead to a system-wide avalanche due to an anomaly in one module. Therefore, each module needs to use frequency control services to ensure its own stability.
[0112] While related technologies also provide frequency control methods, these methods are implemented on a single machine, which can lead to server unavailability and poor service stability when the machine crashes or the network fails.
[0113] To address the aforementioned technical problems, this application provides a frequency control method. Upon receiving an access request, the method obtains the access request, including a request identifier, and then routes the access request to a target server in a server-side distributed cluster according to a routing strategy. The server-side distributed cluster includes multiple servers. Typically, these servers will not simultaneously fail or experience network failures. The routing strategy can route the access request to a suitable server within the server-side distributed cluster (i.e., the target server), ensuring that the target server is functioning correctly and preventing server failures or network failures from affecting the frequency control service. In this way, a normally functioning target server can accumulate the current cumulative frequency value based on the request identifier and generate a control strategy based on the cumulative frequency value and control generation rules. Subsequently, the client can retrieve the control strategy from the target server and then control the access request according to the control strategy to achieve normal frequency control service. Compared with frequency control methods provided by related technologies, the server in this application is deployed in a server-side distributed cluster mode. When performing frequency control on access requests, it can route the access request to the corresponding target server based on the routing strategy. If one server fails, it can route to another server, resulting in good service stability.
[0114] The method provided in this application can be applied to various scenarios requiring frequency control services, such as those provided by financial institutions and payment institutions. The method provided in this application can be executed by a computer device, which can be a terminal or a server.
[0115] Next, with reference to the accompanying drawings, the frequency control method provided in this application will be described from the perspective of client-server interaction. See also Figure 1 As shown, the method includes:
[0116] S101. The client obtains an access request, which includes a request identifier.
[0117] The client can provide various functions, such as login, transaction, compliance, and sales functions. When users use these functions, they may trigger access requests through the client, which are used to implement the corresponding functions.
[0118] Various functions can be implemented through corresponding systems. For example, the login function can be implemented through the login system, the transaction function can be implemented through the transaction system, the compliance function can be implemented through the compliance system, and the sales function can be implemented through the sales system.
[0119] To facilitate the differentiation of access request sources and subsequent statistical analysis of access frequency from corresponding sources to determine whether to intercept the request and implement frequency control services, access requests can include a request identifier. This identifier identifies the source of the access request. Specifically, the request identifier can indicate the device or user that triggered the access request, as well as the corresponding service. For example, the request identifier can include a user identifier (ID) and a service ID, or it can include the client's Internet Protocol (IP) and service ID.
[0120] S102. The client routes the access request to the target server in the server-side distributed cluster according to the routing policy.
[0121] After receiving an access request, the client can route the request to the target server in the distributed cluster according to the routing strategy. The routing strategy could be a consistent hashing routing strategy used by the client when sending the access request to the server, ensuring a high hit rate even in the event of a single point of failure on the server side.
[0122] This application does not limit the timing of reporting access requests to the target server. In one possible implementation, the client can route access requests to the target server in the server's distributed cluster in real time.
[0123] In another possible implementation, to avoid excessive processing and reduce resource consumption, the client can route access requests to the target server in the distributed server cluster only when certain conditions are met. In this case, the method for routing access requests to the target server in the distributed server cluster according to the routing strategy could be to push the access request to a request buffer queue, then read the access request from the request buffer queue, and route it to the target server according to the routing strategy. The request buffer queue can provide an access request reporting interface for the caller, thereby pushing access requests to the request buffer queue so that access requests can be read from the request buffer queue and reported to the target server.
[0124] Access requests can be cached by using a request buffer queue. When access requests in the request buffer queue meet certain conditions (such as reaching a certain number or at certain intervals), the access requests are then read from the request buffer queue and reported to the target server, thereby avoiding excessively frequent reporting and subsequent processing, and reducing resource consumption.
[0125] In one possible implementation, the client may include a local control service plugin, which reads access requests from the request buffer queue and reports them to the target server. The local control service plugin can periodically (e.g., 1ms) aggregate the reported data in the request buffer queue and send it to the server's distributed cluster. Simultaneously, it pulls pre-calculated control policies from the server's distributed cluster and writes them to the policy buffer queue, incrementally retrieving control policies relevant to the local business.
[0126] S103. The target server accumulates the frequency based on the request identifier to obtain the current accumulated frequency value, and reads the pre-configured control generation rules.
[0127] Upon receiving an access request, the target server can accumulate the current cumulative frequency value based on the request identifier in the request and read the pre-configured control generation rules to generate control policies subsequently. These control generation rules can be stored in the rule configuration management service module, and therefore can be read from this module. The rule configuration management service module is used to configure business logic and control generation rules, supporting both single-policy generation and complex combined policy generation.
[0128] In one possible implementation, the target server may include a frequency service module, which can be used to obtain the current accumulated frequency value. The frequency service module can be distributed across a cluster. The front-end service plugin, through a configured routing strategy, routes access requests with the same request identifier to the same target server for frequency accumulation and generates control policies based on configured control generation rules. The implementation uses the Thrift network programming framework, providing a Thrift Remote Procedure Call (RPC) interface that supports various common programming languages, including Java, C#, C, C++, Node.js, Python, and HypertextPreprocessor (PHP).
[0129] Frequency accumulation involves adding variables, and the key is finding the correct memory node for accumulation. The frequency service module uses a key-value storage model, indexing the corresponding frequency accumulation memory node using either (user ID, service ID, time unit, time point) or (client IP, service ID, time unit, time point) as the key. This memory node stores complete information about the frequency limit, including an unsigned counter for the frequency accumulation.
[0130] Based on the characteristic of frequency accumulation, in one possible implementation, the method of obtaining the current accumulated frequency value by accumulating frequency based on the request identifier can be to obtain the first memory node based on the request identifier, and then accumulate the frequency based on the existing accumulated frequency value stored in the first memory node to obtain the current accumulated frequency value.
[0131] In one possible implementation, when storing existing accumulated frequency values or accumulating frequencies in memory nodes (e.g., the first memory node), a lock-free multidimensional hashing method based on shared memory can be used to improve access speed. The frequency service module achieves extremely high read and write speeds by storing data in shared memory using multidimensional hashing. To improve the concurrent processing capability of the frequency service module, it is designed as a network processing model using EPOLL (a read / write event notification mechanism, an improved poll for handling large batches of file descriptors) plus a thread pool. In high-concurrency scenarios, when writing data to shared memory, to ensure data accuracy without locking, lock-free programming techniques are used to reduce the performance overhead of locking. In this case, using the Linux system's built-in _sync_* series of application programming interfaces (APIs) to modify the data in the memory nodes is the optimal choice.
[0132] The embodiments of this application employ multidimensional hashing and lock-free technology to achieve atomic updates of memory nodes, resulting in high update efficiency.
[0133] Understandably, if a memory node has not been updated for a certain period of time, it becomes an expired node and needs to be allocated to other request identifiers. If memory resource expiration and reclamation are not supported, this would lead to a significant waste of memory resources. Therefore, in one possible implementation, this embodiment can also determine whether each memory node (e.g., a second memory node) has not been updated for a preset time. If a second memory node has not been updated for a preset time, it indicates that it has not been updated for a long time and can be considered an expired node, thus allowing it to be allocated to other request identifiers.
[0134] The preset time in this application embodiment can be an expiration time, which can be set according to actual needs. For example, the expiration time for second-level time nodes is set with 60 time units, the expiration time for minute-level time nodes is set with 10 time units, and the expiration time for hourly and day-level time nodes is set with 3 time units.
[0135] By determining whether memory nodes have expired and reclaiming expired memory nodes, memory resource waste can be avoided.
[0136] It should be noted that the frequency accumulation method is crucial during the frequency control service process. A suitable accumulation method can yield a more accurate current accumulated frequency value, thereby achieving a more accurate frequency control service.
[0137] In this application embodiment, to adapt to different business scenarios, multiple accumulation methods are provided. Some accumulation methods are more suitable for implementing frequency control services in scenarios of manual attacks within a fixed period, while others are more suitable for implementing frequency control services in scenarios of continuous attacks initiated by machines. Based on this, in one possible implementation, the method of obtaining the current accumulated frequency value by accumulating frequency based on the request identifier can be to determine the target accumulation method from multiple accumulation methods based on the request identifier and the business scenario, and then accumulate the frequency according to the target accumulation method to obtain the current accumulated frequency value.
[0138] The above embodiments support multiple accumulation methods. When accumulating frequencies, the appropriate accumulation method can be selected according to the business scenario, thereby obtaining a more accurate current accumulated frequency value and achieving a more accurate frequency control service.
[0139] In one possible implementation, multiple accumulation methods can be based on frequency accumulation within different time windows, such as frequency accumulation based on a rolling time window and frequency accumulation based on a sliding time window. A rolling time window is divided according to a fixed time interval, and the elements between windows do not overlap. The biggest advantage of this type of window is its simplicity, making it suitable for situations where access requests reported by a certain business are accumulated according to a fixed period. The allocation process of access requests within the rolling time window is as follows: Figure 2 As shown.
[0140] A sliding time window adds a sliding time interval to a scrolling window, allowing window data to overlap. It can count recent access requests based on a user-specified window size, such as calculating the current cumulative frequency of access requests within the last 3 seconds. The allocation process of access requests within the sliding time window is as follows: Figure 3 As shown.
[0141] The above embodiments support frequency accumulation using both sliding and rolling time windows, and can calculate the frequency within the most recent time range and the frequency within a fixed time window range.
[0142] S104. The target server generates a control strategy based on the cumulative frequency value and the control generation rules.
[0143] The target server can generate control policies based on cumulative frequency values and control generation rules. These rules specify which control policies to generate under different circumstances. After generating the control policies, they can be synchronized to the control service module for querying by business systems. This simplifies queries, making them lightweight, computationally efficient, and avoids adding unnecessary burden to business systems.
[0144] In one possible implementation, the control strategy can be generated based on the cumulative frequency value and the control generation rule by comparing the cumulative frequency value with the frequency control threshold to obtain a comparison result. The comparison result can indicate whether the cumulative frequency value exceeds the frequency control threshold, and then the control strategy can be generated based on the comparison result and the control generation rule.
[0145] The frequency control threshold can be preset, based on experience, or set based on analysis results. If the frequency control threshold is set too high, the frequency control service will fail to provide the necessary protection; if it is set too low, the frequency control service is prone to numerous false alarms, impacting business operations. Therefore, in one possible implementation, to make the set frequency control threshold more reasonable, the access frequencies of different users can be analyzed. If the analysis results determine that users exceeding the target frequency are abnormal users, then the target frequency is determined as the frequency control threshold.
[0146] The above methods can determine a more reasonable frequency control threshold, avoiding setting the frequency control threshold too high so that the frequency control service cannot play its due protective role, and setting the frequency control threshold too low so that the frequency control service is prone to a large number of erroneous control situations, which will affect the business.
[0147] In one possible implementation, the target server can also provide a control policy persistence service, thereby synchronizing the control policy to persistent storage. After the target server loses power or restarts, the control policy can be restored from persistent storage to shared memory to avoid data loss.
[0148] S105. The target server sends the control policy to the client.
[0149] S106. The client processes the access request according to the control policy.
[0150] After generating the control policy, the target server can distribute the control policy to the client, so that the client can control the access requests according to the control policy. Specifically, the client can proactively send the control policy to the target server, and when the client retrieves it, the target server will distribute the control policy to the client.
[0151] In one possible implementation, after the control policy is generated, it can be stored in shared memory. The control policy can be sent to the client by reading the control policy from the shared memory and then sending the control policy to the client.
[0152] In one possible implementation, to avoid excessive client-side control processing and reduce resource consumption, control policy caching can be implemented. This involves retrieving control policies from the target server and writing them to a policy buffer queue. Then, the client can process access requests according to these control policies by reading them from the policy buffer queue and applying them accordingly.
[0153] The control policy cache allows the caller to push control policies to the policy buffer queue, and simultaneously obtain instructions on whether to control the current access request through the control policy shared memory.
[0154] The above method allows for the reading of control policies from the policy buffer queue when access requests need to be controlled, thereby preventing the client from performing control processing too frequently and reducing resource consumption.
[0155] The foregoing embodiments have provided a detailed description of the frequency control method. The overall architecture for implementing frequency control services using the frequency control method provided in this application can be found in [reference needed]. Figure 4As shown, the system mainly consists of a client-side and server-side distributed cluster. The client generates access requests through systems such as login, transaction, compliance, and sales, and pushes these requests to a request buffer queue. The control service local plugin reads the access requests from the request buffer queue and routes them to the target server in the server-side distributed cluster according to the routing strategy. The frequency service module of the target server accumulates the frequency of the access requests to obtain the current accumulated frequency value and reads the pre-configured control generation rules from the rule configuration management service module. The frequency service module generates a control policy based on the accumulated frequency value and the control generation rules, sends the control policy to the control service module, and synchronizes the control policy to persistent storage. The client's control service local plugin incrementally pulls the control policy and pushes it to the policy buffer queue. When control of an access request is needed, the client reads the control policy from the policy buffer queue to process the access request.
[0156] Based on the frequency control method provided in the foregoing embodiments, this application also provides a frequency control device, see [link to previous document]. Figure 5 The device includes:
[0157] Acquisition unit 501 is used to acquire an access request, wherein the access request includes a request identifier;
[0158] The routing unit 502 is used to route the access request to the target server of the server-side distributed cluster according to the routing policy. The target server is used to accumulate the frequency based on the request identifier to obtain the current accumulated frequency value, and generate a control policy according to the accumulated frequency value and the control generation rules.
[0159] Pull unit 503 is used to pull the control policy from the target server;
[0160] The processing unit 504 is used to control the access request according to the control policy.
[0161] In one possible implementation, the routing unit is used for:
[0162] Push the access request to the request buffer queue;
[0163] The access request is read from the request buffer queue and routed to the target server according to the routing strategy.
[0164] In one possible implementation, the pull unit is used for:
[0165] The control policy is retrieved from the target server and written to the policy buffer queue;
[0166] The processing unit is used for:
[0167] The control policy is read from the policy buffer queue, and the access request is controlled according to the control policy.
[0168] As can be seen from the above technical solution, upon receiving an access request, the access request, including its identifier, can be obtained. Then, the access request is routed to the target server in the server-side distributed cluster according to the routing strategy. The server-side distributed cluster includes multiple servers. Typically, these servers will not simultaneously fail or experience network failures. The routing strategy can route the access request to a suitable server within the server-side distributed cluster (i.e., the target server), ensuring that the target server is functioning correctly and preventing server failures or network failures from affecting the frequency control service. In this way, the normally functioning target server can accumulate the current cumulative frequency value based on the request identifier and generate a control strategy based on the cumulative frequency value and control generation rules. Subsequently, the client can retrieve the control strategy from the target server and then process the access request according to the control strategy, thus achieving normal frequency control service. Compared with the frequency control methods provided by related technologies, the server in this application is deployed in a server-side distributed cluster mode. When performing frequency control on access requests, the access request can be routed to the corresponding target server based on the routing strategy. If one server fails, it can be routed to another server, resulting in good service stability.
[0169] Based on the frequency control method provided in the foregoing embodiments, this application also provides another frequency control device, see [link to previous document]. Figure 6 The device includes:
[0170] The acquisition unit 601 is used to acquire the access request uploaded by the client. The access request includes a request identifier and is routed by the client to the target server of the server-side distributed cluster according to the routing strategy.
[0171] Accumulation unit 602 is used to accumulate frequency based on the request identifier to obtain the current accumulated frequency value;
[0172] The acquisition unit 601 is also used to read pre-configured control generation rules;
[0173] The generation unit 603 is used to generate a control strategy based on the frequency accumulation value and the control generation rules;
[0174] The distribution unit 604 is used to distribute the control policy to the client.
[0175] In one possible implementation, the accumulation unit is used for:
[0176] The first memory node is obtained based on the request identifier;
[0177] The current cumulative frequency value is obtained by accumulating the existing cumulative frequency value stored in the first memory node.
[0178] In one possible implementation, the apparatus further includes an allocation unit, the allocation unit being configured to:
[0179] If the second memory node is not updated within a preset time, the second memory node will be allocated to other request identifiers.
[0180] In one possible implementation, the accumulation unit is used for:
[0181] Based on the request identifier and business scenario, the target accumulation method is determined from multiple accumulation methods;
[0182] The current cumulative frequency value is obtained by accumulating the frequency according to the target accumulation method.
[0183] In one possible implementation, the generating unit is used for:
[0184] The cumulative frequency value is compared with the frequency control threshold to obtain the comparison result;
[0185] The control strategy is generated based on the comparison results and the control generation rules.
[0186] In one possible implementation, the device further includes an analysis unit and a determination unit:
[0187] The analysis unit is used to analyze visitors with different access frequencies and obtain analysis results.
[0188] The determining unit is configured to determine the target frequency as the frequency control threshold if, based on the analysis results, an access party exceeding the target frequency is determined to be an abnormal access party.
[0189] In one possible implementation, the device further includes a storage unit:
[0190] The storage unit is used to store the control strategy in shared memory;
[0191] The sending unit is used to read the control policy from the shared memory and send the control policy to the client.
[0192] In one possible implementation, the device further includes a synchronization unit and a recovery unit:
[0193] The synchronization unit is used to synchronize the control strategy to persistent storage;
[0194] The recovery unit is used to restore the control policy from the persistent storage to the shared memory after the target server is powered off or restarted.
[0195] This application also provides a computer-readable storage medium for storing program code, which, when executed by a processor, implements the method described in any of the foregoing embodiments.
[0196] This application also provides a computer program product, which includes program code. When the program code is executed by a processor, it implements the method described in any of the foregoing embodiments.
[0197] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium can be at least one of the following media: read-only memory (ROM), RAM, magnetic disk, or optical disk, etc., and other media capable of storing program code.
[0198] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The device and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0199] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A frequency control method characterized by, The method includes: Obtain an access request, wherein the access request includes a request identifier; The access request is routed to the target server in the server-side distributed cluster according to the routing strategy. Access requests with the same request identifier are routed to the same target server in the server-side distributed cluster. The target server is used to accumulate the frequency based on the request identifier to obtain the current accumulated frequency value, and to generate a control strategy based on the accumulated frequency value and the control generation rules. The control policy is retrieved from the target server. The access request is controlled and processed according to the control policy; The routing strategy is a consistent hashing routing strategy; Both the control strategy and the storage method of the cumulative frequency value adopt a lock-free hash method based on shared memory.
2. The method according to claim 1, characterized in that, The step of routing the access request to the target server in the server-side distributed cluster according to the routing strategy includes: Push the access request to the request buffer queue; The access request is read from the request buffer queue and routed to the target server according to the routing strategy.
3. The method according to claim 1, characterized in that, The step of pulling the control policy from the target server includes: The control policy is retrieved from the target server and written to the policy buffer queue; The step of controlling the access request according to the control policy includes: The control policy is read from the policy buffer queue, and the access request is controlled according to the control policy.
4. A frequency control method, characterized in that, The method includes: The system retrieves access requests uploaded by the client, the access requests including a request identifier, and the access requests are routed by the client to the target server in the server-side distributed cluster according to the routing strategy. Access requests with the same request identifier are routed to the same target server in the server-side distributed cluster. The system accumulates the frequency based on the request identifier to obtain the current accumulated frequency value and reads the pre-configured control generation rules. A control strategy is generated based on the cumulative frequency value and the control generation rules; The control policy is sent to the client. The routing strategy is a consistent hashing routing strategy; Both the control strategy and the storage method of the cumulative frequency value adopt a lock-free hash method based on shared memory.
5. The method according to claim 4, characterized in that, The step of accumulating the frequency based on the request identifier to obtain the current accumulated frequency value includes: The first memory node is obtained based on the request identifier; The current cumulative frequency value is obtained by accumulating the existing cumulative frequency value stored in the first memory node.
6. The method according to claim 5, characterized in that, The method further includes: If the second memory node is not updated within a preset time, the second memory node will be allocated to other request identifiers.
7. The method according to claim 4, characterized in that, The step of accumulating the frequency based on the request identifier to obtain the current accumulated frequency value includes: Based on the request identifier and business scenario, the target accumulation method is determined from multiple accumulation methods; The current cumulative frequency value is obtained by accumulating the frequency according to the target accumulation method.
8. The method according to any one of claims 4-7, characterized in that, The step of generating a control strategy based on the cumulative frequency value and the control generation rules includes: The cumulative frequency value is compared with the frequency control threshold to obtain the comparison result; The control strategy is generated based on the comparison results and the control generation rules.
9. The method according to claim 7, characterized in that, The method further includes: The analysis results were obtained by analyzing visitors with different access frequencies. If, based on the analysis results, it is determined that an access party exceeding the target frequency is an abnormal access party, then the target frequency is determined as the frequency control threshold.
10. The method according to any one of claims 4-7, characterized in that, The method further includes: The step of sending the control policy to the client includes: The control policy is read from the shared memory and then sent to the client.
11. The method according to claim 10, characterized in that, The method further includes: Synchronize the control policy to persistent storage; After the target server is powered off or restarted, the control policy is restored from the persistent storage to the shared memory.
12. A frequency control device, characterized in that, The device includes: An acquisition unit is used to acquire an access request, wherein the access request includes a request identifier; The routing unit is used to route the access request to the target server in the server-side distributed cluster according to the routing strategy. Access requests with the same request identifier are routed to the same target server in the server-side distributed cluster. The target server is used to accumulate the frequency based on the request identifier to obtain the current accumulated frequency value, and generate a control strategy according to the accumulated frequency value and the control generation rules. A pull unit is used to pull the control policy from the target server. A processing unit is configured to control and process the access request according to the control policy; The routing strategy is a consistent hashing routing strategy; Both the control strategy and the storage method of the cumulative frequency value adopt a lock-free hash method based on shared memory.
13. A frequency control device, characterized in that, The device includes: The acquisition unit is used to acquire the access request uploaded by the client. The access request includes a request identifier and is routed by the client to the target server in the server-side distributed cluster according to the routing strategy. The accumulation unit is used to accumulate frequencies based on the request identifier to obtain the current accumulated frequency value; The acquisition unit is also used to read pre-configured control generation rules; The generation unit is used to generate a control strategy based on the cumulative frequency value and the control generation rules; The distribution unit is used to distribute the control policy to the client; The routing strategy is a consistent hashing routing strategy; Both the control strategy and the storage method of the cumulative frequency value adopt a lock-free hash method based on shared memory.
Citation Information
Patent Citations
Access frequency control method and access frequency control system
CN114760121A