Front-end and back-end data interaction method and device based on dynamic balance, equipment and medium
Through the front-end and back-end data interaction method based on dynamic equalization, the optimal back-end service module is dynamically selected and data transmission is transmitted through persistent connections, which solves the delay and overload problems of traditional Session in front-end data communication, and realizes load balancing and low Delayed data transmission.
Patent Information
- Application Number
- CN202411650317.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-02-18
AI Technical Summary
Traditional Session has high latency and overload problems in front-end data communication, making it difficult to achieve rational utilization of resources and real-time connection.
A front-end and back-end data interaction method based on dynamic equalization is proposed. By generating and adjusting the performance parameter group of the back-end service module, dynamically selecting the optimal back-end service module for data transmission, and achieving persistent connections through the data interaction interface layer.
Load balancing is realized, server load is reduced, front and back end data communication latency is reduced, and overall system performance and user experience is improved.
Smart Images

Figure CN119484535A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine learning technology, and in particular to a front-end and back-end data interaction method, device, equipment and medium based on dynamic balancing. Background Art
[0002] At present, with the development of Web application technology, traditional Internet front-end and back-end coupled applications are gradually replaced by front-end and back-end separated Web application systems. Under the front-end and back-end separated architecture, the functions of the front-end and back-end are clearly divided. The front-end mainly processes page logic and user interaction, while the back-end mainly processes data and implements logic. The separated architecture allows the front-end and back-end to be developed independently and no longer depend on each other, thereby improving development efficiency. At the same time, the separation of the front-end and back-end also allows the front-end staff to focus more on interface design and user experience optimization, while the back-end staff can focus on the implementation of business logic and the improvement of data processing capabilities. When the front-end and the back-end need to communicate, the traditional Session is usually used as a bridge to connect the front-end and the back-end. However, when the traditional Session is used as a bridge to connect the front-end and the back-end, there are problems of high communication latency and overload. Summary of the invention
[0003] The main purpose of the embodiments of the present application is to propose a front-end and back-end data interaction method, device, equipment and medium based on dynamic balancing, which can reasonably utilize computing resources, reduce server load, and reduce front-end and back-end data communication delays.
[0004] To achieve the above purpose, an embodiment of the present application proposes a front-end and back-end data interaction method based on dynamic balancing, the method comprising: When a front-end and back-end interaction request is obtained through the front-end user interface, a performance parameter group corresponding to each back-end service module is generated according to the performance of each back-end service module; Dynamically adjusting the parameter configuration mode of the performance parameter group according to the target condition, and obtaining the performance parameter group after the dynamic adjustment as the optimal performance parameter group, wherein the target condition includes the response time for responding to the front-end and back-end interaction request and the weight value of each parameter in the performance parameter group; Determining a target backend service module from the plurality of backend service modules according to the optimal performance parameter group corresponding to each backend service module; The front-end user interface is connected to the target back-end service module through a data interaction interface layer to perform communication data transmission.
[0005] In some embodiments, the parameter configuration mode of the performance parameter group is dynamically adjusted according to the target condition to obtain the performance parameter group after the dynamic adjustment as the optimal performance parameter group, wherein the target condition includes the response time for responding to the front-end and back-end interaction request and the weight value of each parameter in the performance parameter group, including: Based on the performance parameter group, generating an element matrix, each element in the element matrix represents a parameter configuration mode of the performance parameter group; Based on a preset fitness function, determining the fitness of each of the elements in the element matrix, wherein the response time and the weight value are used as parameters of the fitness function; Based on a preset population optimization algorithm, after updating the target element in the element matrix, the element corresponding to the highest fitness is taken as the target, and each of the elements in the element matrix is updated to update the element matrix; When the number of times the element matrix is updated reaches the preset number of iterations, a target element matrix is obtained; The parameter configuration mode corresponding to the element with the highest fitness in the target element matrix is taken as the optimal parameter configuration mode, and the optimal performance parameter group corresponding to the optimal parameter configuration mode is obtained.
[0006] In some embodiments, the step of connecting the front-end user interface and the target back-end service module through a data interaction interface layer to perform communication data transmission includes the step of encrypting the communication data transmitted through the data interaction interface layer; The step of encrypting and transmitting the communication data transmitted through the data interaction interface layer includes: Sending a preset protocol and a key to the target backend service module via the front-end user interface; After decoding by the target backend service module according to the key, converting the preset protocol into an encrypted transmission protocol corresponding to the key; The front-end user interface is connected to the target back-end service module by using the interface corresponding to the encrypted transmission protocol, and communication and data transmission are performed between the front-end user interface and the target back-end service module.
[0007] In some embodiments, the method further comprises: When a plurality of the front-end and back-end interaction requests are obtained, a plurality of the target back-end service modules are obtained, and all the target back-end service modules are sorted; The sorted multiple target backend service modules are used to respond to the target frontend and backend interaction requests among the multiple frontend and backend interaction requests until each of the frontend and backend interaction requests is responded to.
[0008] In some embodiments, the method further comprises: When a plurality of the front-end and back-end interaction requests are obtained, determining a priority score for each of the back-end service modules based on the optimal performance parameter group corresponding to each of the back-end service modules; Based on the priority score of each of the backend service modules, all the backend service modules are sorted and a polling response strategy is generated; The polling response strategy is executed so that each of the front-end and back-end interaction requests is responded to by the sorted target back-end service module.
[0009] In some embodiments, executing the polling response strategy so that each of the front-end and back-end interaction requests is responded to by a sorted target back-end service module includes: Determining a round value of each of the backend service modules based on the priority score of each of the backend service modules; Determining available backend service modules according to the round value of each of the backend service modules; According to the ranking number of each of the available backend service modules, respond to the target frontend-backend interaction request among the multiple frontend-backend interaction requests through each of the available backend service modules, and update the round value of each of the available backend service modules; When an unresponded front-end and back-end interaction request is detected, the step of determining available back-end service modules according to the round value of each back-end service module is returned to execution until the round value of each back-end service module is less than a preset value.
[0010] In some embodiments, executing the polling response strategy so that each of the front-end and back-end interaction requests is responded to by a sorted target back-end service module includes: Determining a round value of each of the backend service modules based on the priority score of each of the backend service modules; Determine the current backend service module according to the sequence number of each backend service module; Responding to the front-end and back-end interaction request through the current back-end service module, and decreasing the round value of the current back-end service module; When the round value of the current backend service module is zero and an unresponded front-end and back-end interaction request is detected, the next backend service module is used as the current backend service module, and the process returns to executing the steps of responding to the front-end and back-end interaction request through the current backend service module and decreasing the round value of the current backend service module until the round value of each backend service module is zero.
[0011] To achieve the above-mentioned purpose, another aspect of the embodiment of the present application proposes a front-end and back-end data interaction device based on dynamic balancing, the device comprising: An acquisition module, configured to generate a performance parameter group corresponding to each backend service module according to the performance of each backend service module when a frontend-backend interaction request is acquired through a frontend user interface; An adjustment module, used to dynamically adjust the parameter configuration mode of the performance parameter group according to the target condition, and obtain the performance parameter group after the dynamic adjustment as the optimal performance parameter group, wherein the target condition includes the response time for responding to the front-end and back-end interaction request and the weight value of each parameter in the performance parameter group; A selection module, configured to determine a target backend service module from a plurality of the backend service modules according to an optimal performance parameter group corresponding to each of the backend service modules; The connection module is used to connect the front-end user interface with the target back-end service module through the data interaction interface layer for communication and data transmission.
[0012] To achieve the above-mentioned purpose, another aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned front-end and back-end data interaction method based on dynamic balancing when executing the computer program.
[0013] To achieve the above objectives, another aspect of an embodiment of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the front-end and back-end data interaction method based on dynamic balancing is implemented.
[0014] The embodiments of the present application include at least the following beneficial effects: In an embodiment of the present application, a performance parameter group of a backend service is generated based on real-time performance data and real-time request load to adapt to different front-end and back-end interaction requests. On this basis, the performance parameter group is adjusted according to target conditions such as response time and weight value to determine the optimal performance parameter group, and the target backend service module is determined from multiple backend service modules based on the optimal performance parameter group, thereby ensuring that data is transmitted to the most appropriate service module, so as to achieve load balancing and avoid overloading of local backend service modules by dynamically selecting the optimal backend service module. After determining the target backend service module, communication data transmission is performed through the data interaction interface layer. This persistent connection method can reduce the delay caused by frequent establishment and disconnection of connections, and because the data interaction interface layer can maintain a persistent connection, it is helpful to reduce additional computing resource overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1This is a flow chart of a front-end and back-end data interaction method based on dynamic balancing provided in an embodiment of the present application; Figure 2 It is a flowchart of step S102 in the front-end and back-end data interaction method based on dynamic balancing provided in an embodiment of the present application; Figure 3 It is a flowchart of step S104 in the front-end and back-end data interaction method based on dynamic balancing provided in an embodiment of the present application; Figure 4 This is another flow chart of the front-end and back-end data interaction method based on dynamic balancing provided in an embodiment of the present application; Figure 5 This is another flow chart of the front-end and back-end data interaction method based on dynamic balancing provided in an embodiment of the present application; Figure 6 It is a flow chart of step S503 in the front-end and back-end data interaction method based on dynamic balancing provided in an embodiment of the present application; Figure 7 This is another flow chart of step S503 in the front-end and back-end data interaction method based on dynamic balancing provided in an embodiment of the present application; Figure 8 It is a structural diagram of a front-end and back-end interactive system when a front-end and back-end data interaction method based on dynamic balancing is applied in the front-end and back-end interactive system; Fig. 9 It is a structural diagram of a front-end and back-end data interaction device based on dynamic balancing provided in an embodiment of the present application; Fig.10 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0016] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below in conjunction with the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the embodiments of the present application. They are only examples of devices and methods consistent with some aspects of the embodiments of the present application as detailed in the attached claims.
[0017] Before describing the embodiments of the present application in detail, some nouns and terms involved in the embodiments of the present application are first described. The nouns and terms involved in the embodiments of the present application are subject to the following explanations.
[0018] RESTful API refers to an application program interface (API) design style based on the HTTP protocol, namely "Representational State Transfer", which uses the verbs or methods in the HTTP protocol (such as GET, POST, PUT, DELETE, etc.) to operate and process data in network applications. It locates resources through a unique resource identifier (usually a URL) and implements resource creation, reading, updating, and deletion operations through HTTP requests.
[0019] The Session mechanism refers to a technology used to track user status in Web applications.
[0020] Web (World Wide Web) refers to the technical fields such as network and Internet, which are widely translated. It is manifested in three forms, namely hypertext, hypermedia, and Hypertext Transfer Protocol (HTTP).
[0021] Sparrow Search Algorithm (SSA) refers to a swarm intelligence optimization algorithm inspired by the foraging and anti-predation behaviors of sparrows.
[0022] At present, with the development of Web application technology, traditional Internet front-end and back-end coupled applications are gradually replaced by front-end and back-end separated Web application systems. In traditional Web applications, the Session mechanism is often used to maintain sessions for authentication during the data interaction between the client and the server. Under the front-end and back-end separated architecture, the functions of the front-end and back-end are clearly divided: the front-end mainly processes page logic and user interaction, while the back-end mainly processes data and implements logic. The separated architecture allows the front-end and back-end to be developed independently and no longer depend on each other, thereby improving development efficiency. At the same time, the front-end and back-end separation also allows front-end staff to focus more on interface design and user experience optimization, while back-end staff can focus on the implementation of business logic and the improvement of data processing capabilities. In addition, the front-end and back-end separated architecture enables back-end services to provide services across terminals (platforms). Whether it is a Web browser, mobile application or desktop application, as long as they can send requests that meet the specifications, they can communicate and exchange data with the back-end service. This cross-platform capability broadens the use scenarios of Web applications and provides users with a more convenient and rich experience.
[0023] However, when using the traditional Session as a bridge to connect the front-end and back-end, these problems still exist: first, the traditional Session cannot achieve the rational application of resources, resulting in an increase in the load of the local server; second, the traditional Session cannot establish a real-time connection, resulting in a long delay when the front-end request is sent to the back-end for processing or when the back-end processing is fed back to the front-end. In order to solve the above problems, the main purpose of the embodiments of the present application is to propose a front-end and back-end data interaction method, device, equipment and medium based on dynamic balancing, which can reasonably utilize computing resources, reduce the load of the server, and reduce the front-end and back-end data communication delay.
[0024] Figure 1 is a flowchart of a method for front-end and back-end data interaction based on dynamic balancing provided by an embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S104.
[0025] Step S101, when a front-end and back-end interaction request is obtained through the front-end user interface, a performance parameter group corresponding to each back-end service module is generated according to the performance of each back-end service module.
[0026] Step S102, dynamically adjust the parameter configuration mode of the performance parameter group according to the target condition, and obtain the performance parameter group after dynamic adjustment as the optimal performance parameter group, wherein the target condition includes the response time for responding to the front-end and back-end interaction requests and the weight value of each parameter in the performance parameter group.
[0027] Step S103: determining a target backend service module from a plurality of backend service modules according to the optimal performance parameter group corresponding to each backend service module.
[0028] Step S104, connecting the front-end user interface and the target back-end service module via the data interaction interface layer to perform communication data transmission.
[0029] Steps S101 to S104 shown in the embodiment of the present application adjust the performance parameter group of the backend service according to the real-time performance data and the real-time request load to adapt to different front-end and back-end interaction requests. On this basis, the performance parameter group is adjusted according to target conditions such as response time and weight value. Then, the optimal performance parameter group is determined by a preset number of iterations, and the target backend service module is determined from multiple backend service modules according to the optimal performance parameter group, so as to ensure that data is transmitted to the most suitable service module, so as to achieve load balancing and avoid overloading of local backend service modules by dynamically selecting the optimal backend service module. After determining the target backend service module, communication data transmission is performed through the data interaction interface layer. This persistent connection method can reduce the delay caused by frequent establishment and disconnection of connections, and because the data interaction interface layer can maintain a persistent connection, it is helpful to reduce additional computing resource overhead.
[0030] In step S101 of some embodiments, according to the performance of each backend service module, the performance parameter group corresponding to each backend service module can be generated by collecting the operation data of each backend service module in real time through a monitoring tool, such as CPU usage, memory consumption, I / O operation, etc., and classifying the multiple operation data into performance parameter groups. Optionally, a set of preset performance parameter templates are defined for different service modules, and the style of the performance parameter group is set according to the characteristics of the service modules and historical performance data.
[0031] In step S102 of some embodiments, one of the implementation methods may be: adjusting the parameter configuration mode of the performance parameter group according to a preset number of iterations. For example, when the number of adjustments is equal to the preset number of iterations, the adjusted performance parameter group is used as the optimal performance parameter group. Optionally, the parameter configuration mode of the performance parameter group is adjusted according to the iteration termination condition. The iteration termination condition includes a preset response time threshold, a preset error value range, etc. For example, after the parameter configuration mode of the performance parameter group is adjusted for the third time, in the operating environment of the adjusted performance parameter group, the response time of the front-end user interface interacting with the back-end service module is less than the response time threshold, that is, the parameter configuration mode of the performance parameter group is stopped from being adjusted.
[0032] In step S102 of some embodiments, a genetic algorithm can be applied to simulate the natural selection process to find the optimal performance parameter combination to select the optimal performance parameter group, or a gradient descent optimization algorithm can be used to adjust the parameters to minimize the response time and optimize the performance parameters, thereby adjusting to obtain the optimal performance parameter group.
[0033] In step S103 of some embodiments, optionally, a score is given to each service module based on the score of the optimal performance parameter group, combined with the response time and the parameter weight value, and the module with the highest score is selected.
[0034] In step S104 of some embodiments, the RESTful architectural style is used to transmit data through the HTTP protocol to achieve communication between the front-end and the back-end, or service mesh technologies such as Istio or Linkerd are used to achieve communication between the front-end and the back-end and control the traffic during the communication process.
[0035] See also Figure 2 In some embodiments, step S102 may include but is not limited to steps S201 to S203: Step S201: Generate an element matrix based on the performance parameter group, where each element in the element matrix represents a parameter configuration mode of the performance parameter group.
[0036] Step S202: determining the fitness of each element in the element matrix based on a preset fitness function, wherein the response time and the weight value are used as parameters of the fitness function.
[0037] Step S203, based on a preset population optimization algorithm, after updating the target element in the element matrix, the element corresponding to the highest fitness is taken as the target, and each element in the element matrix is updated to update the element matrix.
[0038] Step S204: When the number of times the element matrix is updated reaches a preset number of iterations, a target element matrix is obtained.
[0039] Step S205: taking the parameter configuration mode corresponding to the element with the highest fitness in the target element matrix as the optimal parameter configuration mode, and obtaining the optimal performance parameter group corresponding to the optimal parameter configuration mode.
[0040] In steps S201 to S203 shown in the embodiment of the present application, a population optimization algorithm is used to iteratively update the element matrix. Through iterative updates with a preset number of iterations, the algorithm can gradually approach the optimal performance parameter configuration until it converges to the optimal solution, thereby increasing the probability of finding the global optimal solution. Moreover, through continuous iterative updates, the system performance is kept optimized, ensuring adaptation to dynamic changes in system load and performance requirements.
[0041] In step S202 of some embodiments, an optional implementation is to design a fitness function that receives the response duration and the parameter weight value as input parameters and calculates the fitness value: for each element in the element matrix, calculate its fitness value. The fitness values are normalized to ensure that the fitness values are at the same level, and the performance of each element is evaluated based on the normalized fitness values. The higher the fitness value, the better the performance parameter configuration method of the element.
[0042] In step S203 of some embodiments, an optional implementation is that, first, the element matrix is used as the initial population, and each element represents a potential solution (i.e., parameter configuration mode). Secondly, the fitness function defined in step S202 is used to evaluate the fitness of each element in the population. Then, according to the fitness value, the elements with higher fitness are selected to enter the next generation using methods such as roulette and tournament selection. Again, the selected elements are crossover (hybridization) operated to generate new offspring. For example, methods such as single-point crossover, multi-point crossover or uniform crossover can be used. Then, certain parameters of the offspring elements are mutated with a certain probability to increase the diversity of the population and avoid premature convergence. Then, the fitness of the newly generated offspring elements is evaluated again. Finally, according to the fitness value, the optimal elements are selected to be retained in the population, and the elements with lower fitness are replaced to form a new population. The selection, crossover, mutation and replacement operations are repeated until the preset number of iterations is reached or other stop conditions are met.
[0043] Optionally, a sparrow optimization algorithm is used as the population optimization algorithm of this embodiment to illustrate this embodiment.
[0044] First, a sparrow population containing different parameter configurations is initialized, where each sparrow represents a possible configuration parameter in the performance parameter group. The sparrow population is represented by the following element matrix:
[0045] Among them, d represents the change dimension, and m represents the number of sparrows in the sparrow population generated this time.
[0046]
[0047] Among them, f() represents the fitness function, which is used to evaluate the response time and load weight of this path.
[0048] F can be calculated by the following formula n :
[0049] In calculating F n After that, the pickers in the flock will continue to track the producer, hoping that the producer will find a better food source. In this case, they will leave their current position to find the target food source, thereby updating the position of one of the sparrows, that is, updating one of the parameter configuration methods. The method of updating the position of the sparrow is as follows:
[0050] After updating the position of one of the sparrows, the entire flock of sparrows is iterated with the best response time and weight as the goal: the fitness evaluation and position update process is repeated until the preset number of iterations is reached. The iteration process can be performed according to the following formula:
[0051] in, and They are respectively the best fitness value and the worst fitness value among the fitness values corresponding to all communication connections established between the front-end and the back-end.
[0052] After the iteration, the sparrow with the highest fitness (i.e. the optimal parameter configuration) is selected.
[0053] See also Figure 3 In some embodiments, step S104 may include a step of encrypting the communication data transmitted through the data interaction interface layer.
[0054] The steps of encrypting and transmitting the communication data transmitted through the data interaction interface layer include but are not limited to steps S301 to S303: Step S301, sending a preset protocol and key to a target backend service module through a frontend user interface.
[0055] Step S302: After decoding by the target backend service module according to the key, the preset protocol is converted into an encrypted transmission protocol corresponding to the key.
[0056] Step S303, using the interface corresponding to the encrypted transmission protocol, the front-end user interface is connected to the target back-end service module, and communication data transmission is performed between the front-end user interface and the target back-end service module.
[0057] When steps S301 to S303 shown in the embodiment of the present application are implemented in a specific application scenario, first, the front-end user interface module and the back-end service module in the front-end user interface are handshaked through the HTTP protocol. During this process, the front-end user interface module sends an Upgrade header with HTTP and a WebSocket key to the back-end service module, which decodes and upgrades the protocol to WebSocket after the response. After a successful handshake, the front-end user interface module establishes a persistent full-duplex connection with the back-end service module, allowing both parties to send and receive data freely. Then, WebSocket is used in JavaScript using the API provided in the browser. The API includes operations such as creating connections, sending messages, receiving messages, and handling connection closures. After one-way or one-way two-way data transmission, WebSocket always maintains the connection between the front-end user interface module and the back-end service module.
[0058] It can be understood that in this embodiment, the encrypted transmission protocol effectively prevents third parties from eavesdropping on the communication content and protects sensitive data from being leaked, and the use of keys provides an authentication mechanism for the system. Only the front-end user interface holding the correct key can establish an encrypted connection with the back-end service module, which enhances the authorization management of the system. By using the preset protocol and key, the security of data during transmission is ensured, and the data is prevented from being intercepted or tampered with during transmission.
[0059] See also Figure 4 In some embodiments, the front-end and back-end data interaction method based on dynamic balancing may further include but is not limited to steps S401 to S402: Step S401, when multiple front-end and back-end interaction requests are obtained, multiple target back-end service modules are obtained, and all target back-end service modules are sorted.
[0060] Step S402: using the sorted multiple target backend service modules to respond to the target frontend and backend interaction requests among the multiple frontend and backend interaction requests until each frontend and backend interaction request is responded to.
[0061] In some embodiments, all target backend service modules are sorted according to a preset sorting rule, and the sorting rule can be flexibly set, such as sorting according to the priority of each target backend service module, sorting according to the idleness of each target backend service module, etc. For example, the target backend service module with the first priority is ranked first in the sequence, the target backend service module with the second priority is ranked second in the sequence, and so on, and the sorting is performed according to the priority of each target backend service module.
[0062] It is understandable that this embodiment ensures that requests are evenly distributed among all available service modules by cyclically sorting the backend service modules, avoiding the situation where some modules are overloaded while other modules are idle. Since requests are allocated to the backend service modules in sequence, the waiting time of requests in the queue can be reduced, thereby improving the response speed.
[0063] See also Figure 5 In some embodiments, the front-end and back-end data interaction method based on dynamic balancing may further include but is not limited to steps S501 to S503: Step S501, when multiple front-end and back-end interaction requests are obtained, the priority score of each back-end service module is determined based on the optimal performance parameter group corresponding to each back-end service module.
[0064] Step S502: sort all backend service modules based on the priority score of each backend service module, and generate a polling response strategy.
[0065] Step S503: execute the polling response strategy so that each front-end and back-end interaction request is responded to by the sorted target back-end service module.
[0066] It can be understood that this embodiment can dynamically adjust the priority of the backend service module according to the real-time performance data to adapt to different workloads and performance changes, while the polling response strategy ensures that all requests have a chance to be processed, achieving fairness and consistency in request processing.
[0067] In some embodiments, when generating a polling response strategy, considering that each backend service module responds to requests at different times, it is necessary to determine the round value of each backend service module to determine the number of times each backend service module responds to requests in each polling.
[0068] Optionally, this embodiment provides a method for determining a round value of a backend service module, the method comprising the following steps: First, according to the performance of the backend service module, a multivariate function group is established as the performance parameter group of the backend service module, and the priority of the backend service module is scored according to the performance parameter group. For example, the multivariate function group is expressed as:
[0069] Optionally, the number of elements of the multivariate function group is determined according to the actual number of evaluation indicators. The evaluation indicators of this embodiment include the resource utilization rate of the backend service module, the data computing ability of the backend service module, the response time of the backend service module, and the number of previous uses of the backend service module. Then, a multivariate function group is established based on the positive and negative correlation between the evaluation indicators and the priority. In this embodiment, the multivariate function is expressed as:
[0070] in, The data computing capability of the backend service module. , , They are the resource utilization rate of the backend service module, the response time of the backend service module, and the number of times the backend service module has been used in the past. , , , They are , , , The weight value of .
[0071] Then, each backend service module is sorted in ascending order according to its priority score. Then, the multivariate function group of each backend service module is normalized. For example, the multivariate function group A of a backend service module i Perform normalization:
[0072] in, Normalized prior priority score for each backend service module, is the normalized priority score, This is the minimum value among all backend service modules.
[0073] Finally, the normalized priority score , according to the principle of rounding, only the integer digits are retained to get the round value .
[0074] See also Figure 6 In some embodiments, step S503 may include but is not limited to steps S601 to S604: Step S601, determining the round value of each backend service module based on the priority score of each backend service module.
[0075] Step S602: Determine available backend service modules according to the round value of each backend service module.
[0076] Step S603, according to the ranking number of each available backend service module, respond to the target frontend-backend interaction request among the multiple frontend-backend interaction requests through each available backend service module, and update the round value of each available backend service module.
[0077] Step S604, when an unresponded front-end and back-end interaction request is detected, return to step S602 and execute until the round value of each back-end service module is less than a preset value.
[0078] Optionally, steps S601 to S604 of this embodiment are described through a specific application scenario.
[0079] After sorting each backend service module, when the first frontend-backend interaction request is received, the backend service module ranked first will respond to the first frontend-backend interaction request in the order of sorting; when the second frontend-backend interaction request is received, the backend service module ranked second will respond to the second frontend-backend interaction request, and so on until all backend service modules respond once, ending the first round of polling response.
[0080] When all backend service modules have responded once and receive a frontend-backend interaction request again, start the second round of polling response, select one of the backend service modules, and determine the round value of the backend service module. Is it less than -1, if yes, then use the backend service module to respond, if no, then in this round of polling response, the backend service module is not used to respond to the front-end and back-end interaction requests. When the second round of polling response, the round value of all backend service modules Both greater than -1, the second round of polling response ends.
[0081] For example, there are four backend service modules Ⅰ, Ⅱ, Ⅲ, and Ⅳ, and their final rounds are 1, 2, 3, and 4 respectively. The first four requests are responded to once by the four backend service modules respectively. When the 5th to 7th requests are received, Ⅱ, Ⅲ, and Ⅳ respond once respectively. When the 8th to 9th requests are received, Ⅲ and Ⅳ respond once respectively. When the 10th request is received, Ⅳ responds once and ends this round. This step is repeated for subsequent requests.
[0082] See also Figure 7 In some embodiments, step S503 may include but is not limited to steps S701 to S704: Step S701, determining the round value of each backend service module based on the priority score of each backend service module.
[0083] Step S702: determine the current backend service module according to the sequence number of each backend service module.
[0084] Step S703: respond to the front-end and back-end interaction request through the current back-end service module, and decrement the round value of the current back-end service module.
[0085] Step S704, when the round value of the current backend service module is zero and an unresponded front-end and back-end interaction request is detected, the next backend service module is used as the current backend service module, and the process returns to step S703 until the round value of each backend service module is zero.
[0086] Optionally, steps S701 to S704 of this embodiment are described through a specific application scenario.
[0087] After sorting each backend service module, when receiving a front-end and back-end interaction request, the backend service module with the first ranking will be selected to respond first, and subsequent requests will give priority to this backend service module until the number of responses of this backend service module is equal to the round value of this backend service module. .
[0088] When the front-end and back-end interaction request is received again, another back-end service module is switched to respond until the number of responses of the other back-end service module is also equal to its round value. .
[0089] Similarly, when the response times of all backend service modules reach their respective round values , then the current round of polling response ends, and the above process is repeated when a new round of polling response begins.
[0090] In some embodiments, the implementation of executing the polling response strategy so that each front-end and back-end interaction request is responded to by the sorted target back-end service module also includes: When obtaining a front-end and back-end interaction request through the front-end user interface, obtain the client's address identification code; use the preset hash function to calculate the hash value corresponding to the client's address identification code; take the modulus of the hash value and map it to the target back-end service module. For example, if there are 3 back-end service modules, take the hash value modulo 3, and the result is 0, 1 or 2, which corresponds to three different back-end service modules respectively. According to the mapping result mapped to the target back-end service module, respond to the front-end and back-end interaction request through the target back-end service module.
[0091] See also Figure 8 , the data interaction between the front-end and back-end separation is mainly realized through the data interaction interface layer. The data interaction interface layer is used for the communication connection between the front-end user interface module and the back-end service module, and the data interaction interface layer adopts the RESTfulAPI design principle to transmit data in JSON or XML format through the HTTP / HTTPS protocol. In this embodiment, by improving the sparrow algorithm model and optimizing the load balancing strategy parameters, the requests of the front-end user interface are dynamically allocated to different back-end service modules, thereby setting a load balancing mechanism for the system. The data interaction interface layer is used to establish a real-time communication connection between the front-end user interface module and the back-end service module, and the data interacted in the data interaction interface layer is securely encrypted, thereby setting a secure encryption mechanism for the system.
[0092] In this embodiment, when implementing a data interaction method based on front-end and back-end separation, the communication connection between the front-end user interface module and the back-end service module is mainly realized through the data interaction interface layer. The solution adopts the RESTful API design principle and transmits data in JSON or XML format through the HTTP / HTTPS protocol.
[0093] First, monitor the performance indicators of the backend service module in real time, such as resource utilization, computing power, response time, and historical usage. Optionally, generate a population containing multiple sparrows (each sparrow represents a different performance parameter configuration method for the backend service module). Through simulation operation, evaluate the response time and load weight of each strategy and calculate the fitness function. According to the fitness evaluation results, update the position of the sparrow, that is, adjust the parameter configuration of the load balancing strategy. Repeat the fitness evaluation and position update process until the preset number of iterations is reached or the optimal solution is found to screen out the optimal backend service module.
[0094] Secondly, a multivariate function is established based on the performance indicators to prioritize each backend service module. The priority scores are normalized to ensure that the scores are of the same magnitude. Based on the normalized priority scores, a polling order is generated to ensure that requests are evenly distributed to each backend service module.
[0095] Then, a backend service module is selected to respond according to the polling strategy. When the selected backend service module reaches the preset number of responses, it switches to the next service module. Continue to distribute requests in the polling order until all backend service modules reach the preset number of responses.
[0096] When the backend service module responds to the front-end and back-end interaction request from the front-end user interface, the front-end user interface module sends a request containing an Upgrade header and a WebSocket key to the backend service module via the HTTP protocol, requesting that the protocol be upgraded to WebSocket. After receiving the request, the backend service module decodes and responds, completing the handshake process, and the protocol is upgraded to WebSocket. Optionally, select a suitable encryption algorithm, such as AES or RSA, based on the sensitivity of the data. Exchange encryption keys through a secure channel. Encrypt the data using the selected encryption algorithm and key before sending it. After receiving the data, the recipient uses the same key and algorithm to decrypt the data.
[0097] After a successful handshake, the front-end and back-end establish a persistent full-duplex connection, allowing both parties to send and receive data freely. After the front-end user interface and the back-end service module establish a WebSocket connection, use the API provided by the browser in JavaScript to manage the WebSocket connection, including creating a connection, sending messages, receiving messages, and handling connection closure to manage the communication data between the front-end user interface and the back-end service module.
[0098] This embodiment can achieve efficient data interaction and dynamic load balancing while ensuring data security, thereby improving the overall performance of the system and user experience.
[0099] It is understandable that the application scenarios of this embodiment include scenarios that require real-time data exchange, such as teacher screens in teaching assistance, online games, real-time monitoring, chat applications, etc., which maintain communication status through long connections, reducing the extra overhead and delay caused by frequent establishment and disconnection of connections. By establishing a load balancing mechanism and using logic to match the response service module for each request, the resources of the service module can be rationally optimized to avoid overloading of local service modules. This embodiment can perform different resource allocation optimizations according to different actual demand scenarios.
[0100] See also Fig. 9 The embodiment of the present application further provides a front-end and back-end data interaction device based on dynamic balancing, which can implement the front-end and back-end data interaction method based on dynamic balancing, and the device includes: The acquisition module 801 is used to generate a performance parameter group corresponding to each backend service module according to the performance of each backend service module when a frontend-backend interaction request is acquired through the frontend user interface.
[0101] The adjustment module 802 is used to dynamically adjust the parameter configuration method of the performance parameter group according to the target conditions, and obtain the performance parameter group after the dynamic adjustment as the optimal performance parameter group, wherein the target conditions include the response time for responding to the front-end and back-end interaction requests and the weight value of each parameter in the performance parameter group.
[0102] The selection module 803 is used to determine a target backend service module from multiple backend service modules according to the optimal performance parameter group corresponding to each backend service module.
[0103] The connection module 804 is used to connect the front-end user interface with the target back-end service module through the data interaction interface layer for communication and data transmission.
[0104] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0105] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned front-end and back-end data interaction method based on dynamic balancing when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0106] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0107] See also Fig.10 , Fig.10 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes: The processor 901 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application; The memory 902 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 902 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 902, and the processor 901 calls and executes the front-end and back-end data interaction method based on dynamic balancing in the embodiment of this application; Input / output interface 903, used to implement information input and output; Communication interface 904, used to realize communication interaction between the device and other devices, which can be realized through wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.); A bus 905 that transmits information between various components of the device (e.g., the processor 901, the memory 902, the input / output interface 903, and the communication interface 904); The processor 901 , the memory 902 , the input / output interface 903 and the communication interface 904 are connected to each other in communication within the device via a bus 905 .
[0108] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the front-end and back-end data interaction method based on dynamic balancing is implemented.
[0109] It can be understood that the contents of the above method embodiments are all applicable to the present storage medium embodiments, the functions specifically implemented by the present storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0110] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0111] In an embodiment of the present application, a performance parameter group of a backend service is generated based on real-time performance data and real-time request load to adapt to different front-end and back-end interaction requests. On this basis, the performance parameter group is adjusted according to target conditions such as response time and weight value. Then, the optimal performance parameter group is determined, and the target backend service module is determined from multiple backend service modules based on the optimal performance parameter group, thereby ensuring that data is transmitted to the most appropriate service module, so as to achieve load balancing and avoid overloading of local backend service modules by dynamically selecting the optimal backend service module. After determining the target backend service module, communication data transmission is performed through the data interaction interface layer. This persistent connection method can reduce the delay caused by frequent establishment and disconnection of connections, and because the data interaction interface layer can maintain a persistent connection, it is helpful to reduce additional computing resource overhead.
[0112] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0113] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0114] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0115] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0116] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0117] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0118] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0119] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0120] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0121] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0122] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A front-end and back-end data interaction method based on dynamic balancing, characterized in that: The method comprises: When a front-end and back-end interaction request is obtained through the front-end user interface, a performance parameter group corresponding to each back-end service module is generated according to the performance of each back-end service module; Dynamically adjusting the parameter configuration mode of the performance parameter group according to the target condition, and obtaining the performance parameter group after the dynamic adjustment as the optimal performance parameter group, wherein the target condition includes the response time for responding to the front-end and back-end interaction request and the weight value of each parameter in the performance parameter group; Determining a target backend service module from the plurality of backend service modules according to the optimal performance parameter group corresponding to each backend service module; The front-end user interface is connected to the target back-end service module through a data interaction interface layer to perform communication data transmission.
2. The front-end and back-end data interaction method based on dynamic balancing according to claim 1 is characterized in that: The dynamically adjusting the parameter configuration mode of the performance parameter group according to the target condition, and obtaining the performance parameter group after the dynamic adjustment as the optimal performance parameter group, wherein the target condition includes the response time of responding to the front-end and back-end interaction request and the weight value of each parameter in the performance parameter group, including: Based on the performance parameter group, generating an element matrix, each element in the element matrix represents a parameter configuration mode of the performance parameter group; Based on a preset fitness function, determining the fitness of each of the elements in the element matrix, wherein the response time and the weight value are used as parameters of the fitness function; Based on a preset population optimization algorithm, after updating the target element in the element matrix, the element corresponding to the highest fitness is taken as the target, and each of the elements in the element matrix is updated to update the element matrix; When the number of times the element matrix is updated reaches the preset number of iterations, a target element matrix is obtained; The parameter configuration mode corresponding to the element with the highest fitness in the target element matrix is taken as the optimal parameter configuration mode, and the optimal performance parameter group corresponding to the optimal parameter configuration mode is obtained.
3. The front-end and back-end data interaction method based on dynamic balancing according to claim 1 is characterized in that: The step of connecting the front-end user interface with the target back-end service module through the data interaction interface layer to perform communication data transmission includes the step of encrypting the communication data transmitted through the data interaction interface layer; The step of encrypting and transmitting the communication data transmitted through the data interaction interface layer includes: Sending a preset protocol and a key to the target backend service module via the front-end user interface; After decoding by the target backend service module according to the key, converting the preset protocol into an encrypted transmission protocol corresponding to the key; The front-end user interface is connected to the target back-end service module by using the interface corresponding to the encrypted transmission protocol, and communication and data transmission are performed between the front-end user interface and the target back-end service module.
4. The front-end and back-end data interaction method based on dynamic balancing according to claim 1 is characterized in that: The method further comprises: When a plurality of the front-end and back-end interaction requests are obtained, a plurality of the target back-end service modules are obtained, and all the target back-end service modules are sorted; The sorted multiple target backend service modules are used to respond to the target frontend and backend interaction requests among the multiple frontend and backend interaction requests until each of the frontend and backend interaction requests is responded to.
5. The front-end and back-end data interaction method based on dynamic balancing according to claim 1 is characterized in that: The method further comprises: When a plurality of the front-end and back-end interaction requests are obtained, determining a priority score for each of the back-end service modules based on the optimal performance parameter group corresponding to each of the back-end service modules; Based on the priority score of each of the backend service modules, all the backend service modules are sorted and a polling response strategy is generated; The polling response strategy is executed so that each of the front-end and back-end interaction requests is responded to by the sorted target back-end service module.
6. The front-end and back-end data interaction method based on dynamic balancing according to claim 5 is characterized in that: The executing the polling response strategy so that each of the front-end and back-end interaction requests is responded to by the sorted target back-end service module includes: Determining a round value of each of the backend service modules based on the priority score of each of the backend service modules; Determining available backend service modules according to the round value of each of the backend service modules; According to the ranking number of each of the available backend service modules, respond to the target frontend-backend interaction request among the multiple frontend-backend interaction requests through each of the available backend service modules, and update the round value of each of the available backend service modules; When an unresponded front-end and back-end interaction request is detected, the step of determining available back-end service modules according to the round value of each back-end service module is returned to execution until the round value of each back-end service module is less than a preset value.
7. The front-end and back-end data interaction method based on dynamic balancing according to claim 5 is characterized in that: The executing the polling response strategy so that each of the front-end and back-end interaction requests is responded to by the sorted target back-end service module includes: Determining a round value of each of the backend service modules based on the priority score of each of the backend service modules; Determine the current backend service module according to the sequence number of each backend service module; Responding to the front-end and back-end interaction request through the current back-end service module, and decreasing the round value of the current back-end service module; When the round value of the current backend service module is zero and an unresponded front-end and back-end interaction request is detected, the next backend service module is used as the current backend service module, and the process returns to executing the steps of responding to the front-end and back-end interaction request through the current backend service module and decreasing the round value of the current backend service module until the round value of each backend service module is zero.
8. A front-end and back-end data interaction device based on dynamic balancing, characterized in that: The device comprises: An acquisition module, configured to generate a performance parameter group corresponding to each backend service module according to the performance of each backend service module when a frontend-backend interaction request is acquired through a frontend user interface; An adjustment module, used to dynamically adjust the parameter configuration mode of the performance parameter group according to the target condition, and obtain the performance parameter group after the dynamic adjustment as the optimal performance parameter group, wherein the target condition includes the response time for responding to the front-end and back-end interaction request and the weight value of each parameter in the performance parameter group; A selection module, configured to determine a target backend service module from a plurality of the backend service modules according to an optimal performance parameter group corresponding to each of the backend service modules; The connection module is used to connect the front-end user interface with the target back-end service module through the data interaction interface layer for communication and data transmission.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the front-end and back-end data interaction method based on dynamic balancing as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the front-end and back-end data interaction method based on dynamic balancing described in any one of claims 1 to 7 is implemented.