CN111552577A - Method for preventing invalid request from occurring, storage medium - Google Patents

Method for preventing invalid request from occurring, storage medium Download PDF

Info

Publication number
CN111552577A
CN111552577A CN202010212679.6A CN202010212679A CN111552577A CN 111552577 A CN111552577 A CN 111552577A CN 202010212679 A CN202010212679 A CN 202010212679A CN 111552577 A CN111552577 A CN 111552577A
Authority
CN
China
Prior art keywords
request
time
server
overtime
shared object
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010212679.6A
Other languages
Chinese (zh)
Other versions
CN111552577B (en
Inventor
刘德建
林伟
郭玉湖
陈宏�
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujian Tianquan Educational Technology Ltd
Original Assignee
Fujian Tianquan Educational Technology Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujian Tianquan Educational Technology Ltd filed Critical Fujian Tianquan Educational Technology Ltd
Priority to CN202010212679.6A priority Critical patent/CN111552577B/en
Publication of CN111552577A publication Critical patent/CN111552577A/en
Application granted granted Critical
Publication of CN111552577B publication Critical patent/CN111552577B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0751Error or fault detection not based on redundancy
    • G06F11/0754Error or fault detection not based on redundancy by exceeding limits
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/541Client-server

Abstract

The invention provides a method for preventing invalid requests from occurring and a storage medium, wherein the method comprises the following steps: the client sends a request carrying the overtime to the server; the server side creates a shared object corresponding to the request and sets the overtime time of the request in the shared object; recording the execution time of the server for calling each micro-service interface calling method according to the request; and if the request is judged to be overtime according to the record and the overtime time in the shared object, the server stops processing the request. The invention can effectively prevent the occurrence of micro-service invalid requests, thereby improving the efficiency and the usability of the system; and has the advantages of simple and convenient implementation mode, easy implementation, remarkable effect and the like.

Description

Method for preventing invalid request from occurring, storage medium
Technical Field
The invention relates to the field of micro service interface calling, in particular to a method and a storage medium for preventing invalid requests from occurring.
Background
Today, the mobile internet is developed vigorously to develop various system applications, and many systems have various data interactions with other systems. The data interaction mode is various: performing data access through an interface; directly performing interactive access through a database; messaging through MQs, etc. The method for calling the interface to perform data interaction in the http protocol or the RPC and other modes which are frequently used at present is the most common data interaction mode in the current internet scene. We often refer to the way microservice calls use this model. By using the method, multi-system data interaction can be rapidly carried out, and the efficiency is improved.
However, the interface calling method using the micro service has a problem of timeout due to the influence of various factors such as complicated network conditions and unstable counterpart systems. A timeout time is set when a client calls a certain interface of a server; meanwhile, the interior of the interface of the server side can call a plurality of micro-service interfaces, and the problem does not exist under the condition that the services are normal. However, if the interface for the server to invoke a particular microservice times out, there may be a problem with invalid requests. For example, the timeout time for the client to call the server interface is set to 30 seconds, and the server interface calls 4 microservice interfaces in sequence besides its own business logic. When the second interface is called in sequence, the total time has exceeded 30 seconds, and the client will disconnect due to a timeout. At this time, the inside of the request of the server is still executed continuously, and at this time, the third and fourth microservice interfaces are called again in sequence, and are changed into invalid requests, that is, the execution is successful, and the client cannot be used. In such a scenario of invoking the micro-service interface, when a bottleneck exists in an interface, or the pressure is too high, or the network is not good, or the resources are insufficient, the time consumption of the micro-service request is increased, which may cause the increase of the invalid request.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: a method and a storage medium for preventing invalid requests are provided, which can improve system efficiency and usability.
In order to solve the technical problems, the invention adopts the technical scheme that:
a method of preventing the occurrence of invalid requests, comprising:
the client sends a request carrying the overtime to the server;
the server side creates a shared object corresponding to the request and sets the overtime time of the request in the shared object;
recording the execution time of the server for calling each micro-service interface calling method according to the request;
and if the request is judged to be overtime according to the record and the overtime time in the shared object, the server stops processing the request.
The invention provides another technical scheme as follows:
a computer-readable storage medium, having stored thereon a computer program enabling, when executed by a processor, to carry out the steps involved in a method of preventing invalidating requests as described above.
The invention has the beneficial effects that: the overtime time of the request is transmitted by the client, the time consumed by the micro-service interface called by the server for processing the request is calculated in the server, and if the total overtime time is exceeded, the subsequent operation of the request is stopped, so that the invalid request of the micro-service is solved, and the efficiency and the usability of the system are greatly improved.
Drawings
FIG. 1 is a flowchart illustrating a method for preventing invalid requests according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a method for preventing an invalid request according to an embodiment of the present invention.
Detailed Description
In order to explain technical contents, achieved objects, and effects of the present invention in detail, the following description is made with reference to the accompanying drawings in combination with the embodiments.
The most key concept of the invention is as follows: the overtime time of the request is transmitted by the client, the time consumed by the micro-service interface called by the server for processing the request is calculated in the server, and if the total overtime time is exceeded, the subsequent operation of the request is stopped, so that the invalid request is avoided.
Referring to fig. 1 and fig. 2, the present invention provides a method for preventing an invalid request from occurring, including:
the client sends a request carrying the overtime to the server;
the server side creates a shared object corresponding to the request and sets the overtime time of the request in the shared object;
recording the execution time of the server for calling each micro-service interface calling method according to the request;
and if the request is judged to be overtime according to the record and the overtime time in the shared object, the server stops processing the request.
From the above description, the beneficial effects of the present invention are: by a method for calculating the request time, the client transmits the overtime time, the time consumption calculation of the micro-service interface is carried out in the server, and when the time consumption of the internal calling interface of each micro-service exceeds the total overtime time transmitted by the client, the subsequent operation of the interface is stopped, so that the invalid request of the micro-service is solved, and the efficiency and the availability of the system are greatly improved.
Further, the recording server calls the execution time of each micro service interface calling method according to the request, and before, the method further includes:
the method for calling the configuration micro-service interface uses a preset suffix name;
acquiring the calling time and the ending time of each micro service interface calling method by intercepting the micro service interface calling method with the suffix name as the preset suffix name;
and acquiring and recording the execution time of the calling method of each micro service interface according to the calling time and the ending time.
According to the description, the called micro-service interface is accurately and comprehensively acquired in an interception mode for time-consuming monitoring through the suffix name of the unified micro-service interface calling method.
Further, if it is determined that the request has timed out according to the record and the timeout time in the shared object, specifically:
and if the value obtained by subtracting the execution time of each micro service interface calling method from the overtime time in the shared object is less than or equal to 0, judging that the request is overtime.
From the above description, it can be seen that, after the total time consumption of the internal call interfaces of each microservice is monitored and the total timeout time is reached, the determination result is immediately obtained, and the occurrence of invalid requests is prevented.
Further, the server creates a shared object corresponding to the request, and sets the timeout time of the request, specifically:
the server analyzes the request through a filter to obtain request parameters including the overtime time;
and the server side creates a shared object corresponding to the request and sets the request parameters in the shared object.
From the above description, by setting a uniform filter, it is achieved to efficiently parse each request, and obtain request parameters, especially the total timeout time of the request interface.
The invention provides another technical scheme as follows:
a computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, is able to carry out the following method of preventing an invalid request from occurring:
the client sends a request carrying the overtime to the server;
the server side creates a shared object corresponding to the request and sets the overtime time of the request in the shared object;
recording the execution time of the server for calling each micro-service interface calling method according to the request;
and if the request is judged to be overtime according to the record and the overtime time in the shared object, the server stops processing the request.
Further, the recording server calls the execution time of each micro service interface calling method according to the request, and before, the method further includes:
the method for calling the configuration micro-service interface uses a preset suffix name;
acquiring the calling time and the ending time of each micro service interface calling method by intercepting the micro service interface calling method with the suffix name as the preset suffix name;
and acquiring and recording the execution time of the calling method of each micro service interface according to the calling time and the ending time.
Further, if it is determined that the request has timed out according to the record and the timeout time in the shared object, specifically:
and if the value obtained by subtracting the execution time of each micro service interface calling method from the overtime time in the shared object is less than or equal to 0, judging that the request is overtime.
Further, the server creates a shared object corresponding to the request, and sets the timeout time of the request, specifically:
the server analyzes the request through a filter to obtain request parameters including the overtime time;
and the server side creates a shared object corresponding to the request and sets the request parameters in the shared object.
As can be understood from the above description, those skilled in the art can understand that all or part of the processes in the above technical solutions can be implemented by instructing related hardware through a computer program, where the program can be stored in a computer-readable storage medium, and when executed, the program can include the processes of the above methods. The program can also achieve advantageous effects corresponding to the respective methods after being executed by a processor.
The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
Example one
Referring to fig. 2, the present embodiment provides a method for effectively preventing an invalid request from occurring in a request processing process, including the following steps:
s1: and configuring all micro service interface calling methods to use preset unified suffix names.
The method names after the suffix name are unified, such as getXXXPAy, setXXXPAy, etc., and the suffix "proxy" is uniformly added.
S2: the client sends a request carrying the timeout time to the server.
Specifically, when the client calls the interface of the server, one more parameter needs to be transferred: the timeout time of the request. The value of the parameter directly corresponds to the total timeout time for the client to call the interface.
S3: the server analyzes the request through the filter, and creates a shared object corresponding to the request to store and analyze all the parameters including the timeout time.
Specifically, the server needs to set a uniform filter, and the main function of the filter is to analyze parameters carried by each request sent by the client, particularly the timeout time of the interface. Meanwhile, a shared object, such as a threaded local object, is created for the request, and all request parameters and timeout time obtained by analyzing the request are set in the object, so that the use of subsequent programs is facilitated. Wherein, the ThreadLocal indicates that the requesting thread can share the data in the ThreadLocal.
S4: and recording the execution time of the server for calling each micro-service interface calling method according to the request.
Specifically, the calling time and the ending time of each called micro service interface calling method can be obtained by intercepting the micro service interface calling method with the suffix name as the preset uniform suffix name; and then acquiring and recording the execution time of the calling method of each micro service interface according to the acquired calling time and the acquired ending time.
The server is assumed to be written and developed by using JAVA language. Then, an intercepting tangent plane may be set in this step, and the tangent plane is implemented through a spring AOP mechanism, and the main implementation functions of the tangent plane are as follows: unifying a micro service interface calling method with a proxy suffix; after intercepting the method, executing micro service interface call related to the method, and recording call (starting) time; when the micro service interface is successfully called or fails to be called or the micro service interface is timed out (namely the calling is finished), the execution time is obtained.
S5: and monitoring whether the total time consumption of calling each micro-service interface exceeds the total time-out time of the request transmitted by the client according to the record and the time-out time in the shared object, and if the request is judged to be time-out, stopping processing the request by the server.
Specifically, the timeout time in the ThreadLocal object is deducted by the execution time of the interface (including the execution time of all micro-service interfaces), and if the remaining time is greater than 0, the subsequent interface call can be continued; if the remaining time is less than 0, it indicates that the time spent by the request exceeds the timeout time of the client, the client has disconnected, at this time, the processing of the remaining other micro-service interfaces is already an invalid request, at this time, the continued operation of the interface can be stopped, and the return is directly finished.
Such as: the aggregation interface of a certain gateway can call a, b, c and d4 micro service interfaces inside, when the total calling time when executing the a and b micro service interfaces exceeds the timeout time defined by the client, the client has already broken the request link because of timeout, the subsequent c and d micro service interfaces of the current request can not request any more, even if requesting an invalid request.
By the method, the invalid request of the micro service can be solved, and the efficiency and the availability of the system are greatly improved.
Example two
This embodiment provides a specific application scenario corresponding to the first embodiment:
assuming that the client calls an aggregation interface of the server, and the timeout client _ timeout is set to 30 seconds, the aggregation interface calls interfaces a, b, c, and d of 4 microservices inside.
When the client requests the aggregation interface from the server, the client _ timeout is transferred to be 30. The server filter sets the time to the thread sharing variable. When the micro service method taking Proxy as suffix is called inside the aggregation interface every time, the program can automatically deduct the time consumed by the current corresponding micro service interface from the thread. For example, the microservice interface a takes 10 seconds, the microservice interface b takes 25 seconds, and after the b interface call is finished, the total consumed time of the two interfaces, namely the a interface and the b interface, already exceeds the client _ timeout in the local. At this time, the program stops the continuous operation of the interface, and the c and d interfaces of the microservice do not need to be called again, because the time of the client is overtime, the client has already disconnected the connection, and the rest interface request operations are invalid.
EXAMPLE III
This embodiment corresponds to the first embodiment and the second embodiment, and provides a computer-readable storage medium, on which a computer program is stored, where the computer program is capable of implementing the steps included in the method for preventing an invalid request from occurring according to the first embodiment or the second embodiment when the computer program is executed by a processor. The detailed steps are not repeated here, and refer to the descriptions of the first embodiment and the second embodiment for details.
In summary, the method and the storage medium for preventing the invalid request provided by the present invention can effectively prevent the occurrence of the micro-service invalid request, thereby improving the efficiency and the availability of the system; and has the advantages of simple and convenient implementation mode, easy implementation, remarkable effect and the like.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

Claims (5)

1. A method for preventing the occurrence of invalid requests, comprising:
the client sends a request carrying the overtime to the server;
the server side creates a shared object corresponding to the request and sets the overtime time of the request in the shared object;
recording the execution time of the server for calling each micro-service interface calling method according to the request;
and if the request is judged to be overtime according to the record and the overtime time in the shared object, the server stops processing the request.
2. The method as claimed in claim 1, wherein the recording server calls the execution time of each micro service interface calling method according to the request, and before the recording server, the method further comprises:
the method for calling the configuration micro-service interface uses a preset suffix name;
acquiring the calling time and the ending time of each micro service interface calling method by intercepting the micro service interface calling method with the suffix name as the preset suffix name;
and acquiring and recording the execution time of the calling method of each micro service interface according to the calling time and the ending time.
3. The method according to claim 1, wherein if the request is determined to have timed out based on the record and the timeout period in the shared object, the method further comprises:
and if the value obtained by subtracting the execution time of each micro service interface calling method from the overtime time in the shared object is less than or equal to 0, judging that the request is overtime.
4. The method for preventing the occurrence of invalid requests according to claim 1, wherein the server creates a shared object corresponding to the request and sets the timeout time of the request, specifically:
the server analyzes the request through a filter to obtain request parameters including the overtime time;
and the server side creates a shared object corresponding to the request and sets the request parameters in the shared object.
5. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, is adapted to carry out the steps of a method for preventing invalidating requests according to any one of claims 1 to 4.
CN202010212679.6A 2020-03-24 2020-03-24 Method for preventing invalid request from occurring and storage medium Active CN111552577B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010212679.6A CN111552577B (en) 2020-03-24 2020-03-24 Method for preventing invalid request from occurring and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010212679.6A CN111552577B (en) 2020-03-24 2020-03-24 Method for preventing invalid request from occurring and storage medium

Publications (2)

Publication Number Publication Date
CN111552577A true CN111552577A (en) 2020-08-18
CN111552577B CN111552577B (en) 2023-11-03

Family

ID=72001915

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010212679.6A Active CN111552577B (en) 2020-03-24 2020-03-24 Method for preventing invalid request from occurring and storage medium

Country Status (1)

Country Link
CN (1) CN111552577B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112491735A (en) * 2020-11-10 2021-03-12 京东数字科技控股股份有限公司 Flow control method, device, equipment and computer readable storage medium
CN112783739A (en) * 2021-01-05 2021-05-11 广州品唯软件有限公司 Timeout time display method, device, system, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104954453A (en) * 2015-06-02 2015-09-30 浙江工业大学 Data mining REST service platform based on cloud computing
US20160196149A1 (en) * 2015-01-05 2016-07-07 Dell Software Inc. Milestone based dynamic multiple watchdog timeouts and early failure detection
CN106375435A (en) * 2016-08-31 2017-02-01 福建天晴数码有限公司 Web thread timeout monitoring method and system
CN109189509A (en) * 2018-09-03 2019-01-11 中国平安人寿保险股份有限公司 The response method and server that call method, the interface of interface call
CN110659132A (en) * 2019-08-29 2020-01-07 福建天泉教育科技有限公司 Request processing optimization method and computer-readable storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160196149A1 (en) * 2015-01-05 2016-07-07 Dell Software Inc. Milestone based dynamic multiple watchdog timeouts and early failure detection
CN104954453A (en) * 2015-06-02 2015-09-30 浙江工业大学 Data mining REST service platform based on cloud computing
CN106375435A (en) * 2016-08-31 2017-02-01 福建天晴数码有限公司 Web thread timeout monitoring method and system
CN109189509A (en) * 2018-09-03 2019-01-11 中国平安人寿保险股份有限公司 The response method and server that call method, the interface of interface call
CN110659132A (en) * 2019-08-29 2020-01-07 福建天泉教育科技有限公司 Request processing optimization method and computer-readable storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112491735A (en) * 2020-11-10 2021-03-12 京东数字科技控股股份有限公司 Flow control method, device, equipment and computer readable storage medium
CN112783739A (en) * 2021-01-05 2021-05-11 广州品唯软件有限公司 Timeout time display method, device, system, computer equipment and storage medium

Also Published As

Publication number Publication date
CN111552577B (en) 2023-11-03

Similar Documents

Publication Publication Date Title
CN107402956B (en) Data processing method and device for large task and computer readable storage medium
CN111711697A (en) Message pushing method, device, equipment and storage medium
CN111552577B (en) Method for preventing invalid request from occurring and storage medium
CN111064626B (en) Configuration updating method, device, server and readable storage medium
US11223686B2 (en) Transport channel via web socket for OData
CN111200606A (en) Deep learning model task processing method, system, server and storage medium
CN113590433B (en) Data management method, data management system, and computer-readable storage medium
CN113342503B (en) Real-time progress feedback method, device, equipment and storage medium
CN114610404A (en) Component calling method and device based on application framework and computer equipment
CN108111630B (en) Zookeeper cluster system and connection method and system thereof
CN111858086B (en) Processing method and storage medium for queue timeout in request task processing
CN113965628A (en) Message scheduling method, server and storage medium
CN111984388A (en) Method, device and medium for coordinating data consistency in distributed transactions of cloud environment
CN116541167A (en) System flow control method, device, electronic equipment and computer readable medium
CN115629909A (en) Service data processing method and device, electronic equipment and storage medium
CN110162250B (en) Screenshot method, system and storage medium
US20230093004A1 (en) System and method for asynchronous backend processing of expensive command line interface commands
CN111294377A (en) Network request sending method of dependency relationship, terminal device and storage medium
CN114385351A (en) Cloud management platform load balancing performance optimization method, device, equipment and medium
CN114640610A (en) Service management method and device based on cloud protogenesis and storage medium
CN113760487B (en) Service processing method and device
CN111031123B (en) Spark task submission method, system, client and server
CN115250276A (en) Distributed system and data processing method and device
CN113760693A (en) Method and apparatus for local debugging of microservice systems
CN112612428A (en) Method and device for improving performance of Codeigniter frame

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant