Disclosure of Invention
In order to overcome the defects in the prior art, the invention provides a concurrency number determining method, a concurrency number determining device and a server, which can solve the problem of low timeliness of the determined concurrency number.
In order to achieve the above object, the technical solutions provided by the embodiments of the present invention are as follows:
in a first aspect, an embodiment of the present invention provides a concurrency number determining method, where the method includes:
acquiring the number of request messages within a first preset time length;
and determining the concurrency number from the counting time to the current time according to a preset determination rule and the number of the request messages, wherein the time length between the counting time and the current time is a second preset time length which is greater than or equal to the first preset time length.
Optionally, the obtaining the number of the request packets within the first preset time duration includes:
and acquiring a request message sent by the user terminal based on an optical character recognition interface, and counting the number of the request message in the first preset time.
Optionally, the first preset duration is one second, and the counting the number of the request packets in the first preset duration includes:
and associating the current second and a preset request name as a Key based on a Key-Value database, caching, and determining the number of the request messages in the current second based on the corresponding relation between the Value obtained through a preset strategy and the number of the request messages.
Optionally, the Value obtained by the preset policy includes:
and within the current second, calling the Key once when the request message is the request message corresponding to the preset request name, and performing accumulation operation on a preset initial Value to obtain the Value after the Key is called.
Optionally, before obtaining the number of the request packets within the first preset time, the method further includes:
and classifying the request message according to the request name corresponding to the request message.
Optionally, the determining, according to a preset determination rule and the number of the request packets, a concurrency number from a statistical time to a current time includes:
and determining the maximum quantity of the quantities corresponding to the multiple sets of the first preset time lengths as the concurrency number from the counting time to the current time.
In a second aspect, an embodiment of the present invention provides a concurrency number determining apparatus, where the apparatus includes:
the device comprises an obtaining unit, a sending unit and a receiving unit, wherein the obtaining unit is used for obtaining the number of request messages in a first preset time length;
and the determining unit is used for determining the concurrency number from the counting time to the current time according to a preset determining rule and the number of the request messages, wherein the time length between the counting time and the current time is a second preset time length which is greater than or equal to the first preset time length.
Optionally, the obtaining unit is further configured to:
and acquiring a request message sent by the user terminal based on an optical character recognition interface, and counting the number of the request message in the first preset time.
Optionally, the obtaining unit is further configured to:
and associating the current second and a preset request name as a Key based on a Key-Value database, caching, and determining the number of the request messages in the current second based on the corresponding relation between the Value obtained through a preset strategy and the number of the request messages.
In a third aspect, an embodiment of the present invention provides a server, including:
a storage unit;
a processing unit; and
a concurrency number determination device including one or more software functional modules stored in the storage unit and executed by the processing unit, the concurrency number determination device comprising:
the device comprises an obtaining unit, a sending unit and a receiving unit, wherein the obtaining unit is used for obtaining the number of request messages in a first preset time length;
and the determining unit is used for determining the concurrency number from the counting time to the current time according to a preset determining rule and the number of the request messages, wherein the time length between the counting time and the current time is a second preset time length which is greater than or equal to the first preset time length.
Compared with the prior art, the concurrency number determining method, the concurrency number determining device and the server provided by the invention at least have the following beneficial effects: the method comprises the steps of obtaining the number of request messages in a first preset time length; and then according to the preset determination rule and the number of the request messages, determining the concurrency number from the counting time to the current time, so that the time of the counted concurrency number is close to the current time, and the timeliness of the concurrency number is improved. In addition, the time length between the statistical time and the current time is a second preset time length which is greater than or equal to the first preset time length, namely, a new concurrency number can be determined every other second preset time length, so that the timeliness of the determined concurrency number is improved.
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail below.
Detailed Description
The technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. It is to be understood that the described embodiments are merely a few embodiments of the invention, and not all embodiments. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Furthermore, the terms "first," "second," and the like are used merely to distinguish one description from another, and are not to be construed as indicating or implying relative importance.
Some embodiments of the invention are described in detail below with reference to the accompanying drawings. The embodiments described below and the features of the embodiments can be combined with each other without conflict.
Referring to fig. 1, an interaction diagram of a server 10 and a user terminal 20 according to an embodiment of the present invention is provided. The server 10 provided by the embodiment of the present invention can establish a communication connection with at least one user terminal 20 through a network to perform data interaction. In addition, the server 10 may count the number of concurrencies caused by the access of the user terminal 20 to the server 10. The concurrency number may refer to a Query Per Second (QPS), which is a measure of how much traffic a specific Query server 10 processes in a specified time, and may refer to the number of connections accessing a service site in one Second.
For example, in a banking institution, it is usually necessary to read and authenticate the user's identification card, and then handle corresponding services after the authentication is passed, such as changing the password or registering a new card or other services. At this time, the user terminal 20 may scan the identity card to obtain corresponding identity information, and then send a request message for identity authentication to the server 10, and the server 10 or another server 10 communicatively connected to the server 10 may authenticate the identity based on the request message. In addition, if a plurality of user terminals 20 simultaneously transmit request messages to the server 10 at the same time, the server 10 may count the number of concurrent requests.
The number of the user terminals 20 communicatively connected to the server 10 may be one or more, and the number may be set according to actual circumstances, and is not particularly limited herein.
In the present embodiment, the user terminal 20 may be, but is not limited to, a smart phone, a Personal Computer (PC), a tablet PC, a Personal Digital Assistant (PDA), a Mobile Internet Device (MID), and the like. The network may be, but is not limited to, a wired network or a wireless network.
Fig. 2 is a block diagram of a server 10 according to an embodiment of the present invention. In this embodiment, the server 10 may include a processing unit 11, a communication unit 12, a storage unit 13, and a concurrency determination apparatus 100, where the processing unit 11, the communication unit 12, the storage unit 13, and the concurrency determination apparatus 100 are directly or indirectly electrically connected to each other to implement data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines.
The processing unit 11 may be an integrated circuit chip having signal processing capabilities. The processing unit 11 may be a general purpose processor. For example, the Processor may be a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a Network Processor (NP), or the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed.
The communication unit 12 is used for establishing a communication connection between the server 10 and the user terminal 20 or other servers 10 via a network, and transceiving data via the network.
The storage unit 13 may be, but is not limited to, a random access memory, a read only memory, a programmable read only memory, an erasable programmable read only memory, an electrically erasable programmable read only memory, or the like. In this embodiment, the storage unit 13 may be configured to store data such as a Key-Value database and a preset duration. Of course, the storage unit 13 may also be used for storing a program, which the processing unit 11 executes upon receiving an execution instruction.
Further, the concurrency number determining apparatus 100 includes at least one software function module which may be stored in the storage unit 13 in the form of software or firmware (firmware) or solidified in an Operating System (OS) of the server 10. The processing unit 11 is configured to execute executable modules stored in the storage unit 13, such as software functional modules and computer programs included in the concurrency number determination apparatus 100.
It is understood that the configuration shown in fig. 2 is merely a schematic diagram of the configuration of the server 10, and that the server 10 may include more or less components than those shown in fig. 2. The components shown in fig. 2 may be implemented in hardware, software, or a combination thereof.
Fig. 3 is a flowchart illustrating a method for determining a concurrency number according to an embodiment of the present invention. The method for determining the number of concurrency provided by the embodiment of the invention can be applied to the server 10, and the server 10 executes each step of the method for determining the number of concurrency, so that the timeliness of the determined number of concurrency can be improved, and the phenomenon that the determined number of concurrency loses reference function due to the fact that the determined number of concurrency is too long from the current moment can be avoided. The concurrency number may be used for pressure monitoring of the server 10, and may be used as a basis for system framework and business process optimization of the server 10. For example, the larger the concurrency number is, the greater the pressure of the server 10 is, and at this time, the data processing service may be shared by other servers 10, so as to reduce the data processing pressure of the current server 10.
In this embodiment, the concurrency number determination method may include the steps of:
step S210, obtaining the number of request messages in a first preset time length;
step S220, according to a preset determination rule and the number of the request messages, determining the concurrency number from the counting time to the current time, wherein the time length between the counting time and the current time is a second preset time length which is greater than or equal to the first preset time length.
The steps of the concurrency determination method shown in fig. 3 will be described in detail below:
step S210, obtaining the number of request messages within a first preset duration.
The first preset duration may be set according to an actual situation, and the number of the request messages may be understood as the number of the request messages.
In this embodiment, step S210 may include: acquiring a request message sent by the user terminal 20 based on the optical character recognition interface, and counting the number of the request messages in a first preset time length.
An Optical Character Recognition (OCR) interface refers to a collection interface in an electronic device. Such as an interface for an external scanner or digital camera in a personal computer. OCR is understood to be a process in which a scanner or digital camera inspects characters printed on paper, determines their shapes by detecting dark and light patterns, and then translates the shapes into computer text using character recognition methods; the characters in the paper document are optically converted into image files with black and white dot matrixes for the print characters, and the characters in the images are converted into text formats through recognition software for further editing and processing by character processing software. For example, in identification card authentication, the user terminal 20 may extract identity information corresponding to the identification card by using a scanner or a digital camera based on OCR, and then the user terminal 20 transmits the identity information to the server 10 for authentication.
In this embodiment, step S210 may include: and based on a Key-Value database, associating the current second and the preset request name as a Key, caching, and determining the number of the request messages in the current second based on the corresponding relation between the Value obtained through a preset strategy and the number of the request messages.
The association between the current second and the preset request name is Key, which can be understood as: and establishing a mapping relation between the current one-second time information and a preset request name, and using the mapping relation as Key. For example, if the current second of a day is 00:00:01, the preset request name may be a name representing "identification" used for identification of an identification card, and the preset request name may be a name representing "identification" used for identification of the identification card, then the mapping relationship between "00: 00: 01" and "identification" may be established and used as a Key, so that the Key is used to count the concurrence number of the request name "identification" in the current second. In addition, after the statistics is completed, the user can also search the concurrence number with the time of 00:00:01 and the request name of 'identification' through the mapping relation. Of course, the preset request name may be set according to actual situations, and is not limited specifically here.
In this embodiment, the preset policy may be set according to actual conditions, for example, in the current second, every time an access request is received, a Key is called, and every time a Key is called, an addition operation is performed on a Value of the Key. In addition, each time a fixed constant, such as the numbers 1, 2, 3, etc., may be added to the Value.
When caching Key, Redis can be used for caching. Redis is an open source log-type and Key-Value database which is written by using ANSI C language, supports network, can be based on memory and can also be persistent, and provides API of multiple languages. The ANSI is a character code, and 1 byte in the range of 0x 00-0 x7f is usually used to represent 1 english character in order to make the computer support more languages. An API refers to an Application Programming Interface (API).
Understandably, Redis is a Key-Value storage system. Redis supports master-slave synchronization. Data may be synchronized from a master server 10 to any number of slave servers 10, and a slave server 10 may be a master server 10 associated with other slave servers 10. This enables Redis to perform single-level tree replication. The storage disk can write data intentionally or unintentionally. Due to the implementation of the publish/subscribe mechanism, when the tree is synchronized anywhere from the database, a channel can be subscribed to and the complete message publication record of the master server 10 can be received. Based on this, it is helpful to improve scalability of synchronization to read operations and to facilitate data backup so that source data can be retrieved from other servers 10 even if the source data is lost or damaged.
In this embodiment, if there are a plurality of servers 10 in the network environment, the server 10 executing the concurrency number determination method may be the main server 10.
For example, the first preset time period is one second. Step S210 may include: and in the current second, calling a Key once when the request message is the request message corresponding to the preset request name, and performing accumulation operation on the preset initial Value to obtain the Value after the Key is called.
Understandably, the request message includes the request type and the request name of the request message. After receiving the request message, the server 10 can call the Key corresponding to the message name of the request message. If the message name of the request message is the same as the preset message name in the Key or has a preset mapping relation, the Key corresponds to the request message. After each call, the Value corresponding to Key can be incremented by 1. Before the Key is called for the first time, the Value may be a preset Value (a preset initial Value), and may be set according to an actual situation.
Specifically, for example, the first preset duration is one second, for example, the preset initial Value is 0, if an access request is received within one second, a Key is called once, 1 is added to the initial Value after the Key is called once, and the final Value is 1 after the Value is added to 1. If the access request is received three times within one second, the Key is called 3 times correspondingly, then the accumulation operation of adding 1 to the initial Value three times is carried out, and then the final Value of 3 is obtained.
Prior to step S210, the concurrency number determination method may further include: and classifying the request message according to the request name corresponding to the request message.
For example, in a banking institution, the service types of the request message may include a transfer service, a withdrawal service, a register new card service, a change of encryption service, and the like. Understandably, based on the step, after the request message is classified, the concurrency number corresponding to each type of classified service is determined, which is helpful for a manager to monitor and manage the processing pressure of each type of service.
Step S220, according to a preset determination rule and the number of the request messages, determining the concurrency number from the counting time to the current time, wherein the time length between the counting time and the current time is a second preset time length which is greater than or equal to the first preset time length.
Understandably, the second preset duration can be set according to the actual situation, and the statistical time corresponds to the second preset duration. For example, the second preset time period is set to be a time period between 5 seconds and 60 seconds, for example, if the second preset time period is 5 seconds, and in the same day, if the current time is 00:00:10 (may refer to the time when zero-minute-ten seconds end), the statistical time is 00:00:05 (may refer to the time when zero-minute-zero-five seconds end; that is, the second preset time period is pushed back from the current time). The server 10 calculates the number of concurrencies of request messages during the periods 00:00:05-00:00: 10.
In this embodiment, the preset determination rule for determining the concurrency number may be set according to the actual situation, for example, step S220 may include: and determining the maximum number of the numbers corresponding to the multiple first preset durations as the concurrency number in the period from the counting time to the current time, or determining the average value of the total number of the message requests in the period from the counting time to the current time to the time as the concurrency number.
Specifically, for example, the first preset time period is 1 second, and the second preset time period is 5 seconds, the server 10 may obtain the number of 5 request messages in 5 seconds, and then select the maximum number from the 5 numbers to serve as the concurrency number.
Or the first preset time length is the same as the second preset time length, and is 5 seconds, and then the average value of the message request number in 5 seconds is used as the concurrency number. That is, the server 10 may obtain the total number of request messages in 5 seconds, and then divide the total number by the time 5 seconds to obtain the concurrency number.
That is, the server 10 may obtain a new concurrency number every 5 seconds by the above method, so that the time of the determined concurrency number is close to the current time, thereby improving the timeliness of the concurrency number, and the concurrency number may be used as effective data for analysis and processing by related personnel or the server 10. For example, the concurrency number may be used for pressure monitoring of the server 10, and may be used as a basis for optimization of the system framework and business process of the server 10.
Based on the above design, the server 10 may obtain the QPS value in real time in the program, and then perform different business processes according to the value, so as to prevent the service from crashing due to exceeding the load limit, and at the same time, may also be used to display the QPS value, and send an early warning prompt according to the QPS value for the service processing capability, for example, if the QPS value exceeds a preset threshold. The preset threshold may be set according to an actual situation, for example, whether the request exceeds the upper limit of the load may be determined by determining whether the QPS value of a second is greater than a threshold, and then different service logic processes may be performed according to the determination.
Fig. 4 is a block diagram of a concurrency determination apparatus 100 according to an embodiment of the present invention. The concurrency number determining apparatus 100 provided by the embodiment of the present invention may be applied to the server 10, and the concurrency number determining apparatus 100 may be configured to execute or implement each step of the concurrency number determining method, so as to solve the problem of low timeliness of the determined concurrency number in the prior art. The concurrency number determination apparatus 100 may include an obtaining unit 110 and a determining unit 120.
An obtaining unit 110, configured to obtain the number of request packets in a first preset time duration.
Optionally, the obtaining unit 110 is further configured to: acquiring a request message sent by the user terminal 20 based on the optical character recognition interface, and counting the number of the request messages in a first preset time length.
Optionally, the obtaining unit 110 is further configured to: and based on a Key-Value database, associating the current second and the preset request name as a Key, caching, and determining the number of the request messages in the current second based on the corresponding relation between the Value obtained through a preset strategy and the number of the request messages.
Optionally, the obtaining unit 110 is further configured to: and in the current second, calling a Key once when the request message is the request message corresponding to the preset request name, and performing accumulation operation on the preset initial Value to obtain the Value after the Key is called.
The determining unit 120 is configured to determine the concurrency number from the statistical time to the current time according to a preset determination rule and the number of the request messages, where a time duration between the statistical time and the current time is a second preset time duration greater than or equal to the first preset time duration.
Optionally, the concurrency number determination apparatus 100 may further include a classification unit. Before the obtaining unit 110 obtains the number of the request messages within the first preset duration, the classifying unit is configured to classify the request messages according to the request names corresponding to the request messages.
It should be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process of the concurrency number determination apparatus 100 described above may refer to the corresponding process of each step in the foregoing method, and will not be described in detail herein.
The embodiment of the invention also provides a computer readable storage medium. The readable storage medium has stored therein a computer program that, when run on a computer, causes the computer to execute the concurrency number determination method as described in the above embodiments.
From the above description of the embodiments, it is clear to those skilled in the art that the present invention can be implemented by hardware, or by software plus a necessary general hardware platform, and based on such understanding, the technical solution of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.), and includes several instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the method described in the embodiments of the present invention.
In summary, the present invention provides a concurrency number determination method, a device and a server. The method comprises the steps of obtaining the number of request messages in a first preset time length; and then according to the preset determination rule and the number of the request messages, determining the concurrency number from the counting time to the current time, so that the time of the counted concurrency number is close to the current time, and the timeliness of the concurrency number is improved. In addition, the time length between the statistical time and the current time is a second preset time length which is greater than or equal to the first preset time length, namely, a new concurrency number can be determined every other second preset time length, so that the timeliness of the determined concurrency number is improved.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, system, and method may be implemented in other ways. The apparatus, system, and method embodiments described above are illustrative only, as the flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions. In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
Alternatively, all or part of the implementation may be in software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.