Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
Fig. 1 illustrates an application scenario of the data loading method of the present application, as shown in fig. 1, for example, for a certain service, a large number of servers are configured, including: server 11, server 12, server 13, etc., may be tens or hundreds in actual implementations. When the servers are started, the initialized configuration data need to be loaded, and then the service processing requests and the services can be normally received. The initialized configuration data may be stored in the database 14, and each server needs to acquire the configuration data from the database 14 and load the configuration data.
When a large number of servers are started at the same time, the servers may load data to the database 14 at the same time, which may put a large strain on the servers and may result in insufficient database connection resources. The data loading method is used for solving the problem, avoiding the situation that the database is under huge pressure, and ensuring the stability of the database. The execution flow of the method can refer to the example of fig. 2, and the flow can be executed by one of the servers:
in step 201, when it is determined that the target data needs to be loaded, a random delay time is generated.
In this step, it is determined that the target data needs to be loaded, for example, the server starts to be started, and it may be checked whether the initialization data is loaded at the next time, and if the initialization data is not loaded, it is necessary to first go to the database to obtain the loaded data to complete the initialization configuration of the server. In the example of initialization by starting up the server, the configuration data used for initialization may be referred to as target data, and in other application scenarios, the data to be loaded may be referred to as target data.
And generating the delay time, wherein the loading of the target data can be delayed and executed instead of immediately executing the loading of the target data when the target data is determined to be loaded, and the delay time is the generated random delay time in the step. The random delay time may be randomly generated, and the random delay time generated by different servers may be different.
For example, assuming that a large number of servers including server 11 to server 13 are all started at the same time in the scenario of fig. 1, according to the method of this step, each server will generate a random delay time at the time of starting, for example, for server 11, the generated random delay time may be 5 seconds, and for server 12, the generated random delay time may be 6 seconds. In addition, even for the same server, the generated random delay time can be different when the server is started at two different times.
In step 202, when the random delay time is reached, the target data is loaded from the database.
For example, taking the random delay time generated by the server 11 as 5 seconds as an example, when determining that the target data needs to be loaded, the server 11 may request the database to obtain the target data load after 5 seconds. For the scenario illustrated in step 201, when a large number of servers are started at the same time, target data needs to be loaded, but since the delay time is randomly generated, the random delay time of each server may be different, and the data loading time of each server may be dispersed, for example, after the servers are started at the same time, server 11 starts loading data after 5 seconds, and server 12 starts loading data after 6 seconds. For the database, the scattered reception of the data loading requests of the servers greatly reduces the pressure compared with the reception at the same time point in the traditional mode.
Furthermore, although the delay time is randomly generated, and the servers started at the same time do not load data at the same time point, it is still possible that the random delay time of some servers is the same. For example, in 100 servers started simultaneously, there may be 15 random delay times generated by the servers, but for the database, compared with the original data loading request received by 100 servers simultaneously, the data loading request received by 15 servers simultaneously still can be received, and the pressure has been reduced significantly.
According to the data loading method, the random delay time is generated, and data loading is performed after the random delay time, so that large batches of data loading requests can be dispersed in time, the pressure on the database is reduced, and the stability of the database is ensured.
In another example, a loading status flag may be set to indicate the status of whether the target data has been loaded more clearly and conveniently, and the random delay time may be generated when it is determined that the target data has not been loaded according to the loading status flag. Referring to the flow shown in FIG. 3:
in step 301, the system start may be a server start, and at this time, initialization configuration is to be performed, so before initialization, it may be determined whether the target data has been loaded according to the preset loading state identifier, in this embodiment, it is determined whether the initialization data is loaded.
Referring to step 302, the loading status flag set in this example may be a flag, and when the flag is true, it may be set to indicate that data has been loaded; when flag is false, it indicates that the data is not loaded yet. In this step, it may be determined whether flag is equal to true.
If yes, indicating that the server has been initialized, go to step 305 and end the process; if not, indicating that initialization data is to be loaded, execution continues with step 303.
In step 303, the server does not load immediately, but generates a random delay time, even if it determines to load data. For example, a time period may be predetermined within which a random delay time is generated. Illustratively, the time period of 0-30 seconds can be randomly generated. In a specific implementation, multiple servers applied to the same service may use the same time period, for example, in the scenario of fig. 1, each server is applied to the same service, and when generating the random delay time, each server may generate time within the time period of 0 to 30 seconds.
The determination of the preset time period may be determined according to a service to which the target data is applied. For example, for a service, when the server starts to start, a service processing request of the service arrives at the server after 30 seconds, and the server needs to complete the initialization configuration as soon as possible before the service processing request arrives, so that, for example, the time period for generating the random delay time may be set to 10 seconds. In addition, when the time period is set, the number of servers can be considered, so that even if the random delay time of partial servers is the same, the number of servers loaded at the same time point can be ensured not to be too large.
In the example shown in fig. 3, it can also be seen that the loading state identifier may be used to indicate whether the target data has been loaded, and whether to generate the random delay time may be determined according to the identifier, so that the loading state identifier may be used as a trigger condition for loading the target data, which is convenient for a manager to control when to load the target data by using the loading state identifier.
For example, assuming that the subsequent target data is updated after the successful target data is loaded, and the server needs to reload the target data at this time, it is possible to modify the loading status flag to indicate that the target data is not loaded, e.g., modify flag true to flag false. Meanwhile, the value of the flag is periodically checked, for example, the state of the flag may be queried every 3 seconds, and when the flag is found to be false, it may be determined that the target data needs to be reloaded at this time. The server may generate a random delay time and load the updated target data from the database when the random delay time is reached. In this example, the loading status identifier is queried periodically, and it can be determined whether data needs to be loaded according to the identifier, and when it is determined that data needs to be loaded, the data is loaded by delaying the time at random.
FIG. 4 illustrates the flow of another business process method, in this example, assuming that the loading was not successful when the data was loaded from the database at step 304. For example, when the server successfully loads the initialization data, the flag value may be modified to true, and when the flag value is periodically checked, if the flag is still false, it may be determined that the loading is not successful, and at this time, the flag value is not modified, and a random delay time is continuously generated, see the flow of fig. 4. The delay time generated when the loading fails can be called another random delay time, and then when the another random delay time is reached, the target data is loaded from the database again, and the above steps are repeatedly executed until the data loading is successful.
According to the data loading method, the loading state identifier is set, so that random delay time can be generated when the identifier indicates that the target data is not loaded, and then the data is loaded, a large amount of data can be loaded and dispersed in a time period, the target data can be successfully loaded, the pressure of a database is reduced, and the stability of the database is ensured.
The application also provides a data loading device, which can be applied to a server and can execute the data loading method of the embodiment of the application so as to enable the server to load data at random time delay. As shown in fig. 5, the apparatus may include: a time generation module 51 and a load execution module 52.
A time generation module 51, configured to generate a random delay time when it is determined that target data needs to be loaded;
and the load execution module 52 is configured to execute the process of loading the target data from the database when the random delay time arrives.
Further, the time generation module 51 is configured to determine that the target data needs to be loaded when it is determined that the target data is not loaded according to a preset loading state identifier, where the loading state identifier is used to indicate whether the target data is loaded.
Further, the time generating module 51 is configured to generate a random delay time within a preset time period; and the preset time period is determined according to the service applied by the target data.
Further, the time generating module 51 is configured to generate another random delay time again when the load executing module fails to load the target data from the database; and the load execution module 52 is configured to load the target data from the database again when the another random delay time arrives.
Fig. 6 illustrates another structure of the data loading apparatus, and as shown in fig. 6, the time generation module 51 may include: an identity management submodule 511 and a time management submodule 512.
The identifier management sub-module 511 is configured to, after the target data is loaded, modify the loading status identifier to indicate that the target data is not loaded if the target data is updated;
the time management submodule 512 is configured to determine that target data needs to be loaded according to the modified loading state identifier, and generate random delay time;
and a load execution module 52, configured to load the updated target data from the database when the random delay time arrives.
The data loading device of the embodiment can disperse a large amount of data loading requests in time by generating the random delay time and loading data after the random delay time, thereby reducing the pressure on the database and ensuring the stability of the database.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.