Method and device for processing request

By storing the initial value of the serial number at the preset position and performing preset operations according to the threshold, the problem of processing requests taking up a large storage space in the prior art is solved, and the effect of reducing storage space is achieved.

CN112487001BActive Publication Date: 2025-05-16BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN201910860040.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-09-11
Publication Date
2025-05-16
Estimated Expiration
2039-09-11

AI Technical Summary

Technical Problem

In the prior art, the database generates a new value of the serial number by increasing the primary key ID, resulting in a large storage space occupied by processing requests.

Method used

By storing the initial value of the serial number at the preset position, obtaining the threshold value according to the preset position, and performing the preset operation according to the new value of the serial number and the size relationship of the threshold value, including sending the new value of the serial number to the client, and changing the initial value of the serial number stored in the preset position to the new value of the serial number.

Benefits of technology

Reduces the storage space occupied by processing requests, avoids storing new values ​​of all generated serial numbers in the database, and only stores new values ​​of the current serial number.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112487001B_ABST
    Figure CN112487001B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for processing a request, and relates to the field of computer technology. A specific implementation of the method includes: receiving a sequence number request sent by a client, obtaining a new value of the sequence number according to the initial value of the sequence number stored in a preset position; obtaining a threshold from the preset position; performing a preset operation according to the magnitude relationship between the new value of the sequence number and the threshold; wherein the preset operation includes sending the new value of the sequence number to the client, and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number. This implementation reduces the storage space occupied by processing requests.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for processing a request. Background Art

[0002] At present, the method for processing requests is that the server receives the serial number request sent by the client, obtains the new value of the serial number from the database, and sends the new value of the serial number to the client. The database generates the new value of the serial number by means of the primary key self-increment ID.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] Since the database generates new values ​​of the serial number by means of a primary key auto-increment ID, all new values ​​of the generated serial number are stored in the database, so processing requests takes up a large storage space. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a method and apparatus for processing a request, which can reduce the storage space occupied by the processing request.

