Disclosure of Invention
The invention mainly aims to provide a method for avoiding congestion of a client accessing a server, aiming at solving the defect of server deadlock caused by overlarge access amount of the client to the server.
In order to achieve the above object, the method for avoiding congestion of a client accessing a server provided by the present invention comprises the following steps:
when detecting that a user issues order information to a first database in a server, storing the order information in the first database;
acquiring a preset order information processing sequence, and sequentially storing each order information stored in the first database to the second database according to the order information processing sequence;
processing each order information in the second database respectively, and deleting the processed order information from the second database;
and acquiring the processing state of each order information from the second database, and updating the processing state of the order information to the first database.
Preferably, the step of acquiring a preset order information processing sequence and sequentially storing each of the order information stored in the first database to the second database according to the order information processing sequence includes:
acquiring the release time of each order information stored in the first database;
determining the order information processing sequence according to the release time of each order information stored in the first database;
and sequentially storing each order information stored in the first database to the second database according to the order information processing sequence.
Preferably, the step of sequentially storing each of the order information stored in the first database to the second database according to the order information processing sequence includes:
judging whether a condition for storing the order information stored in the first database to the second database is met;
when the condition that the order information stored in the first database is stored in the second database is met, the order information which is not stored in the first database and is the most front in the distribution sequence of the second database is stored in the second database according to the sequence of the distribution time of each order information stored in the first database.
Preferably, the step of determining whether a condition for storing the order information stored in the first database to the second database is reached includes:
acquiring whether unprocessed order information exists in the second database;
and determining whether a condition for storing the order information stored in the first database to the second database is met according to whether unprocessed order information exists in the second database.
Preferably, the step of processing each order information in the second database and deleting the processed order information from the second database includes:
acquiring a preset first query period;
inquiring whether new order information is received in the second database according to the first inquiry period;
processing the new order information received in the second database;
and deleting the processed order information in the second database from the second database.
Preferably, the step of acquiring the processing status of each of the order information from the second database and updating the processing status of the order information to the first database includes:
acquiring a preset second query period, and querying whether new order information stored in the second database is processed or not according to the second query period;
and when the new order information stored in the second database is processed, updating the state of the processed order information to the first database.
Preferably, the step of acquiring a preset second query period, and querying whether new order information stored in the second database is processed according to the second query period includes:
acquiring a preset second query period;
acquiring whether the order information exists in the second database periodically according to the second query period;
when the order information does not exist in the second database, determining that the order information in the second database is deleted;
and when the order information in the second database is deleted, determining that the new order information stored in the second database is in a processed state.
Preferably, after the step of periodically acquiring whether the order information exists in the second database according to the second query period, the method further includes:
and when the order information exists in the second database, determining that the new order information stored in the second database is in an unprocessed state.
In addition, to achieve the above object, the present invention also provides a terminal, including: memory, a processor and a computer program stored on the memory and executable on the processor, the computer program, when executed by the processor, implementing the steps of the method according to any one of the preceding claims.
Furthermore, to achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, realizes the steps of the method of any one of the above.
In the technical scheme of the invention, when detecting that a user issues order information to a first database in a server, the method for avoiding the congestion of the client accessing the server stores the order information in the first database; acquiring a preset order information processing sequence, and sequentially storing each order information stored in the first database to the second database according to the order information processing sequence; processing each order information in the second database respectively, and deleting the processed order information from the second database; and acquiring the processing state of each order information from the second database, and updating the processing state of the order information to the first database. The first database is used for permanently storing the order information, the second database is used for temporarily storing the order information, the processing process of each order information is processed and completed in the second database, and the processing state of the order information is returned to the first database for storage after the processing is completed.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, to achieve the above object, a first embodiment of the present invention provides a method for avoiding congestion of a client accessing a server, including the following steps:
step S10, when it is detected that a user issues order information to a first database in a server, storing the order information in the first database;
step S20, acquiring a preset order information processing sequence, and sequentially storing each of the order information stored in the first database to the second database according to the order information processing sequence;
step S30, processing each order information in the second database, and deleting the processed order information from the second database;
step S40, obtaining the processing status of each order information from the second database, and updating the processing status of the order information to the first database.
In the technical scheme of the invention, when detecting that a user issues order information to a first database in a server, the method for avoiding the congestion of the client accessing the server stores the order information in the first database; acquiring a preset order information processing sequence, and sequentially storing each order information stored in the first database to the second database according to the order information processing sequence; processing each order information in the second database respectively, and deleting the processed order information from the second database; and acquiring the processing state of each order information from the second database, and updating the processing state of the order information to the first database. The first database is used for permanently storing the order information, the second database is used for temporarily storing the order information, the processing process of each order information is processed and completed in the second database, and the processing state of the order information is returned to the first database for storage after the processing is completed.
Specifically, the server in the invention comprises a first database for permanently storing the user order information, a second database for storing the user order information in a short time, a first timer, a second timer and a processing module for processing the order information. In this embodiment, the first database may be Mysql, and the second database is Redis.
When a user clicks a button for confirming the release of order information at a client, the system detects that the user releases the order information to a first database in a server, the system stores the order information released by the user to the first database, and then queues and sequentially stores all the order information stored in the first database to a second database according to a preset sequence.
It is easy to understand that the number of the first databases and the number of the second databases may be set according to needs, and are not limited specifically here, in this embodiment, the number of the first databases is one, and the number of the second databases is also one, and of course, a plurality of second databases may also be set in the system, and the enabled number of the second databases is determined according to the number of the order information in the first databases.
For example, when the number of the second databases is three (database a, database B, and database C, respectively), a first set number is set as a, a second set number is set as B, a third set number is set as C, and 0 < a < B < C. And when the quantity of the order information in the first database does not exceed a, all the order information in the first database is stored in a database A for processing. When the quantity of the order information in the first database exceeds a and does not exceed B, storing a order information with the release time of the first a name in the first database into a database A for processing, and storing other order information in the first database into a database B for processing. When the quantity of the order information in the first database exceeds B and does not exceed C, storing a order information with the release time of the first a name in the first database into a database A for processing, storing B-a order information with the release time of the first B-a name in the first database into a database B for processing, and storing other order information in the first database into a database C for processing.
Referring to fig. 2, in a first embodiment of the method for avoiding congestion of a client accessing a server according to the present invention, and in a second embodiment of the method for avoiding congestion of a client accessing a server according to the present invention, the step S20 is to obtain a preset order information processing sequence, and sequentially store each of the order information stored in the first database into the second database according to the order information processing sequence, where the method includes:
step S21, acquiring the distribution time of each order information stored in the first database;
step S22, determining the order information processing order according to the distribution time of each order information stored in the first database;
step S23, sequentially storing each of the order information stored in the first database into the second database according to the order information processing sequence.
There are various methods for determining the order information processing sequence according to the release time of each order information stored in the first database, for example, according to the order time of each order information stored in the first database, the order information with the former release time in the first database is preferentially stored in the second database; or, according to the order information release time sequence stored in the first database, preferentially storing the order information with the later release time in the first database to the second database, or according to the order information release time, making other order information processing sequences. In this embodiment, a method is adopted in which, according to the order information release time sequence stored in the first database, order information with a release time earlier in the first database is preferentially stored in the second database, so that order information generated first is preferentially processed, and order information generated later is processed later, and the order information generation sequence is met.
Referring to fig. 3, based on the second embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, in a third embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, the step S21 sequentially stores each of the order information stored in the first database into the second database according to the order information processing sequence, including:
step S24, determining whether a condition for storing the order information stored in the first database to the second database is met;
when the condition that the order information stored in the first database is stored in the second database is met, step S25 is executed, and the order information that is not stored in the first database but is the most advanced in the distribution order of the second database is stored in the second database according to the sequence of the distribution time of each order information stored in the first database.
The method of determining whether the condition for storing the order information stored in the first database to the second database is reached may be set as needed. For example, whether to store the order information stored in the first database into the second database may be determined according to whether processing of the order information in the second database is completed; or, whether to store the order information stored in the first database into the second database may be determined according to whether the number of unprocessed order information in the second database is smaller than a set number.
Based on the third embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, in a fourth embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, the step S24 of determining whether a condition for storing the order information stored in the first database in the second database is reached includes:
step S26, acquiring whether unprocessed order information exists in the second database;
step S27, determining whether a condition for storing the order information stored in the first database to the second database is reached according to whether unprocessed order information exists in the second database.
After the order information in the second database is processed, the unprocessed order information in the first database is stored in the second database, so that the communication congestion phenomenon of the second database is prevented, and the processing speed of the second database can be ensured.
Based on the fourth embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, in a fifth embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, the step S30 is to process each of the order information in the second database, and delete the processed order information from the second database, and includes:
step S31, acquiring a preset first query period;
step S32, inquiring whether new order information is received in the second database according to the first inquiry period;
step S33, processing the new order information received in the second database;
step S34, delete the order information processed in the second database from the second database.
In order to ensure the processing speed in the second database, one piece of unprocessed order information which is published in the first database at a time is stored in the second database, so that only one piece of order information is processed in the second database at a time.
Based on the fifth embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, in the sixth embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, the step S40 of acquiring the processing status of each of the order information from the second database and updating the processing status of the order information to the first database includes:
step S41, acquiring a preset second query period, and querying whether new order information stored in the second database is processed or not according to the second query period;
step S42, when the new order information stored in the second database is processed, updating the status of the processed order information to the first database.
The first query period and the second query period can be set according to needs, and in addition, the modification of the two periods can be carried out according to the setting of a user. The first polling period is controlled by a first timer, and the second polling period is controlled by a second timer.
Based on the sixth embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, in the seventh embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, the step S41 of acquiring a preset second query cycle, and querying whether new order information stored in the second database has been processed according to the second query cycle includes:
step S43, acquiring a preset second query period;
step S44, periodically obtaining whether the order information exists in the second database according to the second query period;
step S45, when the order information does not exist in the second database, determining that the order information in the second database is deleted;
step S46, when the order information in the second database is deleted, determining that the new order information stored in the second database is in a processed state.
According to the order information generation time sequence, storing one order information with the most front order generation time in unprocessed order information in the first database to the second database every time, so that only one order information is processed in the second database every time, and deleting the order information in the second database when the order information in the second database is processed; since the processed order information in the first database is marked with the processed identifier, when the unprocessed order information in the first database, which is generated most before the order generation time, is not searched in the second database, it indicates that the order information is processed in the second database, and at this time, the processed identifier may be added to the order information in the first database.
In order to avoid that the unprocessed order information in the first database, which is generated most ahead in order time, is added with the processed identifier when not being stored in the second database, further, when it is detected that the unprocessed order information in the first database, which is generated most ahead in order time, is stored in the second database, the stored identifier may be added to the order information in the first database, and when the stored order information in the first database, which is generated most ahead in order time, is not searched in the second database, it indicates that the order information is actually processed in the second database, at this time, the order information in the first database may be added with the processed identifier.
Based on the seventh embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, in an eighth embodiment of the method for avoiding congestion of the client accessing the server according to the present invention, after the step S44 regularly obtains whether the order information exists in the second database according to the second query cycle, the method further includes:
step S47, when the order information exists in the second database, determining that the new order information stored in the second database is in an unprocessed state.
The unprocessed state of the order information may be sent to the first database, and an unprocessed identifier is added to the order information in the first database, or the unprocessed state of the order information may not be sent to the first database, which are all included in the protection scope of the present invention and are not limited herein.
In addition, to achieve the above object, the present invention also provides a terminal, including: memory, a processor and a computer program stored on the memory and executable on the processor, the computer program, when executed by the processor, implementing the steps of the method according to any one of the preceding claims.
In some embodiments, the terminal 10 may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display) and an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may further include a standard wired interface and a standard wireless interface, and when in specific use, the front end obtains data through the user interface 1003. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the terminal configuration shown in fig. 4 is not intended to be limiting and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
Since the technical solution of the terminal 10 in this embodiment at least includes all technical solutions of the above method embodiments, at least all technical effects of the above embodiments are achieved, and details are not repeated here.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for causing a terminal device to perform the method according to the embodiments of the present invention.
Furthermore, to achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, realizes the steps of the method of any one of the above.
Since the technical solution of the computer-readable storage medium in this embodiment at least includes all technical solutions of the above method embodiments, at least all technical effects of the above embodiments are achieved, and details are not repeated here.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.