A data source switching method, device, computer equipment and storage medium
By performing long connections and historical data analysis during data source switching, and switching predicting the time point with the lowest transaction volume or failure rate, the problem of data source switching in the existing technology affecting transaction performance is solved, and stable transaction processing is achieved.
Patent Information
- Application Number
- CN202010222349.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-26
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2040-03-26
AI Technical Summary
Existing data source switching methods can easily affect transaction performance, resulting in increased transaction delays and failure rates, affecting system stability.
By connecting the auxiliary data source to the primary data source for a long time, and conducting statistical analysis of historical transaction data, predicting the time point where the transaction volume or transaction failure rate is minimal, data source switching is performed to avoid the shared pool being emptied and transaction resources being wasted.
It reduces transaction delay and failure rate, maintains high transaction performance, and ensures that the system can handle transaction requests stably after data source switching.
Smart Images

Figure CN111475484B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a data source switching method, device, computer equipment and storage medium. Background Art
[0002] Databases are key infrastructure in the fields of finance, transportation, commerce, and even the entire society. Continuous availability is the guarantee for databases to provide services to users continuously. In the actual application of databases, for considerations such as database data security, data processing efficiency, database operation and maintenance costs, and business development needs, there may be a need to switch data sources. For example, it is necessary to switch the database data source currently used by the business system to a database data source with low operation and maintenance costs.
[0003] Switching database data sources is a high-risk operation. If not handled properly, it can easily lead to business system paralysis. The traditional data source switching method is to switch the current data source to the target data source when the preset switching conditions are met. However, after switching to the target data source, if transactions occur in a concentrated manner, transaction delays and an increase in the number of transaction failures will occur, affecting transaction performance and customer experience. Summary of the invention
[0004] The embodiments of the present invention provide a data source switching method, device, computer equipment and storage medium, aiming to solve the problem in the prior art that the data source switching method easily affects transaction performance during switching.
[0005] In a first aspect, an embodiment of the present invention provides a data source switching method, which includes:
[0006] Control the long connection between the auxiliary data source and the main data source;
[0007] Performing statistical analysis on historical transaction data to predict two time points with the smallest transaction volume in a future transaction cycle: a first time point and a second time point; or performing statistical analysis on historical transaction data to predict two time points with the smallest transaction failure rate in a future transaction cycle: a third time point and a fourth time point;
[0008] When a first time point is reached, the control switches the primary data source to the secondary data source, and when a second time point is reached, the control switches the secondary data source to the primary data source; or, when a first time point is reached, the control switches the secondary data source to the primary data source, and when a second time point is reached, the control switches the primary data source to the secondary data source;
[0009] Alternatively, when the third time point is reached, the control switches the primary data source to the secondary data source, and when the fourth time point is reached, the control switches the secondary data source to the primary data source; or, when the third time point is reached, the control switches the secondary data source to the primary data source, and when the fourth time point is reached, the control switches the primary data source to the secondary data source.
[0010] In a second aspect, an embodiment of the present invention provides a data source switching device, comprising:
[0011] A long connection unit, used to control the long connection between the auxiliary data source and the main data source;
[0012] A statistical unit, for performing statistical analysis on historical transaction data, and predicting two time points with the smallest transaction volume in a future transaction cycle: a first time point and a second time point; or performing statistical analysis on historical transaction data, and predicting two time points with the smallest transaction failure rate in a future transaction cycle: a third time point and a fourth time point;
[0013] A switching unit, configured to control the switching of the primary data source to the secondary data source when a first time point is reached, and control the switching of the secondary data source to the primary data source when a second time point is reached; or, control the switching of the secondary data source to the primary data source when the first time point is reached, and control the switching of the primary data source to the secondary data source when the second time point is reached; or, control the switching of the primary data source to the secondary data source when the third time point is reached, and control the switching of the secondary data source to the primary data source when the fourth time point is reached; or, control the switching of the secondary data source to the primary data source when the third time point is reached, and control the switching of the primary data source to the secondary data source when the fourth time point is reached.
[0014] In a third aspect, an embodiment of the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the data source switching method as described in the first aspect when executing the computer program.
[0015] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the data source switching method as described in the first aspect is implemented.
[0016] The embodiment of the present invention provides a data source switching method, device, computer equipment and storage medium. The data source switching method includes: controlling a secondary data source to be connected to a primary data source for a long time; performing statistical analysis on historical transaction data to predict two time points with the smallest transaction volume in a future transaction cycle: a first time point and a second time point; or performing statistical analysis on historical transaction data to predict two time points with the smallest transaction failure rate in a future transaction cycle: a third time point and a fourth time point; when the first time point is reached, controlling the primary data source to be switched to the secondary data source, and when the second time point is reached, controlling the secondary data source to be switched to the primary data source; or when the first time point is reached, controlling the secondary data source to be switched to the primary data source, and when the second time point is reached, controlling the primary data source to be switched to the secondary data source; or when the third time point is reached, controlling the primary data source to be switched to the secondary data source, and when the fourth time point is reached, controlling the secondary data source to be switched to the primary data source; or when the third time point is reached, controlling the secondary data source to be switched to the primary data source, and when the fourth time point is reached, controlling the primary data source to be switched to the secondary data source. The embodiment of the present invention switches the data source by establishing a long connection between the auxiliary data source and the main data source, and finding two time points with the smallest transaction volume or two time points with the smallest transaction failure rate. In this way, high transaction performance can be maintained after switching, and transaction delay can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0018] Figure 1 A schematic diagram of a flow chart of a data source switching method provided by an embodiment of the present invention;
[0019] Figure 2 A schematic diagram of a sub-process of a data source switching method provided in an embodiment of the present invention;
[0020] Figure 3 A schematic diagram of another sub-process of the data source switching method provided by an embodiment of the present invention;
[0021] Figure 4 A schematic block diagram of a data source switching device provided in an embodiment of the present invention;
[0022] Figure 5 A schematic block diagram of a subunit of a data source switching device provided in an embodiment of the present invention;
[0023] Figure 6A schematic block diagram of another subunit of the data source switching device provided in an embodiment of the present invention;
[0024] Figure 7 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0026] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0027] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0028] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0029] See also Figure 1 , Figure 1 A data source switching method is provided in an embodiment of the present invention. The data source switching method may include steps S101 to S103:
[0030] S101, controlling the long connection between the auxiliary data source and the main data source;
[0031] The sharedpool in the database data source is a RAM area (random access memory area), and the RAM area is created at startup and belongs to a component of the System Global Area (SGA). It is mainly used to cache some commonly used SQL statements (such as SQL statements that have been parsed so that they can be reused) and some table and view dependency information. In actual applications, each time the preset switching condition is reached, the old data source will switch to the new data source, and the corresponding sharedpool of the new data source is obtained by creating a new RAM area, so the data in the RAM area is empty. In other words, the sharedpool is cleared, which causes the transaction to be unable to be processed in time when a new transaction request arrives at the transaction system and requests the data source, resulting in an increase in the transaction failure rate. The embodiment of the present invention has discovered this problem, so the auxiliary data source is long-connected with the main data source. In this way, when switching the data source, since the sharedpool will not be cleared, it is not necessary to re-cache some commonly used SQL statements and some table and view dependency information. Therefore, the embodiment of the present invention connects the auxiliary data source with the main data source for a long time, so that even if there is a new transaction request, the transaction can be carried out normally, which can reduce the occurrence of transaction delays and failures.
[0032] The long connection mentioned in the embodiment of the present invention is relative to the short connection, which literally means maintaining the connection status between the client and the server for a long time. The usual short connection operation steps are: connection-data transmission-close connection; and the long connection operation steps are: connection-data transmission-maintain connection-data transmission-maintain connection-…………-close connection. In order to achieve a long connection, data packets can be sent periodically when there is no data communication to maintain the connection status. Since the auxiliary data source and the main data source use a long connection, the auxiliary data source and the main data source will remain connected. Then, when the data source is switched, the sharedpool will not be cleared, so the continuity of the transaction is guaranteed.
[0033] In one embodiment, if Figure 2 As shown, the step S101 includes steps S201 to S202:
[0034] S201, creating a new auxiliary data source and retaining the original auxiliary data source;
[0035] In the embodiment of the present invention, a new auxiliary data source is created while retaining the original auxiliary data source, so that there will be at least two auxiliary data sources in the entire system. The purpose of this is that even if the auxiliary data source connected to the main data source crashes, the main data source can be connected to another auxiliary data source in time to avoid transaction failure.
[0036] The auxiliary data source in the embodiment of the present invention can be an ADG (Active Data Guard) data source. The ADG data source supports multiple functions, such as real-time query (refreshing the latest data of the primary database to the physical standby database), automatic block repair (automatically repairing bad data blocks), remote synchronization (primary and standby synchronization, which can achieve zero data loss protection), standby database block tracking (enabling incremental backup on the standby database), rolling upgrade (simplifying planned downtime), global database services (load balancing and service management across replicated databases), application continuity (making interruptions transparent to users), etc.
[0037] S202: Controlling a long connection between the newly created auxiliary data source and the primary data source.
[0038] In the embodiment of the present invention, the newly created auxiliary data source can be controlled to establish a long connection with the main data source, so that the original auxiliary data source will be used as a backup auxiliary data source. Generally, the backup auxiliary data source will not work. Only when the auxiliary data source in the long connection state crashes, the main data source will connect to the backup auxiliary data source and switch the data source, ensuring that transactions are not affected even if a crash occurs.
[0039] S102, performing statistical analysis on the historical transaction data, predicting two time points with the smallest transaction volume in a future transaction cycle: a first time point and a second time point; or performing statistical analysis on the historical transaction data, predicting two time points with the smallest transaction failure rate in a future transaction cycle: a third time point and a fourth time point;
[0040] In the embodiment of the present invention, two time points need to be found in a transaction cycle. The purpose of finding these two time points is to control the switching of the primary data source to the secondary data source at one time point and to switch the secondary data source back to the primary data source at another time point.
[0041] The purpose of controlling the switching of the primary data source to the secondary data source at a time point is that the transaction volume is small, the read and write resources of the primary data source are wasted, and the operation and maintenance cost of the primary data source is high, so the primary data source needs to be switched to the secondary data source.
[0042] The purpose of controlling the switching of the auxiliary data source back to the primary data source at another time point is that the performance of the primary data source is better than that of the auxiliary data source, so during the peak trading period, the primary data source is used to ensure the transaction success rate.
[0043] There are two ways to find these two time points. One is to use the two time points with the smallest transaction volume in a trading cycle as the target time points, and the other is to use the two time points with the smallest transaction failure rate in a trading cycle as the target time points. Both of these time points can be used as switching time points. One is to consider from the dimension of transaction volume, and the other is to consider from the dimension of transaction failure rate. The following is a detailed description of these two methods.
[0044] In one embodiment, if Figure 3 As shown, the statistical analysis of historical transaction data to predict two time points with the lowest transaction failure rate in a future transaction cycle: the third time point and the fourth time point, includes steps S301 to S304:
[0045] S301, setting a transaction failure rate prediction function, wherein the failure rate prediction function includes a weight of the degree of influence on the transaction failure rate;
[0046] In one embodiment, the transaction failure rate prediction function is:
[0047] h(θ)=θ0+θ1x1+θ2x2
[0048] Among them, x1 represents the time point, x2 represents the trading cycle, and θ0, θ1, and θ2 all represent weights.
[0049] The significance of the transaction failure rate prediction function is to predict the transaction failure rate at a certain time point (the time point can be a certain time period) within a certain transaction cycle.
[0050] Assuming that the transaction cycle is a day and the length of the time point is one minute, then taking a certain day as an example, 0 represents the first minute of the morning, 1 represents the second minute of the morning, and so on, until the 1440th minute. The significance of the above transaction failure rate prediction function is to predict the transaction failure rate within a certain minute of a certain day.
[0051] Of course, the above time points and transaction cycles can also be normalized so that they can converge as quickly as possible and improve computing efficiency in the subsequent processing.
[0052] S302, performing statistics on historical transaction data to obtain the true value of the failure rate at each time point in each transaction cycle, and calculating the predicted value of the failure rate at each time point in each transaction cycle according to the transaction failure rate prediction function;
[0053] This step is to obtain the true value of the failure rate at each time point in each historical trading cycle. For example, the true value of the failure rate at all time points (0-1440) every day from January 1, 2018 to December 31, 2018.
[0054] At the same time, the predicted failure rate values at each time point in each transaction cycle are calculated according to the above transaction failure rate prediction function. Of course, the transaction cycles mentioned here should be the same as the transaction cycles when the above failure rate true value is obtained, and the time points should also be the same. This can facilitate the one-to-one correspondence of subsequent calculations. For example, the above transaction failure rate prediction function can be used to calculate the predicted failure rate values at all time points (0-1440) every day from January 1, 2018 to December 31, 2018.
[0055] S303, calculating the difference between the actual failure rate and the predicted failure rate at each time point in each transaction cycle, and determining the weight and the transaction failure rate prediction function according to the obtained difference;
[0056] In this step, it is necessary to calculate the sum of the differences between the actual value of the failure rate and the predicted value of the failure rate at each time point in each transaction cycle to obtain the error sum; obtain the weight of the transaction failure rate prediction function that minimizes the error sum;
[0057] Specifically, the error and J(θ) can be statistically calculated using the following cost function:
[0058]
[0059] Among them, h θ (x i ) represents the predicted value of the failure rate of the i-th sample, y i Represents the true value of the failure rate of the i-th sample, with a total of m samples.
[0060] In this way, the error sum under all samples can be obtained. By setting different weights, different transaction failure rate prediction functions can be obtained. In this way, different error sums can be obtained under different transaction failure rate prediction functions. By comparing all error sums, when the error sum is the lowest, the corresponding transaction failure rate prediction function should be the most accurate transaction failure rate prediction function, so the weight at this time can be used as the final weight.
[0061] S304. Calculate two time points with the lowest transaction failure rate in a future transaction cycle according to the determined weights and the transaction failure rate prediction function: the third time point and the fourth time point.
[0062] The weight determined in step S303 and the transaction failure rate prediction function can be used to calculate the transaction failure rate at various time points in a future transaction cycle, and then the two time points with the minimum transaction failure rate can be obtained by comparison: the third time point and the fourth time point. The two time points thus found can be used as the time points for data source switching.
[0063] In one embodiment, after step S304, the method further includes:
[0064] The samples are updated and the weights and transaction failure rate prediction function are re-determined, and the two time points with the minimum transaction failure rate in the next transaction cycle are recalculated: the third time point and the fourth time point.
[0065] As time goes by, historical transaction data is constantly updated, that is, samples are constantly updated, so a more accurate transaction failure rate prediction function and corresponding weights can be recalculated based on the updated historical transaction data, that is, the transaction failure rate prediction function is more suitable for the latest transaction situation. In this way, the two time points with the lowest transaction failure rate can be predicted more accurately in the future transaction cycle.
[0066] In one embodiment, the statistical analysis of historical transaction data to predict two time points with the smallest transaction volume in a future transaction cycle: a first time point and a second time point, includes:
[0067] The transaction volume data at each time point of each historical trading cycle are collected and a transaction volume time series diagram is drawn. The two time points with the smallest transaction volume in a future trading cycle are predicted based on the transaction volume time series diagram.
[0068] In this embodiment, the transaction volume data of all time points in each trading cycle are first counted, and then a transaction volume time series diagram is made, so that the change of transaction volume over time can be clearly understood according to the transaction volume time series diagram. Therefore, the two time points with the smallest transaction volume in a trading cycle can be obtained according to the transaction volume time series diagram. However, for each trading cycle, these two time points may be different, so it is impossible to accurately estimate two time points that can meet the future trend. Therefore, the embodiment of the present invention preferably adopts a solution based on the transaction failure rate for prediction.
[0069] In one embodiment, the first time point and the second time point satisfy: the difference between the first time point and the second time point is greater than the first time threshold; the third time point and the fourth time point satisfy: the difference between the third time point and the fourth time point is greater than the second time threshold.
[0070] Since the transaction volume generally changes continuously, the transaction failure rate may also change continuously. Therefore, no matter which of the above solutions is adopted, the first time point and the second time point finally found may be very close, or the third time point and the fourth time point finally found may be very close. If you switch back and forth between two very close time points, it is obviously meaningless to switch the data source. Therefore, the embodiment of the present invention limits the time interval between the two time points finally determined. Specifically, when the solution based on the transaction volume is adopted, the difference between the first time point and the second time point should be greater than the first time threshold; when the solution based on the transaction failure rate is adopted, the difference between the third time point and the fourth time point finally determined should be greater than the first time threshold.
[0071] The first time threshold and the second time threshold can be set to be the same or different according to the specific situation. The length of the first time threshold and the second time threshold can also be set according to the specific situation. For example, assuming that a transaction cycle is one day, the first time threshold and the second time threshold can be 3 hours, that is, the two time points finally determined should be at least 3 hours apart.
[0072] S103: When a first time point is reached, the control is to switch the primary data source to the secondary data source, and when a second time point is reached, the control is to switch the secondary data source to the primary data source; or, when a first time point is reached, the control is to switch the secondary data source to the primary data source, and when a second time point is reached, the control is to switch the primary data source to the secondary data source; or, when a third time point is reached, the control is to switch the primary data source to the secondary data source, and when a fourth time point is reached, the control is to switch the secondary data source to the primary data source; or, when a third time point is reached, the control is to switch the secondary data source to the primary data source, and when a fourth time point is reached, the control is to switch the primary data source to the secondary data source.
[0073] This step is to switch the data source according to the two time points determined in step S102.
[0074] Specifically, when the first time point and the second time point are used, if the data source used before the first time point is the primary data source, then when the first time point is reached, the primary data source can be controlled to be switched to the secondary data source; if the data source used before the first time point is the secondary data source, then when the first time point is reached, the secondary data source can be controlled to be switched to the primary data source. Then, when the second time point is reached, the current data source is controlled to be switched to another data source, for example, the secondary data source is controlled to be switched to the primary data source, or the primary data source is controlled to be switched to the secondary data source.
[0075] Similarly, when the third time point and the fourth time point are used, if the data source used before the third time point is the primary data source, then when the third time point is reached, the primary data source can be controlled to switch to the secondary data source; if the data source used before the third time point is the secondary data source, then when the fourth time point is reached, the secondary data source can be controlled to switch to the primary data source. Then, when the fourth time point is reached, the current data source is controlled to switch to another data source, for example, the secondary data source is controlled to switch to the primary data source, or the primary data source is controlled to switch to the secondary data source.
[0076] Through the method of the embodiment of the present invention, transaction delay can be reduced and transaction performance can be improved when the data source is switched; even if a large number of transactions occur in a concentrated manner after the data source is switched, the transaction performance is within a stable and efficient range.
[0077] The embodiment of the present invention further provides a data source switching device, which is used to execute any embodiment of the aforementioned data source switching method. Figure 4 , Figure 4 4 is a schematic block diagram of a data source switching device provided by an embodiment of the present invention. The data source switching device 400 may be configured in a server.
[0078] The data source switching device 400 may include:
[0079] A long connection unit 401 is used to control the long connection between the auxiliary data source and the main data source;
[0080] The statistical unit 402 is used to perform statistical analysis on the historical transaction data and predict two time points with the smallest transaction volume in a future transaction cycle: a first time point and a second time point; or perform statistical analysis on the historical transaction data and predict two time points with the smallest transaction failure rate in a future transaction cycle: a third time point and a fourth time point;
[0081] The switching unit 403 is used to control the switching of the primary data source to the secondary data source when the first time point is reached, and control the switching of the secondary data source to the primary data source when the second time point is reached; or, when the first time point is reached, control the switching of the secondary data source to the primary data source, and when the second time point is reached, control the switching of the primary data source to the secondary data source; or, when the third time point is reached, control the switching of the primary data source to the secondary data source, and when the fourth time point is reached, control the switching of the secondary data source to the primary data source; or, when the third time point is reached, control the switching of the secondary data source to the primary data source, and when the fourth time point is reached, control the switching of the primary data source to the secondary data source.
[0082] In one embodiment, if Figure 5 As shown, the long connection unit 401 includes:
[0083] A new creation unit 501 is used to create a new auxiliary data source and retain the original auxiliary data source;
[0084] The control unit 502 is used to control the establishment of a long connection between the newly created auxiliary data source and the primary data source.
[0085] In one embodiment, if Figure 6 As shown, the statistical unit 402 includes:
[0086] A setting unit 601 is used to set a transaction failure rate prediction function, wherein the failure rate prediction function includes a weight of the degree of influence on the transaction failure rate;
[0087] The calculation unit 602 is used to collect statistics on historical transaction data, obtain the actual value of the failure rate at each time point in each transaction cycle, and calculate the predicted value of the failure rate at each time point in each transaction cycle according to the transaction failure rate prediction function;
[0088] A determination unit 603 is used to count the difference between the actual value of the failure rate and the predicted value of the failure rate at each time point in each transaction cycle, and determine the weight and the transaction failure rate prediction function according to the obtained difference;
[0089] The first prediction unit 604 is used to calculate two time points at which the transaction failure rate is the smallest in a future transaction cycle according to the determined weight and the transaction failure rate prediction function: a third time point and a fourth time point.
[0090] In one embodiment, the long connection unit 401 further includes:
[0091] The updating unit is used to update the samples and re-determine the weights and the transaction failure rate prediction function, and recalculate the two time points with the minimum transaction failure rate in the future transaction cycle: the third time point and the fourth time point.
[0092] In one embodiment, the transaction failure rate prediction function is:
[0093] h(θ)=θ0+θ1x1+θ2x2
[0094] Among them, x1 represents the time point, x2 represents the trading cycle, and θ0, θ1, and θ2 all represent weights.
[0095] In one embodiment, the long connection unit 401 includes:
[0096] The second prediction unit is used to collect statistics on the transaction volume data at each time point in each historical transaction cycle, draw a transaction volume time series diagram, and predict the two time points with the smallest transaction volume in a future transaction cycle based on the transaction volume time series diagram.
[0097] In one embodiment, the first time point and the second time point satisfy: the difference between the first time point and the second time point is greater than the first time threshold; the third time point and the fourth time point satisfy: the difference between the third time point and the fourth time point is greater than the second time threshold.
[0098] Through the device of the embodiment of the present invention, transaction delay can be reduced and transaction performance can be improved when the data source is switched; even if a large number of transactions occur in a concentrated manner after the data source is switched, the transaction performance is within a stable and efficient range.
[0099] The above-mentioned data source switching device can be implemented in the form of a computer program. The computer program can be Figure 7 Runs on the computer device shown.
[0100] See also Figure 7 , Figure 7 Schematic block diagram of a computer device provided by an embodiment of the present invention. The computer device 7 may be a server, and the server may be an independent server or a server cluster composed of multiple servers.
[0101] See also Figure 7 The computer device 700 includes a processor 702 , a memory and a network interface 705 connected via a system bus 701 , wherein the memory may include a non-volatile storage medium 703 and an internal memory 704 .
[0102] The non-volatile storage medium 703 may store an operating system 7031 and a computer program 7032. When the computer program 7032 is executed, the processor 702 may execute a data source switching method.
[0103] The processor 702 is used to provide computing and control capabilities and support the operation of the entire computer device 700.
[0104] The internal memory 704 provides an environment for the operation of the computer program 7032 in the non-volatile storage medium 703. When the computer program 7032 is executed by the processor 702, the processor 702 can execute the data source switching method.
[0105] The network interface 705 is used for network communication, such as providing data information transmission, etc. Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device 700 to which the solution of the present invention is applied. The specific computer device 700 may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0106] The processor 702 is used to run the computer program 7032 stored in the memory to implement the following functions: controlling the secondary data source to be long connected with the primary data source;
[0107] Performing statistical analysis on historical transaction data to predict two time points with the smallest transaction volume in a future transaction cycle: a first time point and a second time point; or, performing statistical analysis on historical transaction data to predict two time points with the smallest transaction failure rate in a future transaction cycle: a third time point and a fourth time point; when the first time point is reached, controlling the primary data source to switch to the secondary data source, and when the second time point is reached, controlling the secondary data source to switch to the primary data source; or, when the first time point is reached, controlling the secondary data source to switch to the primary data source, and when the second time point is reached, controlling the primary data source to switch to the secondary data source; or, when the third time point is reached, controlling the primary data source to switch to the secondary data source, and when the fourth time point is reached, controlling the secondary data source to switch to the primary data source; or, when the third time point is reached, controlling the secondary data source to switch to the primary data source, and when the fourth time point is reached, controlling the primary data source to switch to the secondary data source.
[0108] In one embodiment, when executing the step of controlling the long connection between the auxiliary data source and the primary data source, the processor 702 performs the following operations: creating a new auxiliary data source and retaining the original auxiliary data source; and controlling the long connection between the new auxiliary data source and the primary data source.
[0109] In one embodiment, the processor 702 performs the following operations when executing the step of performing statistical analysis on the historical transaction data and predicting the two time points with the lowest transaction failure rate in a future transaction cycle: a third time point and a fourth time point: setting a transaction failure rate prediction function, wherein the failure rate prediction function includes a weight for the degree of influence on the transaction failure rate; performing statistics on the historical transaction data to obtain the true value of the failure rate at each time point in each transaction cycle, and calculating the predicted value of the failure rate at each time point in each transaction cycle according to the transaction failure rate prediction function; calculating the difference between the true value of the failure rate and the predicted value of the failure rate at each time point in each transaction cycle, and determining the weight and the transaction failure rate prediction function based on the obtained difference; and calculating the two time points with the lowest transaction failure rate in a future transaction cycle: the third time point and the fourth time point based on the determined weight and the transaction failure rate prediction function.
[0110] In one embodiment, after executing the step of calculating the two time points with the smallest transaction failure rate in a future transaction cycle: the third time point and the fourth time point based on the determined weights and the transaction failure rate prediction function, the processor 702 performs the following operations: updating the samples and re-determining the weights and the transaction failure rate prediction function, and recalculating the two time points with the smallest transaction failure rate in a future transaction cycle: the third time point and the fourth time point.
[0111] In one embodiment, when the processor 702 executes the step of performing statistical analysis on historical transaction data and predicting two time points with the smallest transaction volume in a future trading cycle: a first time point and a second time point, the processor 702 performs the following operations: statistically analyzing the transaction volume data at each time point in each historical trading cycle, and drawing a transaction volume time series graph, and predicting the two time points with the smallest transaction volume in a future trading cycle based on the transaction volume time series graph.
[0112] Those skilled in the art will understand that Figure 7 The embodiments of the computer device shown in the figure do not constitute a limitation on the specific composition of the computer device. In other embodiments, the computer device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, in some embodiments, the computer device may only include a memory and a processor. In such embodiments, the structure and function of the memory and the processor are the same as those of the embodiment of the present invention. Figure 7 The embodiments shown are consistent and will not be described again here.
[0113] It should be understood that in the embodiment of the present invention, the processor 702 may be a central processing unit (CPU), and the processor 702 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0114] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium may be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the following steps are implemented: controlling a secondary data source to be long-connected with a primary data source;
[0115] Performing statistical analysis on historical transaction data to predict two time points with the smallest transaction volume in a future transaction cycle: a first time point and a second time point; or, performing statistical analysis on historical transaction data to predict two time points with the smallest transaction failure rate in a future transaction cycle: a third time point and a fourth time point; when the first time point is reached, controlling the primary data source to switch to the secondary data source, and when the second time point is reached, controlling the secondary data source to switch to the primary data source; or, when the first time point is reached, controlling the secondary data source to switch to the primary data source, and when the second time point is reached, controlling the primary data source to switch to the secondary data source; or, when the third time point is reached, controlling the primary data source to switch to the secondary data source, and when the fourth time point is reached, controlling the secondary data source to switch to the primary data source; or, when the third time point is reached, controlling the secondary data source to switch to the primary data source, and when the fourth time point is reached, controlling the primary data source to switch to the secondary data source.
[0116] In one embodiment, controlling the secondary data source to establish a long connection with the primary data source includes: creating a new secondary data source and retaining the original secondary data source; and controlling the new secondary data source to establish a long connection with the primary data source.
[0117] In one embodiment, the statistical analysis of historical transaction data to predict two time points with the lowest transaction failure rate in a future transaction cycle: a third time point and a fourth time point, includes: setting a transaction failure rate prediction function, wherein the failure rate prediction function includes a weight for the degree of influence on the transaction failure rate; performing statistics on the historical transaction data to obtain the true value of the failure rate at each time point in each transaction cycle, and calculating the predicted value of the failure rate at each time point in each transaction cycle according to the transaction failure rate prediction function; calculating the difference between the true value of the failure rate and the predicted value of the failure rate at each time point in each transaction cycle, and determining the weight and the transaction failure rate prediction function based on the obtained difference; and calculating the two time points with the lowest transaction failure rate in a future transaction cycle based on the determined weight and the transaction failure rate prediction function: the third time point and the fourth time point.
[0118] In one embodiment, after calculating the two time points with the smallest transaction failure rate in a future transaction cycle: the third time point and the fourth time point based on the determined weights and the transaction failure rate prediction function, it also includes: updating the samples and re-determining the weights and the transaction failure rate prediction function, and recalculating the two time points with the smallest transaction failure rate in a future transaction cycle: the third time point and the fourth time point.
[0119] In one embodiment, the transaction failure rate prediction function is: h(θ)=θ0+θ1x1+θ2x2, wherein x1 represents a time point, x2 represents a transaction cycle, and θ0, θ1, and θ2 all represent weights.
[0120] In one embodiment, the statistical analysis of historical transaction data to predict two time points with the smallest transaction volume in a future trading cycle: a first time point and a second time point, includes: statistically analyzing the transaction volume data at each time point in each historical trading cycle, and drawing a transaction volume time series graph, and predicting the two time points with the smallest transaction volume in a future trading cycle based on the transaction volume time series graph.
[0121] In one embodiment, the first time point and the second time point satisfy: the difference between the first time point and the second time point is greater than the first time threshold; the third time point and the fourth time point satisfy: the difference between the third time point and the fourth time point is greater than the second time threshold.
[0122] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the above-described equipment, devices and units can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. Those of ordinary skill in the art can appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with 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 the function. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0123] In the several embodiments provided by the present invention, it should be understood that the disclosed equipment, 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 units is only a logical function division. There may be other division methods in actual implementation. Units with the same function may also be combined into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or units, or may be an electrical, mechanical or other form of connection.
[0124] The units described 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 embodiments of the present invention.
[0125] In addition, each functional unit in each embodiment of the present invention 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.
[0126] 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 storage medium. Based on this understanding, the technical solution of the present invention is essentially 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. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), disk or optical disk and other media that can store program codes.
[0127] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A data source switching method, characterized in that: include: Control the long connection between the auxiliary data source and the main data source; Statistical analysis is performed on historical transaction data to predict the two time points with the lowest transaction failure rate in the next transaction cycle: the third time point and the fourth time point; When the third time point is reached, the control switches the primary data source to the secondary data source, and when the fourth time point is reached, the control switches the secondary data source to the primary data source; or, when the third time point is reached, the control switches the secondary data source to the primary data source, and when the fourth time point is reached, the control switches the primary data source to the secondary data source; When switching data sources, the corresponding shared pool is not cleared; The statistical analysis of historical transaction data to predict the two time points with the lowest transaction failure rate in a future transaction cycle: the third time point and the fourth time point, includes: Setting a transaction failure rate prediction function, wherein the failure rate prediction function includes a weight of the degree of influence on the transaction failure rate; Perform statistics on historical transaction data to obtain the true value of the failure rate at each time point in each transaction cycle, and calculate the predicted value of the failure rate at each time point in each transaction cycle according to the transaction failure rate prediction function; Count the difference between the actual failure rate and the predicted failure rate at each time point in each transaction cycle, and determine the weight and transaction failure rate prediction function based on the obtained difference; The error and J(θ) are calculated by the following loss function: Among them, h θ (x i ) represents the predicted value of the failure rate of the i-th sample, y i represents the true value of the failure rate of the i-th sample, with a total of m samples; According to the determined weights and the transaction failure rate prediction function, two time points with the lowest transaction failure rate in the next transaction cycle are calculated: the third time point and the fourth time point; The method further includes calculating the two time points with the minimum transaction failure rate in a future transaction cycle according to the determined weights and the transaction failure rate prediction function: the third time point and the fourth time point, and further includes: Update the samples and re-determine the weights and transaction failure rate prediction function, and recalculate the two time points with the lowest transaction failure rate in the next transaction cycle: the third time point and the fourth time point; The transaction failure rate prediction function is: h(θ)=θ0+θ1x1+θ2x2 Among them, x1 represents the normalized time point, x2 represents the normalized trading cycle, and θ0, θ1, and θ2 all represent weights.
2. The data source switching method according to claim 1, characterized in that: The control of establishing a long connection between the auxiliary data source and the primary data source includes: Create a new auxiliary data source and keep the original auxiliary data source; Control the establishment of a long connection between the newly created auxiliary data source and the primary data source.
3. The data source switching method according to any one of claims 1 to 2, characterized in that: The third time point and the fourth time point satisfy: a difference between the third time point and the fourth time point is greater than a second time threshold.
4. A data source switching device, characterized in that: include: A long connection unit, used to control the long connection between the auxiliary data source and the main data source; A statistical unit is used to perform statistical analysis on historical transaction data and predict two time points with the lowest transaction failure rate in a future transaction cycle: the third time point and the fourth time point; a switching unit, configured to control the switching of the primary data source to the secondary data source when a third time point is reached, and control the switching of the secondary data source to the primary data source when a fourth time point is reached; or, control the switching of the secondary data source to the primary data source when the third time point is reached, and control the switching of the primary data source to the secondary data source when the fourth time point is reached; When switching data sources, the corresponding shared pool is not cleared; The statistical unit comprises: A setting unit, used to set a transaction failure rate prediction function, wherein the failure rate prediction function includes a weight of the degree of influence on the transaction failure rate; A calculation unit, used to perform statistics on historical transaction data, obtain the true value of the failure rate at each time point in each transaction cycle, and calculate the predicted value of the failure rate at each time point in each transaction cycle according to the transaction failure rate prediction function; A determination unit, used to count the difference between the actual value of the failure rate and the predicted value of the failure rate at each time point in each transaction cycle, and determine the weight and the transaction failure rate prediction function according to the obtained difference; The error and J(θ) are calculated by the following loss function: Among them, h θ (x i ) represents the predicted value of the failure rate of the i-th sample, y i represents the true value of the failure rate of the i-th sample, with a total of m samples; The first prediction unit is used to calculate two time points at which the transaction failure rate is the smallest in a future transaction cycle according to the determined weight and the transaction failure rate prediction function: a third time point and a fourth time point; After the statistical unit, it also includes: An updating unit, used to update the samples and re-determine the weights and the transaction failure rate prediction function, and recalculate the two time points with the minimum transaction failure rate in the next transaction cycle: the third time point and the fourth time point; The transaction failure rate prediction function is: h(θ)=θ0+θ1x1+θ2x2 Among them, x1 represents the normalized time point, x2 represents the normalized trading cycle, and θ0, θ1, and θ2 all represent weights.
5. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the data source switching method according to any one of claims 1 to 3 is implemented.
6. 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 data source switching method according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Method and device for code rate switch of smart television
CN103561283A
A control method, a data terminal and a data transmitting device
CN103634540A
Host batch recovery processing method and device based on double centers
CN104615511A
Master-slave role conversion method, chip and data transmission system
CN108323241A
Large-scale multi-detector predictive modeling
US20140200870A1