[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for processing a request is provided.

[0007] The method for processing a request according to an embodiment of the present invention includes:

[0008] Receive a sequence number request sent by the client, and obtain a new value of the sequence number according to the initial value of the sequence number stored in a preset position;

[0009] Acquire a threshold value from the preset position;

[0010] Execute a preset operation according to the magnitude relationship between the new value of the sequence number and the threshold;

[0011] The preset operation includes sending the new value of the sequence number to the client, and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number.

[0012] In one embodiment, the threshold comprises a first threshold and a second threshold;

[0013] Before receiving the serial number request sent by the client, include:

[0014] Using a preset first value as the second threshold;

[0015] Subtracting the first value from a preset increment of the first value, and using the obtained subtrahend as the initial value of the serial number stored in the preset position;

[0016] The preset ratio is multiplied by the first value to obtain a product, and the product is rounded up to an integer, and the obtained value is used as the first threshold.

[0017] In one embodiment, performing a preset operation according to the magnitude relationship between the new value of the sequence number and the threshold value includes:

[0018] If the new value of the sequence number is less than the first threshold, executing a preset operation;

[0019] If the new value of the sequence number is greater than or equal to the first threshold value and less than the second threshold value, a preset operation is performed and the first value is modified to obtain a modified first value;

[0020] If the new value of the serial number is equal to the second threshold, the first threshold and the second threshold are updated according to the modified first value, and after the first threshold and the second threshold are updated, a preset operation is performed.

[0021] In one embodiment, modifying the first value to obtain the modified first value includes:

[0022] The first value and the increase in the first value are added together, and the obtained addend is used as the modified first value.

[0023] In one embodiment, updating the first threshold and the second threshold according to the modified first value includes:

[0024] Changing the second threshold to the modified first value;

[0025] The preset ratio is multiplied by the modified first value to obtain a product, the product is rounded up to obtain a second value, and the first threshold is changed to the second value.

[0026] In one embodiment, obtaining a new value of the sequence number according to the initial value of the sequence number stored in the preset position includes:

[0027] Reading an initial value of the serial number stored in a preset position, adding 1 to the initial value of the serial number read, to obtain a third value;

[0028] Determine whether the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position;

[0029] If yes, use the third value as the new value of the sequence number;

[0030] If not, return to read the initial value of the serial number stored in the preset position until the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position, and use the third value under the same circumstances as the new value of the serial number.

[0031] To achieve the above objective, according to another aspect of an embodiment of the present invention, a device for processing a request is provided.

[0032] The device for processing a request according to an embodiment of the present invention includes:

[0033] A first acquisition unit is used to receive a sequence number request sent by a client, and obtain a new value of the sequence number according to an initial value of the sequence number stored in a preset position;

[0034] A second acquisition unit, used to acquire a threshold value from the preset position;

[0035] A processing unit is used to perform a preset operation according to the size relationship between the new value of the sequence number and the threshold; wherein the preset operation includes sending the new value of the sequence number to the client and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number.

[0036] In one embodiment, the threshold comprises a first threshold and a second threshold;

[0037] The first acquisition unit is used for:

[0038] Before receiving the sequence number request sent by the client, using the preset first value as the second threshold;

[0039] Subtracting the first value from a preset increment of the first value, and using the obtained subtrahend as the initial value of the serial number stored in the preset position;

[0040] The preset ratio is multiplied by the first value to obtain a product, and the product is rounded up to an integer, and the obtained value is used as the first threshold.

[0041] In one embodiment, the processing unit is configured to:

[0042] If the new value of the sequence number is less than the first threshold, executing a preset operation;

[0043] If the new value of the sequence number is greater than or equal to the first threshold value and less than the second threshold value, a preset operation is performed and the first value is modified to obtain a modified first value;

[0044] If the new value of the serial number is equal to the second threshold, the first threshold and the second threshold are updated according to the modified first value, and after the first threshold and the second threshold are updated, a preset operation is performed.

[0045] In one embodiment, the processing unit is configured to:

[0046] The first value and the increase in the first value are added together, and the obtained addend is used as the modified first value.

[0047] In one embodiment, the processing unit is configured to:

[0048] Changing the second threshold to the modified first value;

[0049] The preset ratio is multiplied by the modified first value to obtain a product, the product is rounded up to obtain a second value, and the first threshold is changed to the second value.

[0050] In one embodiment, the first acquiring unit is used to:

[0051] Reading an initial value of the serial number stored in a preset position, adding 1 to the initial value of the serial number read, to obtain a third value;

[0052] Determine whether the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position;

[0053] If yes, use the third value as the new value of the sequence number;

[0054] If not, return to read the initial value of the serial number stored in the preset position until the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position, and use the third value under the same circumstances as the new value of the serial number.

[0055] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.

[0056] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the method for processing requests provided by the embodiment of the present invention.

[0057] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer readable medium is provided.

[0058] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, the method for processing a request provided by the embodiment of the present invention is implemented.

[0059] An embodiment of the above invention has the following advantages or beneficial effects: receiving a sequence number request sent by a client, obtaining a new value of the sequence number according to the initial value of the sequence number stored in a preset position; obtaining a threshold from the preset position; performing a preset operation according to the magnitude relationship between the new value of the sequence number and the threshold; wherein the preset operation includes sending the new value of the sequence number to the client, and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number. By not storing all the new values ​​of the sequence number obtained, only the new value of the sequence number currently obtained is stored, thereby reducing the storage space occupied by processing requests.

[0060] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0062] Figure 1 is a schematic diagram of the main flow of a method for processing a request according to an embodiment of the present invention;

[0063] Figure 2 is a schematic diagram of an application scenario of a method for processing a request according to an embodiment of the present invention;

[0064] Figure 3 is another application scenario schematic diagram of the method for processing a request according to an embodiment of the present invention;

[0065] Figure 4 is a schematic diagram of main units of an apparatus for processing requests according to an embodiment of the present invention;

[0066] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0067] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0068] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0069] It should be pointed out that the embodiments of the present invention and the features in the embodiments may be combined with each other if there is no conflict.

[0070] Existing methods for processing requests include: a method for processing requests based on a redis database, a method for processing requests based on a mysql database, a method for processing requests based on a universally unique identifier (Universally Unique Identifier, referred to as UUID), and a method for processing requests based on a snowflake algorithm.

