Page loading method and device, electronic equipment and computer readable storage medium
By reading the configuration file of the service cluster, obtaining service node information and connection status, generating a list of available service nodes, and selecting the node with the least number of calls to execute the page loading request, solving the problem of page load failure caused by node exceptions in the service cluster, realizing the successful execution of page loading and the stability of the service cluster.
Patent Information
- Application Number
- CN202411833240.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-03-21
AI Technical Summary
In the service cluster, the java service exception of the current node causes the page load to fail, and the load balancing device cannot determine whether the java service is normal, resulting in the problem of failure of the page load.
By reading the preset configuration files of the service cluster, obtaining the node information of each service node, and obtaining the service interface connection status based on the node information, and generating a list of available service nodes. When a page load request is received, the available service node with the least number of calls is selected to execute the request.
It effectively ensures that the node with normal service and lowest load is requested in the service cluster, ensures the successful execution of page loading, and ensures the stability of the service cluster.
Smart Images

Figure CN119668724A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of cluster services, and in particular to a page loading method, and also to a page loading device, an electronic device, and a computer-readable storage medium. Background Art
[0002] To ensure high availability of services, currently common web applications are deployed in clusters. For example, in a 3-node cluster, when a browser loads a page, it will access the server-side rendered nestjs (a development framework for building efficient and scalable Node.js server-side applications) service, and then the node service calls the current node's java service or database service to obtain data, and renders the page based on the data and returns it to the front end. However, if the current node's java service is abnormal, the entire process will fail, that is, the page will fail to load, wasting the stability of the cluster. The current common solution is to use nginx (a high-performance server) for load balancing, requesting each node in turn, but when nginx accesses nestjs, it cannot know whether the java service is normal, so it cannot guarantee that the correct result is obtained, resulting in page loading failure.
[0003] Therefore, how to request a node with normal service in a service cluster to effectively ensure the successful execution of page loading is an urgent problem to be solved by those skilled in the art. Summary of the invention
[0004] The purpose of the present application is to provide a page loading method, which can request a node with normal service in a service cluster to effectively ensure the successful execution of page loading; another purpose of the present application is to provide a page loading device, electronic device, computer-readable storage medium and computer program product, all of which have the above-mentioned beneficial effects.
[0005] In a first aspect, the present application provides a page loading method, which is applied to a load balancing device, wherein the load balancing device is in communication connection with both a client and a service cluster, wherein the service cluster includes a plurality of service nodes, and the method includes:
[0006] Reading a preset configuration file of the service cluster to obtain node information of each of the service nodes in the service cluster;
[0007] Acquire the service interface connectivity status of the corresponding service node according to the node information; the service interface connectivity status includes an available state and an unavailable state;
[0008] Determine a service node in the service cluster whose service interface connectivity status is in the available status, and generate a list of available service nodes;
[0009] When a page loading request initiated by the client is received, a service node with the least number of calls is selected from the available service node list as a target service node, and the target service node is called to execute the page loading request.
[0010] Optionally, when a page loading request initiated by the client is received, selecting a service node with the least number of calls in the available service node list as a target service node, and calling the target service node to execute the page loading request, including:
[0011] When receiving the page loading request initiated by the client, determining the request type of the page loading request; the request type includes a static resource loading request and an application program interface request;
[0012] If the page loading request is the static resource loading request, then the static resource data is read under the preset static resource path, and the static resource data is fed back to the client for feedback;
[0013] If the page loading request is the application program interface request, a service node with the least number of calls is selected from the available service node list as the target service node, and the target service node is called to execute the page loading request.
[0014] Optionally, if the page loading request is the application program interface request, selecting a service node with the least number of calls in the available service node list as the target service node, and calling the target service node to execute the page loading request, including:
[0015] If the page loading request is the application program interface request, performing a permission check on the application program interface request;
[0016] When the permission check passes, selecting a service node with the least number of calls in the available service node list as the target service node, and calling the target service node to execute the page loading request;
[0017] When the permission check fails, the application program interface request is rejected.
[0018] Optionally, acquiring a service interface connectivity status of a corresponding service node according to the node information includes:
[0019] Acquire the portal interface connectivity status and the config interface connectivity status of the corresponding service node according to the node information;
[0020] Accordingly, determining the service node in the service cluster whose service interface connectivity status is the available status and generating a list of available service nodes includes:
[0021] Determine a service node in the service cluster whose portal interface connectivity status is the available status, and generate a list of portal available service nodes;
[0022] Determine a service node in the service cluster where the config interface connectivity status is the available status, and generate a config available service node list;
[0023] When a page loading request initiated by the client is received, a service node with the least number of calls is selected from the list of available service nodes as a target service node, and the target service node is called to execute the page loading request, including:
[0024] When receiving the page loading request initiated by the client, determining the request service type of the page loading request; the request service type includes portal service and config service;
[0025] If the requested service type is the portal service, selecting a service node with the least number of calls from the portal available service node list as the target service node, and calling the target service node to execute the page loading request;
[0026] If the requested service type is the config service, a service node with the least number of calls is selected from the config available service node list as the target service node, and the target service node is called to execute the page loading request.
[0027] Optionally, the page loading method further includes:
[0028] Obtaining the execution result of the target service node for the page loading request;
[0029] When the execution result is successful, the number of calls of the target service node in the available service node list is increased by one;
[0030] When the execution result is execution failure, the target service node is removed from the list of available service nodes.
[0031] Optionally, when the execution result is execution failure, removing the target service node from the list of available service nodes includes:
[0032] When the execution result is execution failure, obtaining a page loading request execution log;
[0033] If the page loading request execution log includes information that the calling service is unavailable, then removing the target service node from the list of available service nodes;
[0034] If the page loading request execution log does not include the call service unavailable information, the target service node is retained in the available service node list, and an alarm prompt is output.
[0035] Optionally, reading a preset configuration file of the service cluster to obtain node information of each of the service nodes in the service cluster includes:
[0036] The preset configuration file of the service cluster is read at a preset time interval to obtain the node information of each of the service nodes in the service cluster.
[0037] In a second aspect, the present application further discloses a page loading device, which is applied to a load balancing device, wherein the load balancing device is in communication connection with both a client and a service cluster, wherein the service cluster includes a plurality of service nodes, and the device includes:
[0038] A reading module, used to read a preset configuration file of the service cluster and obtain node information of each service node in the service cluster;
[0039] An acquisition module, used for acquiring a service interface connectivity status of a corresponding service node according to the node information; the service interface connectivity status includes an available status and an unavailable status;
[0040] A determination module, configured to determine a service node in the service cluster whose service interface connectivity status is in the available status, and generate a list of available service nodes;
[0041] The execution module is used to select a service node with the least number of calls as a target service node in the available service node list when receiving a page loading request initiated by the client, and call the target service node to execute the page loading request.
[0042] In a third aspect, the present application further discloses an electronic device, comprising:
[0043] Memory for storing computer programs;
[0044] A processor is used to implement the steps of any one of the page loading methods described above when executing the computer program.
[0045] In a fourth aspect, the present application further discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the page loading methods described above are implemented.
[0046] In a fifth aspect, the present invention further discloses a computer program product, including a computer program / instruction, which implements the steps of any one of the page loading methods described above when executed by a processor.
[0047] The present application provides a page loading method, which is applied to a load balancing device, wherein the load balancing device is communicatively connected with a client and a service cluster, wherein the service cluster includes multiple service nodes, and the method includes: reading a preset configuration file of the service cluster to obtain node information of each of the service nodes in the service cluster; obtaining a service interface connectivity status of the corresponding service node according to the node information; the service interface connectivity status includes an available status and an unavailable status; determining a service node in the service cluster whose service interface connectivity status is the available status, and generating a list of available service nodes; when a page loading request initiated by the client is received, selecting a service node with the least number of calls in the list of available service nodes as a target service node, and calling the target service node to execute the page loading request.
[0048] By applying the technical solution provided by the present application, a load balancing device is deployed between the client and the service cluster. Based on the load balancing device, the node information of each service node in the service cluster can be obtained by reading the preset configuration file of the service cluster, thereby obtaining the service interface connectivity status of each service node, that is, determining whether the service of each service node is available. Thus, the available service nodes in the service cluster can be determined. On this basis, for the received page loading request, the available service node with the least number of calls can be directly selected from the available service nodes to execute the page loading request and realize page loading. It can be seen that the present technical solution can effectively ensure that the service node with normal service and the lowest load is requested in the service cluster, thereby effectively ensuring the successful execution of page loading and ensuring the stability of the service cluster.
[0049] In one embodiment of the present application, since the resources that the client needs to load during the page loading process are different, different page loading request execution methods are provided for different types of page loading requests. For static resource loading requests, due to the uniqueness and immutability of static resources, a static resource storage path can be created in advance to implement static resource storage, so as to directly obtain static resource data under the preset static resource path and provide feedback to the client; for application interface requests, due to the non-uniqueness of dynamic resources, the available service node with the lowest load can be selected to execute the request and provide feedback to the client. In this way, a page loading solution based on the request type is implemented, which can effectively ensure the efficiency of page loading and the accuracy of page loading results.
[0050] The page loading device, electronic device, computer-readable storage medium and computer program product provided in this application also have the above-mentioned technical effects, and this application will not elaborate on them here. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the technical solutions in the prior art and the embodiments of the present application, the drawings required for use in the description of the prior art and the embodiments of the present application are briefly introduced below. Of course, the drawings described below in relation to the embodiments of the present application are only part of the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without creative work, and the obtained other drawings also belong to the protection scope of the present application.
[0052] Figure 1 A schematic diagram of the structure of a page loading system provided by this application;
[0053] Figure 2 A schematic diagram of a page loading method provided by this application;
[0054] Figure 3 A flowchart of another page loading method provided by this application;
[0055] Figure 4 A schematic diagram of the structure of a page loading device provided by the present application;
[0056] Figure 5 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0057] The core of the present application is to provide a page loading method, which can request a node with normal service in a service cluster to effectively ensure the successful execution of page loading; another core of the present application is to provide a page loading device, electronic device, computer-readable storage medium and computer program product, all of which have the above-mentioned beneficial effects.
[0058] In order to describe the technical solutions in the embodiments of the present application more clearly and completely, the technical solutions in the embodiments of the present application will be introduced below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0059] An embodiment of the present application provides a page loading method.
[0060] First, please refer to Figure 1 , Figure 1 This is a schematic diagram of the structure of a page loading system provided by the present application, the page loading system includes a load balancing device, a client and a service cluster, the client and the service cluster are both connected to the load balancing device in communication, and the service cluster includes multiple service nodes. The page loading method provided in the embodiment of the present application is implemented based on the page loading system.
[0061] For further information, please refer to Figure 2 , Figure 2 A schematic diagram of a page loading method provided in this application, which is applied to Figure 1 The load balancing device shown may include the following S101 to S104.
[0062] S101: Read a preset configuration file of a service cluster to obtain node information of each service node in the service cluster.
[0063] This step is intended to achieve the acquisition of node information of each service node in the service cluster, and this process can be implemented according to the preset configuration file of the service cluster. It can be understood that during the initial creation or update (expansion or reduction) of the service cluster, its configuration file will also be created or updated, and the configuration file contains relevant information of each service node in the service cluster, such as node IP, node identification, node location, etc. Therefore, the node information of each service node in the service cluster can be obtained by reading the preset configuration file of the service cluster. Here, the node information of the service node is used to determine the service availability status of the corresponding service node, and information communication with the service node is required to achieve the acquisition of the service availability status. Therefore, in one possible implementation method, the node information of the service node can specifically be the node IP.
[0064] In one embodiment of the present application, reading a preset configuration file of a service cluster to obtain node information of each service node in the service cluster may include: reading a preset configuration file of the service cluster at a preset time interval to obtain node information of each service node in the service cluster.
[0065] It is understandable that the service cluster is changing at any time, and new service nodes may be added or old service nodes may be deleted. Therefore, the preset configuration file of the service cluster is also constantly updated. Correspondingly, the service node information can be obtained according to the preset period, so as to achieve the periodic acquisition of the list of available service nodes to effectively ensure accuracy. Of course, the value of the preset time interval does not affect the implementation of this technical solution, and can be set by the technician according to the actual situation, and this application does not limit this.
[0066] S102: Acquire the service interface connectivity status of the corresponding service node according to the node information; the service interface connectivity status includes an available status and an unavailable status.
[0067] This step aims to determine the service availability status of each service node in the service cluster. Specifically, after obtaining the node information of each service node in the service cluster, for any service node, the load balancing device can use the node information of the service node (the node IP as described above) to establish a communication connection relationship with the service node, thereby determining the service availability status of the service node, which can specifically be the connectivity status of the service interface of the service node. It can be understood that when the service interface of the service node is connected, the service status of the service node is available; when the service interface of the service node is not connected, the service status of the service node is unavailable.
[0068] S103: Determine a service node in the service cluster whose service interface connectivity status is available, and generate a list of available service nodes.
[0069] This step aims to realize the generation of an available service list. Obviously, the service nodes recorded in the available service list are all available service nodes, that is, service nodes whose service interface connectivity status in the service cluster is available.
[0070] S104: When a page loading request initiated by the client is received, a service node with the least number of calls is selected from the list of available service nodes as a target service node, and the target service node is called to execute the page loading request.
[0071] This step is intended to implement the execution of the page loading request. Specifically, the client initiates a page loading request to the service cluster. The page loading request first passes through the load balancing device. Based on the load balancing device, the available service node with the least number of calls can be selected from the current list of available service nodes as the target service node to execute the page loading request. Among them, the least number of calls essentially means the least number of page loading requests that have been processed, that is, the smallest load pressure. In the implementation process, the number of calls of each available service node can be recorded at the same time through the list of available service nodes. The number of calls is increased by one for each successful call. Thus, the service node with the least number of calls in the service cluster can be determined based on the list of available service nodes. After that, the target service node executes the page loading request, obtains the page data locally, and then feeds it back to the client through the load balancing device for page rendering to complete the page loading operation.
[0072] In which, calling the target service node to execute the page loading request may include:
[0073] Get the target token based on the page load request;
[0074] The target token is used to call the Java service of the target service node to execute the page loading request.
[0075] Specifically, in the process of using the target service node to execute a page loading request, the target token contained in the page loading request can be used to implement the call of the Java service in the target service node, that is, the cookie information in the page loading request is obtained, and the target token is parsed from it, and the target token is used to call the Java service of the target service node to execute the page loading request.
[0076] In one embodiment of the present application, when a page loading request initiated by a client is received, a service node with the least number of calls is selected as a target service node in a list of available service nodes, and the target service node is called to execute the page loading request, which may include:
[0077] When receiving a page loading request initiated by a client, determining a request type of the page loading request; the request type includes a static resource loading request and an application program interface request;
[0078] If the page loading request is a static resource loading request, the static resource data is read under the preset static resource path, and the static resource data is fed back to the client for feedback;
[0079] If the page loading request is an application program interface request, a service node with the least number of calls is selected from the list of available service nodes as the target service node, and the target service node is called to execute the page loading request.
[0080] It is understandable that different clients or the same client require different page loading resources during different page loading operations, which may be static resources or application resources (dynamic resources). Among them, static resources are fixed and unchanged, while dynamic resources are non-unique and determined by specific applications. Therefore, different page loading request execution methods can be used for different types of page loading requests. In the implementation process, for static resource loading requests, due to the uniqueness of static resources, a static resource storage path can be created in advance to implement static resource storage, so as to directly obtain static resource data under the preset static resource path and provide feedback to the client; for application interface requests, due to the non-uniqueness of dynamic resources, the available service node with the lowest load can be selected to execute the request and provide feedback to the client.
[0081] It can be seen that in the embodiment of the present application, since the resources required to be loaded by the client during the page loading process are different, different page loading request execution modes are provided for different types of page loading requests. Thus, a page loading solution based on the request type is implemented, which can effectively ensure the page loading efficiency and the accuracy of the page loading results.
[0082] If the page loading request is an application program interface request, selecting a service node with the least number of calls in the available service node list as a target service node, and calling the target service node to execute the page loading request may include:
[0083] If the page loading request is an application program interface request, then the permission check is performed on the application program interface request;
[0084] When the permission check passes, the service node with the least number of calls is selected as the target service node in the list of available service nodes, and the target service node is called to execute the page loading request;
[0085] When the permission check fails, the API request is rejected.
[0086] Specifically, for application interface requests initiated by the client, in order to effectively ensure the security performance of the service cluster, before selecting the target service node to execute the application interface request, you can first perform an authorization check on it, such as user information verification, access permission verification, etc. Only when the authorization check passes can you select the target service node to execute the application interface request, otherwise the application interface request will be rejected. At the same time, a corresponding alarm prompt can also be issued.
[0087] In one embodiment of the present application, acquiring the service interface connectivity status of the corresponding service node according to the node information may include: acquiring the portal interface connectivity status and the config interface connectivity status of the corresponding service node according to the node information;
[0088] Accordingly, determining the service node whose service interface connectivity status is available in the service cluster and generating the available service node list may include: determining the service node whose portal interface connectivity status is available in the service cluster and generating the portal available service node list; determining the service node whose config interface connectivity status is available in the service cluster and generating the config available service node list;
[0089] When a page loading request initiated by a client is received, a service node with the least number of calls is selected from a list of available service nodes as a target service node, and the target service node is called to execute the page loading request, which may include: when a page loading request initiated by a client is received, a request service type of the page loading request is determined; the request service type includes portal service and config service; if the request service type is portal service, a service node with the least number of calls is selected from a list of available portal service nodes as a target service node, and the target service node is called to execute the page loading request; if the request service type is config service, a service node with the least number of calls is selected from a list of available config service nodes as a target service node, and the target service node is called to execute the page loading request.
[0090] Specifically, the services that each service node in the service cluster can provide may include portal services and config services. Therefore, when determining the service interface connectivity status of each service node in the service cluster, the portal interface connectivity status and the config interface connectivity status of each service node in the service cluster can be specifically determined. Correspondingly, the generated available service node list includes a portal available service node list and a config available service node list. On this basis, when executing a page loading request, the available service node list can be selected according to the service type requested by the page loading request to determine the target service node, thereby completing the execution of the page loading request.
[0091] It can be seen that the page loading method provided in the embodiment of the present application deploys a load balancing device between the client and the service cluster. Based on the load balancing device, the node information of each service node in the service cluster can be obtained by reading the preset configuration file of the service cluster, thereby obtaining the service interface connectivity status of each service node, that is, determining whether the service of each service node is available. Thus, the available service nodes in the service cluster can be determined. On this basis, for the received page loading request, the available service node with the least number of calls can be directly selected from the available service nodes to execute the page loading request and realize page loading. It can be seen that the technical solution can effectively ensure that the service node with normal service and the lowest load is requested in the service cluster, thereby effectively ensuring the successful execution of page loading and ensuring the stability of the service cluster.
[0092] Based on the above embodiments:
[0093] In one embodiment of the present application, the page loading method may further include:
[0094] Get the execution result of the target service node for the page loading request;
[0095] When the execution result is successful, the call count of the target service node is increased by one in the list of available service nodes;
[0096] When the execution result is execution failure, the target service node is removed from the list of available service nodes.
[0097] The embodiment of the present application can further implement the update processing of the list of available service nodes. As described above, the target service node in the service cluster is selected by referring to the call counts of each available service node recorded in the list of available service nodes. Then, in the actual application scenario, each time a page loading request is successfully executed, the call count of the target service node in the list of available service nodes will be increased by one, so as to facilitate the accurate screening of the target service node when a new page loading request is subsequently executed.
[0098] In addition, when the page load request fails to execute, the target service node can be directly removed from the list of available service nodes; of course, when the removed target service node resumes service availability, it can be added to the list of available service nodes again, but the call count of the newly added service node starts from 0. Furthermore, when the page load request fails to execute, the service node with the lowest call count can be reselected from the list of available service nodes as the target service node to execute the page load request, ensuring that the page load request is successfully executed.
[0099] When the execution result is execution failure, removing the target service node from the list of available service nodes may include:
[0100] When the execution result is execution failure, obtain the page loading request execution log;
[0101] If the page loading request execution log includes the call service unavailable information, the target service node is removed from the list of available service nodes;
[0102] If the page loading request execution log does not include the call service unavailable information, the target service node is retained in the list of available service nodes and an alarm prompt is output.
[0103] It should be noted that when the target request node fails to execute the page loading request, it is not necessarily because the target request node has a service unavailable problem, but may also be due to a service call failure caused by network instability. Based on this, before removing the target service node from the list of available service nodes, the reason for the failure of the page loading request can be determined first. If it is indeed caused by a service call failure, the target service node can be removed from the list of available service nodes. If it is not caused by a service call failure, there is no need to remove the target service node from the list of available service nodes. An alarm prompt can be output to remind the technicians to perform operation and maintenance management. In this way, the accurate update of the available service list can be achieved. Among them, the analysis of the cause of the failure of the page loading request can be specifically implemented based on the page loading request execution log.
[0104] Based on the above embodiments, an embodiment of the present application provides another page loading method.
[0105] Please refer to Figure 3 , Figure 3 A flowchart of another page loading method provided by this application.
[0106] First, the implementation principle of the page loading method provided in the embodiment of the present application is as follows:
[0107] The load balancing device is built based on Nestjs. When the Nestjs service is started, it reads the configuration file / usr / local / conf / portal.conf of the service cluster, obtains the node list of the service cluster, and caches it. Then the timer is started, and the service interface (java service interface) of each service node in the node list is requested in turn every 5 minutes. If the request fails, the value corresponding to the service node is set to -1 (set to service unavailable). Further, when the web request reaches the nestjs service from the page (page loading request), the service node with the corresponding value that is not -1 and the smallest value (the smallest number of calls) is obtained according to the node list, and the service node is requested to execute the page loading request. If the execution is successful, the corresponding value is +1 (the number of calls is increased by one). If the execution fails, the corresponding value is set to -1, and other service nodes are requested to obtain data.
[0108] Furthermore, based on the implementation principle of the above page loading method, the construction process of the load balancing device is as follows:
[0109] 1. Framework construction:
[0110] 1. Initialize the Nestjs project, configure the corresponding webpack (module packager), and install the corresponding dependency packages.
[0111] 2. Configure the static resource path src / web of Nestjs.
[0112] 3. The Vue package file path is specified as src / web, so that the packaged js and css can be directly placed in this directory. As a result, static resource services can be provided directly by Nestjs without being transferred through nginx.
[0113] 4. Configure the Nestjs memory cache, which includes the cluster node list and the node list of each required Java service.
[0114] 5. Configure a timer to read the cluster node list every 5 minutes, request the Java service interface based on the node IP plus the Java service port, and set the various states of the Java service node list based on the results.
[0115] Among them, the data structure of each list is as follows:
[0116] SERVER_NODE_IP:["127.0.0.1","100.18.64.185"]
[0117] PORTAL_SERVER_NODE_IP: {"127.0.0.1:9100": 0,"100.18.64.185:9100":1}
[0118] CONFIG_SERVER_NODE_IP: {"127.0.0.1:9110": 0,"100.18.64.185:9110":1}
[0119] The number corresponding to the service is the number of calls. -1 means the service is unavailable. If the call is successful, the value is increased by 1. If the call fails, the value is set to -1.
[0120] 2. Logical processing:
[0121] 1. When Nestjs interacts with Java services, since data is first obtained on the server side, token verification information cannot be transmitted through header (http request header) or localstorage, so cookies (a small piece of data sent by the server to the user's browser and saved locally) can be used.
[0122] 2. The browser passes the token to Nestjs through the cookie, and the Nestjs service sets the request header when requesting the Java service.
[0123] 3. When the system is installed and initialized, the node list file / usr / local / conf / portal.conf will be configured, and Nestjs will read the node list of the service cluster from this file and put it into the memory cache.
[0124] 4. Provide a unified entry method for obtaining available service nodes, so that the business layer can directly call this method to get the address of the corresponding Java service and call it directly.
[0125] 5. Load balancing is mainly implemented by round-robin method, which is implemented as follows:
[0126] According to the requested Java service type, get the cache list of the corresponding service, traverse the list, if the value corresponding to the node IP is greater than or equal to 0, it means it is available, if it is -1, it is skipped, and then find the node with the smallest value among all nodes greater than or equal to 0, which means that the node has the least number of calls, then use this node to provide services this time, and add 1 to the value of the node. This ensures that even if the Java service of the node where the Nestjs service is located fails, data can still be obtained by calling other available nodes, ensuring the high availability of the system.
[0127] 6. The availability of each service node in the node service list of the Java cache can be updated regularly by a timer.
[0128] 7. When the timer runs, the configuration file of the node list will be read each time to ensure that the cached node list can be updated synchronously even after the service cluster is expanded or reduced in capacity.
[0129] 3. Compatibility processing:
[0130] 1. Node version 16 or above is required to implement Nestjs service.
[0131] 2. Nestjs and related dependencies (such as nestjs cache, nestjs timer) version is 10 and above.
[0132] Finally, the specific implementation process of the page loading method provided in the embodiment of the present application is as follows:
[0133] 1. The browser loads the page and the request reaches the Nestjt server. If it is a request for static resources, the static resources under src / web are directly returned to the client according to the path.
[0134] 2. If it is an API interface request, it will first check a series of permissions before reaching the service layer of the Nestjs service.
[0135] 3. Based on business needs, if the service layer needs to call a Java service, it will obtain the required available JAVA service address through a unified method provided by the load balancing mechanism.
[0136] 4. The cookie information attached to the web request (page loading request) contains a token, which is used to call the Java service. If successful, business processing is performed based on the returned data and the value of the node in the cache list is increased by 1. If it fails, if the reason for the failure is that the service is unavailable, the corresponding service status in the cache list is set to -1. Other business errors do not update the node status of the cache list.
[0137] 5. The timer task runs independently of the web request. The timer task is started when the service starts. The main logic is as follows: set it to run every 5 minutes. At the beginning of each time, it reads the configuration file / usr / local / conf / portal.conf, obtains the IP list of the service cluster, and updates it to the cached SERVER_NODE_IP. Then it loops through the list and requests the portal service interface on each IP node. If it can be connected normally, check the node status corresponding to the PORTAL_SERVER_NODE_IP cache. If it is -1, set it to 0. It indicates that it is available. If it is ≥0, it is skipped. If it cannot be connected normally, the status of the node in the PORTAL_SERVER_NODE_IP cache object is set to -1, indicating that it is unavailable. Request the config service interface on each IP node. If it can be connected normally, check the node status corresponding to the CONFIG_SERVER_NODE_IP cache. If it is -1, it is set to 0, indicating that it is available. If it is ≥0, it is skipped. If it cannot be connected normally, the status of the node in the CONFIG_SERVER_NODE_IP cache object is set to -1, indicating that it is unavailable.
[0138] 6. The scheduled task only verifies whether the service is online and can be connected. It does not judge or process whether there is any internal fault. Specific business errors can be checked by recording logs.
[0139] It can be seen that the page loading method provided in the embodiment of the present application deploys a load balancing device between the client and the service cluster. Based on the load balancing device, the node information of each service node in the service cluster can be obtained by reading the preset configuration file of the service cluster, thereby obtaining the service interface connectivity status of each service node, that is, determining whether the service of each service node is available. Thus, the available service nodes in the service cluster can be determined. On this basis, for the received page loading request, the available service node with the least number of calls can be directly selected from the available service nodes to execute the page loading request and realize page loading. It can be seen that the technical solution can effectively ensure that the service node with normal service and the lowest load is requested in the service cluster, thereby effectively ensuring the successful execution of page loading and ensuring the stability of the service cluster.
[0140] An embodiment of the present application provides a page loading device.
[0141] Please refer to Figure 4 , Figure 4 This is a structural diagram of a page loading device provided by the present application. The page loading device is applied to a load balancing device. The load balancing device is connected to both a client and a service cluster. The service cluster includes multiple service nodes. The page loading device may include:
[0142] Reading module 1, used to read the preset configuration file of the service cluster and obtain the node information of each service node in the service cluster;
[0143] Acquisition module 2, used to acquire the service interface connectivity status of the corresponding service node according to the node information; the service interface connectivity status includes an available state and an unavailable state;
[0144] Determination module 3, used to determine the service nodes in the service cluster whose service interface connectivity status is available, and generate a list of available service nodes;
[0145] The execution module 4 is used to select the service node with the least number of calls as the target service node in the list of available service nodes when receiving the page loading request initiated by the client, and call the target service node to execute the page loading request.
[0146] It can be seen that the page loading device provided in the embodiment of the present application deploys a load balancing device between the client and the service cluster. Based on the load balancing device, the node information of each service node in the service cluster can be obtained by reading the preset configuration file of the service cluster, thereby obtaining the service interface connectivity status of each service node, that is, determining whether the service of each service node is available. Thus, the available service nodes in the service cluster can be determined. On this basis, for the received page loading request, the available service node with the least number of calls can be directly selected from the available service nodes to execute the page loading request and realize page loading. It can be seen that the technical solution can effectively ensure that the service node with normal service and the lowest load is requested in the service cluster, thereby effectively ensuring the successful execution of page loading and ensuring the stability of the service cluster.
[0147] In one embodiment of the present application, the execution module 4 may include:
[0148] A determination unit, configured to determine a request type of the page loading request when receiving a page loading request initiated by a client; the request type includes a static resource loading request and an application program interface request;
[0149] The first execution unit is used for reading static resource data under a preset static resource path and feeding back the static resource data to the client for feedback if the page loading request is a static resource loading request;
[0150] The second execution unit is configured to select a service node with the least number of calls from the available service node list as a target service node if the page loading request is an application program interface request, and call the target service node to execute the page loading request.
[0151] In one embodiment of the present application, the above-mentioned second execution unit can be specifically used to perform permission verification on the application interface request if the page loading request is an application interface request; when the permission verification passes, select the service node with the least number of calls in the list of available service nodes as the target service node, and call the target service node to execute the page loading request; when the permission verification fails, reject the application interface request.
[0152] In one embodiment of the present application, the acquisition module 2 may be specifically used to acquire the portal interface connectivity status and the config interface connectivity status of the corresponding service node according to the node information;
[0153] Accordingly, the above-mentioned determination module 3 can be specifically used to determine the service nodes whose portal interface connectivity status is available in the service cluster, and generate a list of portal available service nodes; determine the service nodes whose config interface connectivity status is available in the service cluster, and generate a list of config available service nodes;
[0154] The above-mentioned execution module 4 can be specifically used to determine the request service type of the page loading request when a page loading request initiated by the client is received; the request service types include portal service and config service; if the request service type is portal service, then the service node with the least number of calls is selected as the target service node in the portal available service node list, and the target service node is called to execute the page loading request; if the request service type is config service, then the service node with the least number of calls is selected as the target service node in the config available service node list, and the target service node is called to execute the page loading request.
[0155] In one embodiment of the present application, the page loading device may also include an update module for obtaining the execution result of the target service node for the page loading request; when the execution result is successful, the number of calls of the target service node in the list of available service nodes is increased by one; when the execution result is failed, the target service node is removed from the list of available service nodes.
[0156] In one embodiment of the present application, the above-mentioned update module can be specifically used to obtain the page loading request execution log when the execution result is execution failure; if the page loading request execution log includes the call service unavailable information, the target service node is removed from the list of available service nodes; if the page loading request execution log does not include the call service unavailable information, the target service node is retained in the list of available service nodes, and an alarm prompt is output.
[0157] In one embodiment of the present application, the reading module 1 may be specifically used to read a preset configuration file of the service cluster at a preset time interval to obtain node information of each service node in the service cluster.
[0158] For an introduction to the device provided in the embodiments of the present application, please refer to the above method embodiments, and the present application will not elaborate on them here.
[0159] An embodiment of the present application provides an electronic device.
[0160] Please refer to Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in this application, and the electronic device may include:
[0161] A memory 11, used for storing computer programs;
[0162] The processor 10 can implement the steps of any of the above-mentioned page loading methods when executing a computer program.
[0163] like Figure 5 , which is a schematic diagram of the composition structure of an electronic device, the electronic device may include: a processor 10, a memory 11, a communication interface 12 and a communication bus 13. The processor 10, the memory 11 and the communication interface 12 all communicate with each other through the communication bus 13.
[0164] In the embodiment of the present application, the processor 10 may be a central processing unit (CPU), an application specific integrated circuit, a digital signal processor, a field programmable gate array or other programmable logic devices, etc.
[0165] The processor 10 may call a program stored in the memory 11 . Specifically, the processor 10 may execute operations in the embodiment of the page loading method.
[0166] The memory 11 is used to store one or more programs, which may include program codes, and the program codes include computer operation instructions. In the embodiment of the present application, the memory 11 at least stores programs for implementing the following functions:
[0167] Read the preset configuration file of the service cluster to obtain the node information of each service node in the service cluster;
[0168] Obtain the service interface connectivity status of the corresponding service node according to the node information; the service interface connectivity status includes available status and unavailable status;
[0169] Determine the service nodes in the service cluster whose service interface connectivity status is available, and generate a list of available service nodes;
[0170] When a page loading request initiated by a client is received, a service node with the least number of calls is selected as a target service node in the list of available service nodes, and the target service node is called to execute the page loading request.
[0171] In a possible implementation, the memory 11 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function, etc.; the data storage area may store data created during use.
[0172] In addition, the memory 11 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device or other volatile solid-state storage device.
[0173] The communication interface 12 may be an interface of a communication module, and is used to connect to other devices or systems.
[0174] Of course, it should be noted that Figure 5 The structure shown does not constitute a limitation on the electronic device in the embodiment of the present application. In actual applications, the electronic device may include Figure 5 More or fewer components than shown, or combinations of certain components.
[0175] An embodiment of the present application provides a computer-readable storage medium.
[0176] The computer-readable storage medium provided in the embodiment of the present application stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned page loading methods can be implemented.
[0177] Among them, the computer-readable storage medium can be any available medium that can be stored in a computer or a data storage device such as a server or data center that includes one or more available media integrated. For example, it can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape, etc.), an optical medium (such as a DVD) or a semiconductor medium (such as a solid-state hard disk) and other media that can store computer program codes.
[0178] For an introduction to the computer-readable storage medium provided in the embodiments of the present application, please refer to the above method embodiments, and the present application will not elaborate on them here.
[0179] An embodiment of the present application provides a computer program product.
[0180] The computer program product provided in the embodiments of the present application includes a computer program / instruction, and when the computer program / instruction is executed by a processor, the steps of any of the above-mentioned page loading methods can be implemented.
[0181] Specifically, in the above embodiments, all or part of them can be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of them can be implemented in the form of a computer program product.
[0182] Among them, the computer program product may include one or more computer programs / instructions, and when the computer program / instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application may be generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions may be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line, etc.) or wireless (e.g., infrared, wireless, microwave, etc.) means.
[0183] For an introduction to the computer program product provided in the embodiments of the present application, please refer to the above method embodiments, and the present application will not elaborate on them here.
[0184] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0185] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0186] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0187] The technical solution provided by the present application is described in detail above. The principle and implementation method of the present application are described in detail using specific examples herein, and the description of the above embodiments is only used to help understand the method and core idea of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the present application.
Claims
1. A page loading method, characterized in that: Applied to a load balancing device, the load balancing device is in communication connection with both a client and a service cluster, the service cluster includes a plurality of service nodes, the method includes: Reading a preset configuration file of the service cluster to obtain node information of each of the service nodes in the service cluster; Acquire the service interface connectivity status of the corresponding service node according to the node information; the service interface connectivity status includes an available state and an unavailable state; Determine a service node in the service cluster whose service interface connectivity status is in the available status, and generate a list of available service nodes; When a page loading request initiated by the client is received, a service node with the least number of calls is selected from the available service node list as a target service node, and the target service node is called to execute the page loading request.
2. The page loading method according to claim 1, characterized in that: When a page loading request initiated by the client is received, a service node with the least number of calls is selected from the available service node list as a target service node, and the target service node is called to execute the page loading request, including: When receiving the page loading request initiated by the client, determining the request type of the page loading request; the request type includes a static resource loading request and an application program interface request; If the page loading request is the static resource loading request, then the static resource data is read under the preset static resource path, and the static resource data is fed back to the client for feedback; If the page loading request is the application program interface request, a service node with the least number of calls is selected from the available service node list as the target service node, and the target service node is called to execute the page loading request.
3. The page loading method according to claim 2, characterized in that: If the page loading request is the application program interface request, selecting a service node with the least number of calls in the available service node list as the target service node, and calling the target service node to execute the page loading request, including: If the page loading request is the application program interface request, performing a permission check on the application program interface request; When the permission check passes, selecting a service node with the least number of calls in the available service node list as the target service node, and calling the target service node to execute the page loading request; When the permission check fails, the application program interface request is rejected.
4. The page loading method according to claim 1, characterized in that: Acquiring the service interface connectivity status of the corresponding service node according to the node information includes: Acquire the portal interface connectivity status and the config interface connectivity status of the corresponding service node according to the node information; Accordingly, determining the service node in the service cluster whose service interface connectivity status is the available status and generating a list of available service nodes includes: Determine a service node in the service cluster whose portal interface connectivity status is the available status, and generate a list of portal available service nodes; Determine a service node in the service cluster where the config interface connectivity status is the available status, and generate a config available service node list; When a page loading request initiated by the client is received, a service node with the least number of calls is selected from the list of available service nodes as a target service node, and the target service node is called to execute the page loading request, including: When receiving the page loading request initiated by the client, determining the request service type of the page loading request; the request service type includes portal service and config service; If the requested service type is the portal service, selecting a service node with the least number of calls from the portal available service node list as the target service node, and calling the target service node to execute the page loading request; If the requested service type is the config service, a service node with the least number of calls is selected from the config available service node list as the target service node, and the target service node is called to execute the page loading request.
5. The page loading method according to claim 1, characterized in that: Also includes: Obtaining the execution result of the target service node for the page loading request; When the execution result is successful, the number of calls of the target service node in the available service node list is increased by one; When the execution result is execution failure, the target service node is removed from the list of available service nodes.
6. The page loading method according to claim 5, characterized in that: When the execution result is execution failure, removing the target service node from the list of available service nodes includes: When the execution result is execution failure, obtaining a page loading request execution log; If the page loading request execution log includes information that the calling service is unavailable, then removing the target service node from the list of available service nodes; If the page loading request execution log does not include the call service unavailable information, the target service node is retained in the available service node list, and an alarm prompt is output.
7. The page loading method according to claim 1, characterized in that: Reading a preset configuration file of the service cluster to obtain node information of each of the service nodes in the service cluster includes: The preset configuration file of the service cluster is read at a preset time interval to obtain the node information of each of the service nodes in the service cluster.
8. A page loading device, characterized in that: Applied to a load balancing device, the load balancing device is in communication connection with both a client and a service cluster, the service cluster includes a plurality of service nodes, and the apparatus includes: A reading module, used to read a preset configuration file of the service cluster and obtain node information of each service node in the service cluster; An acquisition module, used for acquiring a service interface connectivity status of a corresponding service node according to the node information; the service interface connectivity status includes an available status and an unavailable status; A determination module, configured to determine a service node in the service cluster whose service interface connectivity status is in the available status, and generate a list of available service nodes; The execution module is used to select a service node with the least number of calls as a target service node in the available service node list when receiving a page loading request initiated by the client, and call the target service node to execute the page loading request.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the page loading method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the page loading method according to any one of claims 1 to 7 are implemented.