[0071] The method for processing requests based on the redis database is similar to the method for processing requests based on the mysql database, specifically: generating a new value of the serial number in the redis database or the mysql database. Due to factors such as interface configuration, the client cannot directly access the database. The client needs to obtain the new value of the serial number from the redis database or the mysql database through the server in the form of a network. As a result, the server's request processing is limited by the server's io interface. In addition, after the server crashes or restarts, the server cannot obtain the new value of the serial number from the redis database. This is because the redis database generates the new value of the serial number by means of an auto-increment command, and all the new values ​​of the generated serial number are not stored. The server can obtain the new value of the serial number from the mysql database. This is because the mysql database generates the new value of the serial number by means of a primary key auto-increment ID, and all the new values ​​of the generated serial number are stored in the database, but there is a problem that processing requests takes up a large storage space.

[0072] Although the method of processing requests based on a universal unique identifier can ensure the uniqueness of the new value of the serial number, the new value of the serial number is a string type, and the indexing performance of a string is inferior to that of a numeric value. In addition, the new value of the serial number is not an auto-incrementing serial number, which is not conducive to client use.

[0073] The method for processing requests based on the snowflake algorithm adds information such as timestamp, region number, and machine number to the new value of the serial number to ensure the uniqueness of the new value of the serial number. As a result, the number of digits of the new value of the serial number is very long, which occupies a large storage space and is not conducive to client use.

[0074] In order to solve the problems existing in the prior art, the embodiment of the present invention provides a method for processing a request, such as Figure 1 As shown, the method includes:

[0075] Step S101: receiving a sequence number request sent by a client, and obtaining a new value of the sequence number according to an initial value of the sequence number stored in a preset position.

[0076] Step S102: Acquire a threshold from the preset position.

[0077] Step S103, performing a preset operation according to the size relationship between the new value of the sequence number and the threshold; wherein the preset operation includes sending the new value of the sequence number to the client, and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number.

[0078] In this embodiment, the preset location may be a server memory. The new value of the sequence number may be a negative integer or a natural number, etc. The threshold may include a first threshold and a second threshold, and the second threshold is greater than the first threshold. There are only three situations in which the new value of the sequence number is less than the first threshold; the second situation is that the new value of the sequence number is greater than or equal to the first threshold and less than the second threshold; the third situation is that the new value of the sequence number is equal to the second threshold. In addition, the specific implementation methods of steps S101 to S103 are described in detail below and will not be repeated here.

[0079] In the embodiment of the present invention, the threshold includes a first threshold and a second threshold;

[0080] Before step S101, the following steps are included:

[0081] Using a preset first value as the second threshold;

[0082] Subtracting the first value from a preset increment of the first value, and using the obtained subtrahend as the initial value of the serial number stored in the preset position;

[0083] The preset ratio is multiplied by the first value to obtain a product, and the product is rounded up to an integer, and the obtained value is used as the first threshold.

[0084] In this embodiment, when it is implemented specifically, Figure 2 As shown:

[0085] Step S201: The server loads a configuration file according to the path of the configuration file, where the configuration file includes a first value, an increase of the first value, and a preset ratio.

[0086] Step S202: The server memory obtains a first value, an increase of the first value, and a preset ratio from a configuration file.

[0087] Step S203: The server memory subtracts the first value from the increase in the first value, and the obtained subtrahend is used as the initial value of the serial number stored in the server memory.

[0088] Step S204: The server memory uses the first value as the second threshold.

[0089] Step S205: The server memory multiplies the preset ratio and the first value to obtain a product, and rounds up the product to obtain a value as the first threshold.

[0090] It should be understood that, without affecting the embodiments of the present invention, those skilled in the art can flexibly set the first threshold, but the first threshold is greater than the calculated initial value of the sequence number stored in the server memory and less than the second threshold. For example, in another embodiment, the difference between the first value and a preset value (the preset value is any positive integer less than the first value) is used as the first threshold.

[0091] In this embodiment, the initial value and the second threshold value of the sequence number stored in the preset position are determined by presetting the first value and the increase of the first value, so that the new value of the sequence number gradually changes from the initial value of the sequence number to the second threshold value; the first value is continuously modified according to the increase of the first value, thereby continuously updating the second threshold value, and new values ​​of the sequence number will be continuously generated. Since the storage space occupied by the first value is significantly less than the storage space occupied by all new values ​​of the sequence number, the storage space occupied by processing requests is further reduced. After a crash or restart, modifying the first value generates a new value of the sequence number, reducing the problem of being unable to process requests after a crash or restart.

[0092] In the embodiment of the present invention, Figure 3 As shown, a preset operation is performed according to the relationship between the new value of the sequence number and the threshold, including:

[0093] Step S301: If the new value of the sequence number is less than the first threshold, perform a preset operation;

[0094] Step S302: If the new value of the sequence number is greater than or equal to the first threshold value and less than the second threshold value, a preset operation is performed and the first value is modified to obtain a modified first value;

[0095] Step S303: If the new value of the serial number is equal to the second threshold, the first threshold and the second threshold are updated according to the modified first value, and after the first threshold and the second threshold are updated, a preset operation is performed.

[0096] In this embodiment, it should be understood that, when the first threshold and the second threshold are not updated, and the new value of the sequence number is greater than or equal to the first threshold and less than the second threshold, the number of times the first value is modified can be the same as the difference between the second threshold and the first threshold, or can be one, or can be any positive integer from one to the difference. Preferably, the number of times the first value is modified is one, so that each value can be used as a new value of the sequence number, and there will be no situation where some values ​​cannot be used as new values ​​of the sequence number, and the number of new values ​​of the generated sequence number is large, and the number of processed requests is large.

[0097] When the first threshold and the second threshold are not updated, the method of making the modification times of the first value 1 includes: if the new value of the serial number is equal to the first threshold, modifying the first value to obtain the modified first value; if the new value of the serial number is greater than the first threshold and less than the second threshold, not modifying the first value.

[0098] It should be noted that if the new value of the serial number is equal to the second threshold, the first threshold and the second threshold must be updated before the preset operation can be performed. The reason is explained below with a specific example: the first threshold is 8, the second threshold is 10, and the new value of the serial number is 10. If the second threshold is changed from 10 to 20, and the first threshold is changed from 8 to 18, after the first threshold and the second threshold are updated, the initial value of the serial number stored in the preset position is changed to the new value of the serial number 10, and a serial number request is received, then according to the initial value 10 of the serial number stored in the preset position, another new value 11 of the serial number can be obtained. The new value 11 of the other serial number is less than the first threshold 18. There is a solution, that is, to execute the preset operation, thereby continuously processing requests. If the initial value of the sequence number stored in the preset position is first changed to the new value 10 of the sequence number, and then the first threshold and the second threshold are updated, and the first threshold and the second threshold have not been completely updated, and a sequence number request is received, then the initial value of the sequence number stored in the preset position is 10, and the new value 11 of another sequence number can be obtained based on 10, and the new value 11 of another sequence number is greater than the second threshold 10 (the second threshold has not been completely updated, the second threshold has not been changed, and it is still 10), but there is no solution to the new value 11 of another sequence number being greater than the second threshold, and therefore, the received sequence number request cannot be processed. Therefore, the new value of the sequence number is not greater than the second threshold.

[0099] In addition, since the threads for modifying the first value, updating the first threshold and updating the second threshold are asynchronous with the thread for processing the request, when the new value of the sequence number is equal to the second threshold, the first threshold and the second threshold are updated. Furthermore, step S301, step S302 and step S303 are in parallel relationship.

[0100] In this embodiment, when the new value of the sequence number is greater than or equal to the first threshold value and less than the second threshold value, the first value is modified to give an alarm; when the new value of the sequence number is equal to the second threshold value, the first threshold value and the second threshold value are updated according to the modified first value, so that new values ​​of the sequence number can continue to be generated. Since the storage space occupied by the first value is significantly less than the storage space occupied by all new values ​​of the sequence number, the storage space occupied by the processing request is further reduced.

[0101] In the embodiment of the present invention, modifying the first value to obtain the modified first value includes:

[0102] The first value and the increase in the first value are added together, and the obtained addend is used as the modified first value.

[0103] In this embodiment, by modifying the first value, the first threshold and the second threshold are updated, and then new values ​​of the sequence number can be continuously generated. Since the storage space occupied by the first value is significantly less than the storage space occupied by all new values ​​of the sequence number, the storage space occupied by the processing request is further reduced.

[0104] In the embodiment of the present invention, updating the first threshold and the second threshold according to the modified first value includes:

[0105] Changing the second threshold to the modified first value;

[0106] The preset ratio is multiplied by the modified first value to obtain a product, the product is rounded up to obtain a second value, and the first threshold is changed to the second value.

[0107] It should be understood that those skilled in the art can flexibly update the first threshold value without affecting the embodiments of the present invention. For example, in another embodiment, the difference between the modified first value and the preset value is used as the second value, and the first threshold value is changed to the second value.

[0108] In this embodiment, by modifying the first value, the second threshold is updated to the modified first value, and the first threshold is updated to the second value, and then new values ​​of the sequence number can be continuously generated. Since the storage space occupied by the first value is significantly less than the storage space occupied by all new values ​​of the sequence number, the storage space occupied by the processing request is further reduced.

[0109] In an embodiment of the present invention, obtaining a new value of the sequence number according to the initial value of the sequence number stored in the preset position includes:

[0110] Reading an initial value of the serial number stored in a preset position, adding 1 to the initial value of the serial number read, to obtain a third value;

[0111] Determine whether the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position;

[0112] If yes, use the third value as the new value of the sequence number;

[0113] If not, return to read the initial value of the serial number stored in the preset position until the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position, and use the third value under the same circumstances as the new value of the serial number.

[0114] In this embodiment, it should be understood that if the first thread and the second thread of the server read the initial value of the sequence number stored in the preset position at the same time, the initial value of the sequence number read by the first thread and the second thread is the same. The first thread has a fast processing speed. When the second thread adds 1 to the initial value 2 of the sequence number read to obtain 3, the first thread has already added 1 to the initial value 2 of the sequence number read to obtain 3. The initial value 2 of the sequence number read is the same as the initial value 2 of the sequence number currently stored in the preset position. 3 is used as the new value of the sequence number. The new value 3 of the sequence number is less than the first threshold value, and 3 is sent to the client, and the initial value 2 of the sequence number stored in the preset position is changed to 3. In this case, the initial value of the serial number currently stored in the preset position is 3, and the initial value 2 of the serial number read by the second thread is different from the initial value 3 of the serial number currently stored in the preset position. The second thread reads the initial value 3 of the serial number stored in the preset position again, adds 1 to the read initial value 3 of the serial number, and obtains 4. The initial value 3 of the serial number read by the second thread is the same as the initial value 3 of the serial number currently stored in the preset position. 4 is used as the new value of the serial number. The new value 4 of the serial number is less than the first threshold, and 4 is sent to the client, and the initial value 3 of the serial number stored in the preset position is changed to 4.

[0115] It should be noted that the new value of the sequence number is obtained according to the initial value of the sequence number stored in the preset position through the Compare and Swap (CAS) algorithm, thereby improving the service interface performance and the performance of processing requests by using a lock-free method.

[0116] In this embodiment, the initial value of the sequence number stored in the preset position is read, and the initial value of the read sequence number is added by 1 to obtain a third value, and the new value of the sequence number is obtained according to the third value. Therefore, the new value of the sequence number is a numerical type. Compared with the string type or the information type with timestamp, the new value of the sequence number has a shorter number of bits and occupies less storage space, further reducing the storage space occupied by the processing request. In addition, the index performance of the numerical value is better than the index performance of the string, and the new value of the sequence number is a self-incrementing sequence number, which is convenient for the client to use.

[0117] In order to solve the problems existing in the prior art, another embodiment of the present invention provides a method for processing a request, which is applied to a server, and the method includes:

[0118] The first step is to set the first value in the configuration file to 10 after the server is turned on, the increase of the first value to 10, and the preset ratio to 0.8.

[0119] In this step, the configuration file can be set up on the server.

[0120] In the second step, the server memory obtains the first value 10, the increase of the first value 10 and the preset ratio 0.8 from the configuration file.

[0121] In the third step, the server memory uses the first value 10 as the second threshold; subtracts the first value 10 from the increase of the first value 10, and the resulting subtrahend 0 is used as the initial value 0 of the serial number stored in the server memory; multiplies the preset ratio 0.8 by the first value 10 to obtain the product 8, and rounds up the product 8 to obtain the value 8 as the first threshold.

[0122] In this step, it should be noted that since the initial value, the first threshold and the second threshold of the sequence number are frequently used, if the initial value, the first threshold and the second threshold of the sequence number are stored in the configuration file, frequent reading of the configuration file will affect the performance of the server in processing requests. Therefore, the initial value, the first threshold and the second threshold of the sequence number are stored in the server memory.

[0123] In the fourth step, the current thread of the server receives the first sequence number request sent by the client.

[0124] In the fifth step, the current thread of the server reads the initial value 0 of the serial number stored in the server memory, saves 0 to the cache of the current thread of the server, adds 1 to 0, and obtains the third value 1.

[0125] In the sixth step, the current thread of the server determines whether the initial value 0 of the read serial number is the same as the initial value of the serial number currently stored in the server memory; if so, the third value 1 is used as the new value of the serial number; if not, return to read the initial value of the serial number stored in the server memory, until the initial value of the read serial number is the same as the initial value of the serial number currently stored in the server memory, and the third value under the same situation is used as the new value of the serial number.

[0126] In the seventh step, the current thread of the server determines that the new value 1 of the sequence number is less than the first threshold 8, sends the new value 1 of the sequence number to the client, and changes the initial value of the sequence number stored in the server memory to the new value 1 of the sequence number.

[0127] In this step, during specific implementation, the current thread of the server reads the first threshold 8 and the second threshold 10 from the server memory, and determines that the new value 1 of the sequence number is less than the first threshold 8.

[0128] In step 8, if the current thread of the server receives the eighth sequence number request sent by the client, it determines the new value of the sequence number to be 8 according to the process described in steps 5 and 6. The current thread of the server determines that the new value of the sequence number 8 is equal to the first threshold 8 and less than the second threshold 10, sends the new value of the sequence number 8 to the client, changes the initial value of the sequence number stored in the server memory to the new value of the sequence number 8, and notifies another thread to modify the first value in the configuration file, specifically: add the first value 10 and the increase of the first value 10, and the obtained addend 20 is used as the modified first value 20, and 10 is replaced by 20.

[0129] In this step, the order of receiving the first sequence number request to the eighth sequence number request is from the front to the back. The clients sending these eight sequence number requests may be the same client or different clients.

[0130] It should be understood that, since another thread is used to modify the first value in the configuration file, the other thread does not block the current thread of the server.

[0131] In step 9, if the current thread of the server receives the ninth sequence number request sent by the client, it determines the new value of the sequence number to be 9 according to the process described in steps 5 and 6. The current thread of the server determines that the new value of the sequence number 9 is greater than the first threshold 8 and less than the second threshold 10, sends the new value of the sequence number 9 to the client, and changes the initial value of the sequence number stored in the server memory to the new value of the sequence number 9.

[0132] In the tenth step, if the current thread of the server receives the tenth sequence number request sent by the client, it determines that the new value of the sequence number is 10 according to the process described in the fifth and sixth steps. The current thread of the server determines that the new value of the sequence number 10 is equal to the second threshold value 10, and notifies another thread to load the modified first value 20 into the server memory. The server memory updates the first threshold and the second threshold according to the modified first value 20, specifically: the second threshold is changed to the modified first value 20; the preset ratio 0.8 is multiplied by the modified first value 20 to obtain the product 16, the product 16 is rounded up to obtain the second value 16, and the first threshold is changed to the second value 16. After the current thread of the server determines that the server memory has updated the first threshold and the second threshold, it sends the new value 10 of the sequence number to the client, and changes the initial value of the sequence number stored in the server memory to the new value 10 of the sequence number.

[0133] In the eleventh step, after the current thread of the server changes the initial value of the serial number stored in the server memory to 10, the server crashes or restarts. The initial value 10 of the serial number stored in the server memory may be lost, but the first value in the configuration file is not affected by the server crash or restart. The first value 20, the increase of the first value 10, and the preset ratio 0.8 in the configuration file will not be lost. After the server is determined to be down or restarted, the server modifies the first value in the configuration file, specifically: add the first value 20 and the increase of the first value 10, and the obtained addend 30 is used as the modified first value 30, and 20 is replaced by 30. The server loads the first value 30 in the configuration file into the server memory. The server memory calculates the second threshold 30, the initial value 20 of the serial number stored in the server memory, and the first threshold 24 according to the process described in the third step.

[0134] In step 12, after the current thread of the server receives the eleventh sequence number request sent by the client, the way in which the current thread of the server processes the request is the same as the process described after step 5 (including step 5). The only difference is that the second threshold, the first threshold and the initial value of the sequence number stored in the server memory are different, which will not be repeated here.

[0135] It should be understood that the method for processing requests provided in the embodiment of the present invention can be applied in a distributed system, and the new value of the sequence number is used to ensure the uniqueness of the service ID.

[0136] It should be noted that when the server is restarted or down, the first value in the configuration file is modified, and the server memory calculates the initial value of the serial number stored in the server memory according to the modified first value; when the server is running normally, the initial value of the serial number stored in the server memory is continuously changed with the new value of the serial number. In addition, there are only two situations in which the first value in the configuration file is modified, one is that the server is restarted or down, and the other is that the new value of the serial number is greater than or equal to the first threshold and less than the second threshold.

[0137] Combination of the above Figure 1-Figure 3 The method of processing requests is explained below. Figure 4 The device that processes the request is described.

[0138] In order to solve the problems existing in the prior art, an embodiment of the present invention provides a device for processing a request, such as Figure 4 As shown, the device comprises:

[0139] The first obtaining unit 401 is used to receive a sequence number request sent by a client, and obtain a new value of the sequence number according to an initial value of the sequence number stored in a preset position.

[0140] The second acquiring unit 402 is configured to acquire a threshold value from the preset position.

[0141] The processing unit 403 is used to perform a preset operation according to the size relationship between the new value of the sequence number and the threshold; wherein the preset operation includes sending the new value of the sequence number to the client and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number.

[0142] In the embodiment of the present invention, the threshold includes a first threshold and a second threshold;

[0143] The first acquiring unit 401 is used for:

[0144] Before receiving the sequence number request sent by the client, using the preset first value as the second threshold;

[0145] Subtracting the first value from a preset increment of the first value, and using the obtained subtrahend as the initial value of the serial number stored in the preset position;

[0146] The preset ratio is multiplied by the first value to obtain a product, and the product is rounded up to an integer, and the obtained value is used as the first threshold.

[0147] In the embodiment of the present invention, the processing unit 403 is used to:

[0148] If the new value of the sequence number is less than the first threshold, executing a preset operation;

[0149] If the new value of the sequence number is greater than or equal to the first threshold value and less than the second threshold value, a preset operation is performed and the first value is modified to obtain a modified first value;

[0150] If the new value of the serial number is equal to the second threshold, the first threshold and the second threshold are updated according to the modified first value, and after the first threshold and the second threshold are updated, a preset operation is performed.

[0151] In the embodiment of the present invention, the processing unit 403 is used to:

[0152] The first value and the increase in the first value are added together, and the obtained addend is used as the modified first value.

[0153] In the embodiment of the present invention, the processing unit 403 is used to:

[0154] Changing the second threshold to the modified first value;

[0155] The preset ratio is multiplied by the modified first value to obtain a product, the product is rounded up to obtain a second value, and the first threshold is changed to the second value.

[0156] In the embodiment of the present invention, the first acquiring unit 401 is used to:

[0157] Reading an initial value of the serial number stored in a preset position, adding 1 to the initial value of the serial number read, to obtain a third value;

[0158] Determine whether the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position;

[0159] If yes, use the third value as the new value of the sequence number;

[0160] If not, return to read the initial value of the serial number stored in the preset position until the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position, and use the third value under the same circumstances as the new value of the serial number.

[0161] It should be understood that the functions performed by the various components of the apparatus for processing requests provided in the embodiment of the present invention have been introduced in detail in the method for processing requests in the above embodiment, and will not be repeated here.

[0162] Figure 5 An exemplary system architecture 500 is shown to which the method for processing a request or the apparatus for processing a request according to the embodiments of the present invention can be applied.

[0163] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0164] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).

[0165] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0166] The server 505 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 501, 502, and 503. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.

[0167] It should be noted that the method for processing requests provided in the embodiment of the present invention is generally executed by the server 505 , and accordingly, the device for processing requests is generally set in the server 505 .

[0168] It should be understood that Figure 5The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0169] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0170] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0171] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0172] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.

[0173] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0174] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a unit, a program segment, or a part of a code, and the above-mentioned unit, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0175] The units involved in the embodiments of the present invention may be implemented by software or hardware. The units described may also be set in a processor, for example, it may be described as: a processor includes a first acquisition unit, a second acquisition unit and a processing unit. The names of these units do not constitute a limitation on the units themselves in some cases, for example, the second acquisition unit may also be described as "a unit for acquiring a threshold value from the preset position".

[0176] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: receiving a serial number request sent by a client, obtaining a new value of the serial number according to the initial value of the serial number stored in a preset position; obtaining a threshold from the preset position; performing a preset operation according to the relationship between the new value of the serial number and the threshold; wherein the preset operation includes sending the new value of the serial number to the client, and changing the initial value of the serial number stored in the preset position to the new value of the serial number.

[0177] According to the technical solution of the embodiment of the present invention, a sequence number request sent by a client is received, and a new value of the sequence number is obtained according to the initial value of the sequence number stored in a preset position; a threshold is obtained from the preset position; and a preset operation is performed according to the magnitude relationship between the new value of the sequence number and the threshold; wherein the preset operation includes sending the new value of the sequence number to the client, and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number. By not storing all the new values ​​of the sequence number obtained, but only storing the new value of the sequence number currently obtained, the storage space occupied by the processing request is reduced.

[0178] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for processing a request, characterized in that: include: Using a preset first value as a second threshold; Subtracting the first value from a preset increment of the first value, and using the obtained subtrahend as the initial value of the serial number stored in the preset position; Multiplying the preset ratio by the first value to obtain a product, rounding up the product, and using the obtained value as the first threshold; Receive a sequence number request sent by the client, and obtain a new value of the sequence number according to the initial value of the sequence number stored in a preset position; Acquire a threshold from the preset position; the threshold includes a first threshold and a second threshold; Execute a preset operation according to the magnitude relationship between the new value of the sequence number and the threshold; The preset operation includes sending the new value of the sequence number to the client, and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number.

2. The method according to claim 1, characterized in that Executing a preset operation according to the magnitude relationship between the new value of the sequence number and the threshold value, including: If the new value of the sequence number is less than the first threshold, executing a preset operation; If the new value of the sequence number is greater than or equal to the first threshold value and less than the second threshold value, a preset operation is performed and the first value is modified to obtain a modified first value; If the new value of the serial number is equal to the second threshold, the first threshold and the second threshold are updated according to the modified first value, and after the first threshold and the second threshold are updated, a preset operation is performed.

3. The method according to claim 2, characterized in that Modifying the first value to obtain the modified first value includes: The first value and the increase in the first value are added together, and the obtained addend is used as the modified first value.

4. The method according to claim 2, characterized in that: Updating the first threshold and the second threshold according to the modified first value includes: Changing the second threshold to the modified first value; The preset ratio is multiplied by the modified first value to obtain a product, the product is rounded up to obtain a second value, and the first threshold is changed to the second value.

5. The method according to claim 1, characterized in that: The new value of the serial number is obtained according to the initial value of the serial number stored in the preset position, including: Reading an initial value of the serial number stored in a preset position, adding 1 to the initial value of the serial number read, to obtain a third value; Determine whether the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position; If yes, use the third value as the new value of the sequence number; If not, return to read the initial value of the serial number stored in the preset position until the initial value of the serial number read is the same as the initial value of the serial number currently stored in the preset position, and use the third value under the same circumstances as the new value of the serial number.

6. A device for processing a request, characterized in that: include: A first acquiring unit, configured to use a preset first value as a second threshold; Subtracting the first value from a preset increment of the first value, and using the obtained subtrahend as the initial value of the serial number stored in the preset position; Multiplying the preset ratio by the first value to obtain a product, rounding up the product, and using the obtained value as the first threshold; Receive a sequence number request sent by the client, and obtain a new value of the sequence number according to the initial value of the sequence number stored in a preset position; A second acquisition unit, configured to acquire a threshold from the preset position; the threshold includes a first threshold and a second threshold; A processing unit is used to perform a preset operation according to the size relationship between the new value of the sequence number and the threshold; wherein the preset operation includes sending the new value of the sequence number to the client and changing the initial value of the sequence number stored in the preset position to the new value of the sequence number.

7. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.

8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Service ID generating method, device and system

    CN106911780A