CN114546734A - Remote service calling method, readable storage medium and computer program product - Google Patents

Remote service calling method, readable storage medium and computer program product Download PDF

Info

Publication number
CN114546734A
CN114546734A CN202210185406.6A CN202210185406A CN114546734A CN 114546734 A CN114546734 A CN 114546734A CN 202210185406 A CN202210185406 A CN 202210185406A CN 114546734 A CN114546734 A CN 114546734A
Authority
CN
China
Prior art keywords
service
calling
record
redis
ordered set
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.)
Pending
Application number
CN202210185406.6A
Other languages
Chinese (zh)
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.)
Beta Technology Beijing Co ltd
Original Assignee
Beta Technology Beijing Co 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 Beta Technology Beijing Co ltd filed Critical Beta Technology Beijing Co ltd
Priority to CN202210185406.6A priority Critical patent/CN114546734A/en
Publication of CN114546734A publication Critical patent/CN114546734A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • 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/16Error detection or correction of the data by redundancy in hardware
    • G06F11/20Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements
    • G06F11/202Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements where processing functionality is redundant
    • G06F11/2023Failover techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9014Indexing; Data structures therefor; Storage structures hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • G06F16/9566URL specific, e.g. using aliases, detecting broken or misspelled links
    • 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
    • G06F9/548Object oriented; Remote method invocation [RMI]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/544Remote

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Quality & Reliability (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The embodiment of the invention provides a remote service calling method, a readable storage medium and a computer program product. The method comprises the following steps: the PHP service determines that a first service is to be remotely invoked; judging whether the standby service mark of the first service is set to be effective or not, if so, sending a service calling request to the standby service of the first service; otherwise, sending a service calling request to the first service, and if the calling is successful, adding the calling record to a first Redis ordered set of the first service; if the calling fails, the calling record is added to the first Redis ordered set and the second Redis ordered set of the first service at the same time, the ratio of the number of the records of the second Redis ordered set and the first Redis ordered set is calculated, the calling failure proportion of the first service is obtained, and whether: and setting the standby service mark of the first service as valid if the calling failure ratio is greater than a preset first threshold value and the record number of the first Redis ordered set is greater than a preset second threshold value. The embodiment of the invention improves the success rate of remote service calling.

Description

Remote service calling method, readable storage medium and computer program product
Technical Field
Embodiments of the present invention relate to a remote service invocation method, a readable storage medium, and a computer program product.
Background
In a conventional PHP (Hypertext Preprocessor) service, when a remote service such as: in this case, if a certain called service suddenly fails, the PHP service is not available, and if no timeout is set, the server resource where the PHP service is located may be occupied, and finally the PHP service may be avalanche.
When the PHP service calls other upstream web services, the direct call is extended by the crrl (crrl is a file transfer tool that works under the command line using URL syntax). There are very important services in the remote service called by PHP such as: the OCR (Optical Character Recognition) service must guarantee 99.999% stability of the OCR service. However, as the service of the OCR service is increasing, the request amount of the OCR service to other services is increasing day by day, when the service called by the OCR service is unavailable, the OCR service may be unavailable or avalanche, and at this time, if the PHP service calls the OCR service, the call cannot be successful.
Therefore, how to improve the call success rate of the PHP service calling the OCR service is an urgent problem to be solved.
Disclosure of Invention
The embodiment of the invention provides a remote service calling method, a readable storage medium and a computer program product, which are used for improving the success rate of remote service calling.
The technical scheme of the embodiment of the invention is realized as follows:
a remote service invocation method, the method comprising:
the method comprises the steps that a PHP service of a hypertext preprocessor determines that a first service is to be called remotely;
judging whether a standby service mark of the first service is set to be effective or not, and if the standby service mark is set to be effective, sending a service calling request to the standby service of the first service;
if the standby service mark is not set to be valid, sending a service calling request to the first service and receiving a service calling response returned by the first service;
if the service calling response indicates that the calling is successful, adding the calling record into a first Redis ordered set of the first service;
if the service calling response indicates that calling fails, adding the calling record to a first Redis ordered set and a second Redis ordered set of the first service at the same time, obtaining the record number of the first Redis ordered set and the record number of the second Redis ordered set, calculating the ratio of the record number of the second Redis ordered set to the record number of the first Redis ordered set, obtaining the calling failure proportion of the first service, and judging whether the calling failure proportion currently meets the following requirements: and if the calling failure proportion of the first service is larger than a preset first threshold value and the record number of the first Redis ordered set is larger than a preset second threshold value, setting the standby service mark of the first service as valid.
The call record comprises: the calling ID and calling time of the current calling are the time for receiving the service calling response;
the method further comprises: for each calling record in the first Redis set, when the time interval between the calling time in the calling record and the current time reaches a preset first time length, deleting the calling record from the first Redis set;
and for each call record in the second Redis set, deleting the call record from the second Redis set when the time interval between the call time in the call record and the current time reaches a preset first time length.
After the setting of the standby service flag is valid and before sending the service invocation request to the standby service of the first service, the method further includes:
randomly generating a random value in a preset first range according to a preset random number generation algorithm, and judging whether the random value falls in a preset second range; wherein the second range is within and smaller than the first range;
if the service is within the preset second range, sending a service calling request to the first service;
and if the current service is not within the preset second range, executing the action of sending the service calling request to the standby service of the first service.
If the service call request falls within the preset second range, after the service call request is sent to the first service, the method further includes: receiving a service calling response returned by the first service;
if the service calling response indicates that calling is successful, adding the calling record into a first Redis ordered set of the first service, acquiring the record number of the first Redis ordered set and the record number of a second Redis ordered set, calculating the ratio of the record number of the second Redis ordered set to the record number of the first Redis ordered set, obtaining the calling failure proportion of the first service, and judging whether the calling failure proportion meets the following requirements: the calling failure proportion of the first service is smaller than a preset third threshold, the record number of the first Redis ordered set is larger than a preset fourth threshold, and if the record number of the first Redis ordered set is larger than the preset fourth threshold, the standby service mark of the first service is set to be invalid;
and if the service calling response indicates that calling fails, adding the calling record into a first Redis ordered set and a second Redis ordered set of the first service at the same time.
After the setting of the standby service flag is valid and before the randomly generating a hash value within a preset first range according to a preset hash algorithm, the method further includes:
judging whether the time interval between the current time and the time when the standby service mark is set to be effective last time is greater than a preset second time length or not;
if not, directly sending a service calling request to the standby service of the first service;
and if so, executing the action of randomly generating a hash value within a preset first range according to a preset hash algorithm.
The setting of the standby service flag for the first service to valid includes:
using a Uniform Resource Locator (URL) of a first service as a key, inquiring corresponding hash records from the Redis, if the hash records are inquired, changing the value of a domain in the hash records as a standby service mark into valid, and changing the value of the domain in the hash records as standby service starting time into current time; if the query is not found, adding a hash record in Redis, wherein the key of the hash record is the URL of the first service, and the hash record comprises two domains, namely a first domain is a standby service mark, the value of the first domain is valid, a second domain is standby service starting time, and the value of the second domain is current time;
the setting of the standby service flag of the first service to invalid includes:
and inquiring the corresponding hash record from the Redis by taking the URL of the first service as a key, changing the value of a domain in the inquired hash record as a standby service mark into invalid, and changing the value of the domain in the hash record as the standby service starting time into 0.
The acquiring the number of records of the first Redis ordered set and the number of records of the second Redis ordered set includes:
and adopting an o (1) algorithm to obtain the record number of the first Redis ordered set and the record number of the second Redis ordered set.
The first service is an Optical Character Recognition (OCR) service.
A non-transitory computer readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the steps of the remote service invocation method recited in any of the above.
A computer program product comprising a computer program or instructions which, when executed by a processor, implement the steps of the remote service invocation method according to any of the preceding claims.
An electronic device, comprising: a processor and a memory, wherein:
the memory stores a program configured to cause the processor to perform the steps of the remote service invocation method as described in any of the above when executed by the processor.
In the embodiment of the invention, the success rate of remote service calling is improved by maintaining the failure record and the total record of remote service calling and determining whether to start the standby service of the remote service according to the calling failure proportion and the total calling times, and meanwhile, the failure record and the total record are maintained through the Redis ordered set, so that the accuracy of the maintained record and the accuracy of the read record are ensured.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive labor.
Fig. 1 is a flowchart of a remote service invocation method according to an embodiment of the present invention;
FIG. 2 is a flow chart of a remote service invocation method provided by another embodiment of the present invention;
fig. 3 is a schematic structural diagram of a remote service invocation device according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprising" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not explicitly listed or inherent to such process, method, article, or apparatus.
The technical solution of the present invention will be described in detail with specific examples. Several of the following embodiments may be combined with each other and some details of the same or similar concepts or processes may not be repeated in some embodiments.
The embodiment of the invention provides a remote service calling method, wherein in the method, a PHP service determines that a first service is required to be called remotely; judging whether a standby service mark of the first service is set to be effective or not, and if the standby service mark is set to be effective, sending a service calling request to the standby service of the first service; if the standby service mark is not set to be valid, sending a service calling request to the first service, and receiving a service calling response returned by the first service; if the service calling response indicates that the calling is successful, adding the calling record into a first Redis ordered set of the first service; if the service calling response indicates that calling fails, adding the calling record to a first Redis ordered set and a second Redis ordered set of the first service at the same time, obtaining the record number of the first Redis ordered set and the record number of the second Redis ordered set, calculating the ratio of the record number of the second Redis ordered set to the record number of the first Redis ordered set, obtaining the calling failure proportion of the first service, and judging whether the calling failure proportion currently meets the following requirements: and if the calling failure proportion of the first service is larger than a preset first threshold value and the record number of the first Redis ordered set is larger than a preset second threshold value, setting the standby service mark of the first service as valid. The embodiment of the invention improves the success rate of the PHP service for calling the remote service.
Fig. 1 is a flowchart of a remote service invoking method according to an embodiment of the present invention, which includes the following steps:
step 101: the PHP service determines to remotely invoke the first service.
Step 102: the PHP service determines whether the standby service flag of the first service is set to valid, if yes, go to step 103; otherwise, step 104 is performed.
Step 103: the PHP service sends a service calling request to the standby service of the first service, and the process is finished.
Step 104: the PHP service sends a service calling request to the first service and receives a service calling response returned by the first service.
Step 105: the PHP service determines whether the service invocation response indicates a successful invocation, if so, performs step 106; otherwise, step 107 is performed.
Step 106: the PHP service adds the call record to the first Redis ordered set of the first service, and the process is ended.
Step 107: the PHP service adds the call records to a first Redis ordered set and a second Redis ordered set of a first service at the same time, obtains the record number of the first Redis ordered set and the record number of the second Redis ordered set, calculates the ratio of the record number of the second Redis ordered set to the record number of the first Redis ordered set, obtains the call failure ratio of the first service, and judges whether the call failure ratio satisfies the following conditions: and if the calling failure proportion of the first service is larger than a preset first threshold value and the record number of the first Redis ordered set is larger than a preset second threshold value, setting the standby service mark of the first service as valid.
In the embodiment of the invention, the success rate of remote service calling is improved by maintaining the failure record and the total record of remote service calling and determining whether to start the standby service of the remote service according to the calling failure proportion and the total calling times, and meanwhile, the failure record and the total record are maintained through the Redis ordered set, so that the accuracy of the maintained record and the accuracy of the read record are ensured.
In an optional embodiment, the record of this call in step 106 and step 107 includes: the calling ID and calling time of the calling are obtained, wherein the calling time is the time of receiving a service calling response; and, the method further comprises: for each calling record in a first Redis set, when the time interval between the calling time in the calling record and the current time reaches a preset first time length, deleting the calling record from the first Redis set; and for each call record in the second Redis set, deleting the call record from the second Redis set when the time interval between the call time in the call record and the current time reaches a preset first time length.
Through the embodiment, the first Redis ordered set and the second Redis ordered set are ensured not to generate bottlenecks, so that the stability of the remote service calling process is ensured.
In an optional embodiment, before the PHP service sends the service invocation request to the standby service of the first service in step 103, the method further includes: randomly generating a random value in a preset first range according to a preset random number generation algorithm, judging whether the random value falls in a preset second range, and if so, sending a service calling request to the first service; if the service call request does not fall within the preset second range, the operation of sending the service call request to the standby service of the first service in step 103 is performed. The second range is located in the first range and smaller than the first range.
In the above embodiment, after the standby service of the first service is enabled, the subsequent call request for the first service is still sent to the first service to test whether the first service is recovered.
In an optional embodiment, if the service falls within the preset second range, after the sending the service invocation request to the first service, the method further includes: receiving a service calling response returned by the first service; if the service calling response indicates that calling is successful, adding the calling record into a first Redis ordered set of the first service, acquiring the record number of the first Redis ordered set and the record number of a second Redis ordered set, calculating the ratio of the record number of the second Redis ordered set to the record number of the first Redis ordered set, obtaining the calling failure proportion of the first service, and judging whether the calling failure proportion meets the following requirements: the calling failure proportion of the first service is smaller than a preset third threshold, the record number of the first Redis ordered set is larger than a preset fourth threshold, and if the record number of the first Redis ordered set is larger than the preset fourth threshold, the standby service mark of the first service is set to be invalid; and if the service calling response indicates that calling fails, adding the calling record into a first Redis ordered set and a second Redis ordered set of the first service at the same time.
In the above embodiment, after the standby service of the first service is enabled, if it is found that the failure ratio of the service invocation request sent to the first service is smaller than the preset third threshold, and the number of the service invocation requests sent to the first service is greater than the preset fourth threshold, it is determined that the first service has been restored, and then the service invocation request sent to the first service can be completely restored.
In an optional embodiment, before randomly generating a hash value within a preset first range according to a preset hash algorithm in step 103, the method further includes: judging whether the time interval between the current time and the time when the standby service mark is set to be effective last time is greater than a preset second time length or not; if not, directly sending a service calling request to the standby service of the first service; and if so, executing an action of randomly generating a hash value within a preset first range according to a preset hash algorithm.
The above embodiment, in view of: the first service is less likely to return to normal within a period of time when the standby service of the first service is just started, and at this time, the service call request for the first service can be completely transferred to the standby service of the first service, so as to reduce call time consumption.
In an alternative embodiment, the step 102 of setting the standby service flag of the first service to be valid includes: using a Uniform Resource Locator (URL) of a first service as a Key (Key), querying a corresponding hash record from the Redis, if the hash record is queried, changing a Value (Value) of a Field (Field) in the hash record as a standby service identifier into valid, and changing a Value of a Field in the hash record as standby service enabling time into current time; if the query is not found, adding a hash record in Redis, wherein the key of the hash record is the URL of the first service, and the hash record comprises two domains, namely a first domain is a standby service mark, the value of the first domain is valid, a second domain is standby service starting time, and the value of the second domain is current time;
in step 103, setting the standby service flag of the first service to invalid includes: and inquiring the corresponding hash record from the Redis by taking the URL of the first service as a key, changing the value of a domain in the inquired hash record as a standby service mark into invalid, and changing the value of the domain in the hash record as the standby service starting time into 0.
In the above embodiment, the standby service flag and the standby service activation time of the first service are maintained in a manner of a Hash key value pair of the Redis, the time complexity of the Hash key value pair operated by the Redis is o (1), and the whole operation is completed in the memory of the Redis, thereby ensuring the reliability of maintenance and operation and the rapidity of operation.
In an optional embodiment, in step 107, acquiring the number of records of the first Redis ordered set and the number of records of the second Redis ordered set includes: and adopting an o (1) algorithm to obtain the record number of the first Redis ordered set and the record number of the second Redis ordered set.
In the above embodiment, the o (1) algorithm is adopted to obtain the number of records of the first Redis ordered set and the number of records of the second Redis ordered set, so that the rapidity of obtaining the number of records is ensured.
In an alternative embodiment, the first service is an OCR service.
Fig. 2 is a flowchart of a remote service invoking method according to another embodiment of the present invention, which includes the following specific steps:
step 201: the PHP service determines to remotely invoke the first service.
Step 202: the PHP service uses the URL of the first service as a Key (Key), acquires a corresponding Hash record from Redis, judges whether the Hash record is acquired, and if so, executes step 203; otherwise, step 207 is performed.
Step 203: the PHP service determines the Field in the Hash record: if the Value (Value) of is _ closed is 1, if yes, go to step 207; otherwise, step 204 is performed.
is _ closed ═ 1, which indicates that the standby service is not enabled by the current first service; is _ closed ═ 0, which indicates that the standby service has been enabled for the current first service.
Step 204: the PHP service obtains the Field from the Hash record: calculating a difference obtained by subtracting the value of the start _ time from the value of the start _ time at the current moment, judging whether the difference is greater than a preset second time length, and if so, executing the step 205; otherwise, step 206 is performed.
The value of the preset second duration may be set empirically, for example: the value can be taken for 3 minutes.
Step 205: the PHP service randomly generates a random value in a preset first range by adopting a preset random number generation algorithm, judges whether the random value is in a preset second range, and if so, executes step 207; otherwise, step 206 is performed.
The second range is within and smaller than the first range, for example: the length of the second range is 10% of the first range.
Step 206: the PHP service initiates a service call request to the standby service of the first service, and the process is ended.
Step 207: the PHP service initiates a service call request to the first service and waits for receiving a service call response returned by the first service.
Step 208: if the PHP service receives a service calling response returned by the first service, and a return value carried by the response is an abnormal value which is not 200 errors, adding the calling record into a first Redis ordered set and a second Redis ordered set of the first service; otherwise, only adding the call record to the first Redis ordered set of the first service.
Wherein, the keys of the first and second Redis ordered sets both contain the URL of the first service, for example: the Key of the first Redis ordered set may be: URL _ all of the first service, Key of the second reds ordered set may be: URL _ error of the first service.
The call record includes a call ID of the call and a call time (score) of the call. The call ID may be obtained through the PHP function uniqid, and the call time may be in the current timestamp (millisecond level).
In order to avoid that the first Redis ordered set and the second Redis ordered set reach a bottleneck, the first Redis ordered set and the second Redis ordered set only store the latest preset first duration as follows: calling records within two minutes, wherein when the storage duration of one calling record in the first Redis ordered set or the second Redis ordered set reaches a preset duration, the storage duration is as follows: two minutes, the call record is deleted.
Step 209: the PHP service acquires the call record numbers of the first Redis ordered set and the second Redis ordered set through an o (1) algorithm, the call record numbers are respectively set as C1 and C2, and d is calculated as C2/C1.
Step 210: the PHP service takes the URL of the first service as a Key, acquires a corresponding Hash record from Redis and judges the Field in the Hash record: if the value of is _ closed is 1, if yes, go to step 211; otherwise, step 213 is performed.
Step 211: the PHP service determines whether: d>d1thAnd C1>C1thIf yes, go to step 212; otherwise, no further processing is performed, and the process ends.
d1th、C1thThe specific value of the preset threshold is set according to experience and the like.
Step 212: the PHP service notifies Redis to send a Field in the Hash record: the value of is _ closed is updated to 0 and the Field in the Hash record: the value of start _ time is updated to the current time, and the present flow ends.
Step 213: the PHP service determines whether: d<d2thAnd C1>C2thIf yes, go to step 214; otherwise, no further processing is performed, and the process ends.
Step 214: the PHP service notifies Redis to send a Field in the Hash record: the value of is _ closed is updated to 1, and the Field in the Hash record: the value of start _ time is updated to 0, and the flow ends.
It should be noted that all Redis operations in the embodiment of the present invention need to ensure atomicity of the operations through the lua, so as to avoid a data recording error caused by a plurality of services simultaneously operating the same record of the Redis.
Fig. 3 is a schematic structural diagram of a remote service invocation device according to an embodiment of the present invention, where the device is located on a PHP service, and the device mainly includes: a standby service enabling information obtaining module 31 and a calling judging module 32, wherein:
the standby service activation information obtaining module 31: for determining that the first service is to be remotely invoked, determining whether the standby service flag of the first service is asserted, and notifying the invocation determining module 32 of the determination result.
The calling judgment module 32: the standby service calling module is used for sending a service calling request to the standby service of the first service if the standby service mark is set to be valid; if the standby service mark is not set to be valid, sending a service calling request to the first service and receiving a service calling response returned by the first service; if the service calling response indicates that the calling is successful, adding the calling record into a first Redis ordered set of the first service; if the service calling response indicates that calling fails, adding the calling record into a first Redis ordered set and a second Redis ordered set of the first service at the same time, acquiring the record number of the first Redis ordered set and the record number of the second Redis ordered set, calculating the ratio of the record number of the second Redis ordered set to the record number of the first Redis ordered set, obtaining the calling failure proportion of the first service, and judging whether the calling failure proportion currently meets the following requirements: and if the calling failure proportion of the first service is larger than a preset first threshold value and the record number of the first Redis ordered set is larger than a preset second threshold value, setting the standby service mark of the first service as valid.
Embodiments of the present application further provide a computer program product, which includes a computer program or instructions, and when the computer program or instructions is executed by a processor, the steps of the remote service invocation method described in any of the above embodiments are implemented.
Embodiments of the present application also provide a computer-readable storage medium storing instructions that, when executed by a processor, may perform steps in a remote service invocation method as described above. In practical applications, the computer readable medium may be included in each device/apparatus/system of the above embodiments, or may exist separately and not be assembled into the device/apparatus/system. Wherein instructions are stored in a computer readable storage medium, which stored instructions, when executed by a processor, may perform the steps in the remote service invocation method as described above.
According to embodiments disclosed herein, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example and without limitation: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing, without limiting the scope of the present disclosure. In the embodiments disclosed herein, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
As shown in fig. 4, an embodiment of the present invention further provides an electronic device. As shown in fig. 4, it shows a schematic structural diagram of an electronic device according to an embodiment of the present invention, specifically:
the electronic device may include a processor 41 of one or more processing cores, memory 42 of one or more computer-readable storage media, and a computer program stored on the memory and executable on the processor. The remote service invocation method described above may be implemented when executing the program of the memory 42.
Specifically, in practical applications, the electronic device may further include a power supply 43, an input/output unit 44, and other components. Those skilled in the art will appreciate that the configuration of the electronic device shown in fig. 4 is not intended to be limiting of the electronic device and may include more or fewer components than shown, or some components in combination, or a different arrangement of components. Wherein:
the processor 41 is a control center of the electronic device, connects various parts of the entire electronic device by various interfaces and lines, and performs various functions of the server and processes data by running or executing software programs and/or modules stored in the memory 42 and calling data stored in the memory 42, thereby performing overall monitoring of the electronic device.
The memory 42 may be used to store software programs and modules, i.e., the computer-readable storage media described above. The processor 41 executes various functional applications and data processing by executing software programs and modules stored in the memory 42. The memory 42 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the server, and the like. Further, the memory 42 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, memory 42 may also include a memory controller to provide processor 41 access to memory 42.
The electronic device further comprises a power supply 43 for supplying power to each component, and the power supply 43 can be logically connected with the processor 41 through a power management system, so that functions of charging, discharging, power consumption management and the like can be managed through the power management system. The power supply 43 may also include any component including one or more dc or ac power sources, recharging systems, power failure detection circuitry, power converters or inverters, power status indicators, and the like.
The electronic device may also include an input-output unit 44, the input-unit output 44 operable to receive input numeric or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control. The input unit output 44 may also be used to display information input by or provided to the user, as well as various graphical user interfaces, which may be made up of graphics, text, icons, video, and any combination thereof.
The flowchart and block diagrams in the figures of the present application illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments disclosed herein. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not explicitly recited in the present application. In particular, the features recited in the various embodiments and/or claims of the present application may be combined and/or coupled in various ways, all of which fall within the scope of the present disclosure, without departing from the spirit and teachings of the present application.
The principles and embodiments of the present invention are explained herein using specific examples, which are provided only to help understanding the method and the core idea of the present invention, and are not intended to limit the present application. It will be appreciated by those skilled in the art that changes may be made in this embodiment and its broader aspects and without departing from the principles, spirit and scope of the invention, and that all such modifications, equivalents, improvements and equivalents as may be included within the scope of the invention are intended to be protected by the claims.

Claims (11)

1. A remote service invocation method, characterized in that the method comprises:
the method comprises the steps that a PHP service of a hypertext preprocessor determines that a first service is to be called remotely;
judging whether a standby service mark of a first service is set to be valid or not, and if the standby service mark is set to be valid, sending a service calling request to the standby service of the first service;
if the standby service mark is not set to be valid, sending a service calling request to the first service, and receiving a service calling response returned by the first service;
if the service calling response indicates that the calling is successful, adding the calling record into a first Redis ordered set of the first service;
if the service calling response indicates that calling fails, adding the calling record to a first Redis ordered set and a second Redis ordered set of the first service at the same time, obtaining the record number of the first Redis ordered set and the record number of the second Redis ordered set, calculating the ratio of the record number of the second Redis ordered set to the record number of the first Redis ordered set, obtaining the calling failure proportion of the first service, and judging whether the calling failure proportion currently meets the following requirements: and if the calling failure ratio of the first service is greater than a preset first threshold value, and the record number of the first Redis ordered set is greater than a preset second threshold value, setting the standby service mark of the first service as valid.
2. The method of claim 1, wherein the call record comprises: the calling ID and calling time of the calling are obtained, wherein the calling time is the time of receiving the service calling response;
the method further comprises: for each calling record in the first Redis set, when the time interval between the calling time in the calling record and the current time reaches a preset first time length, deleting the calling record from the first Redis set;
and for each call record in the second Redis set, deleting the call record from the second Redis set when the time interval between the call time in the call record and the current time reaches a preset first time length.
3. The method of claim 1 or 2, wherein after the standby service flag is asserted and before sending the service invocation request to the standby service of the first service, further comprising:
randomly generating a random value in a preset first range according to a preset random number generation algorithm, and judging whether the random value falls in a preset second range; wherein the second range is within and smaller than the first range;
if the service is within the preset second range, sending a service calling request to the first service;
and if the current service is not within the preset second range, executing the action of sending the service calling request to the standby service of the first service.
4. The method of claim 3, wherein after sending the service invocation request to the first service if the service invocation request falls within the preset second range, further comprising: receiving a service calling response returned by the first service;
if the service calling response indicates that calling is successful, adding the calling record into a first Redis ordered set of the first service, acquiring the record number of the first Redis ordered set and the record number of a second Redis ordered set, calculating the ratio of the record number of the second Redis ordered set to the record number of the first Redis ordered set, obtaining the calling failure proportion of the first service, and judging whether the calling failure proportion meets the following requirements: the calling failure proportion of the first service is smaller than a preset third threshold, the record number of the first Redis ordered set is larger than a preset fourth threshold, and if the record number of the first Redis ordered set is larger than the preset fourth threshold, the standby service mark of the first service is set to be invalid;
and if the service calling response indicates that the calling fails, adding the calling record into the first Redis ordered set and the second Redis ordered set of the first service at the same time.
5. The method of claim 3, wherein after the standby service flag is asserted and before the randomly generating a hash value within a predetermined first range according to a predetermined hash algorithm, further comprising:
judging whether the time interval between the current time and the time when the standby service mark is set to be effective last time is greater than a preset second time length or not;
if not, directly sending a service calling request to the standby service of the first service;
and if so, executing the action of randomly generating a hash value within a preset first range according to a preset hash algorithm.
6. The method of claim 5, wherein the asserting the standby service flag for the first service comprises:
using a Uniform Resource Locator (URL) of a first service as a key, inquiring corresponding hash records from the Redis, if the hash records are inquired, changing the value of a domain in the hash records as a standby service mark into valid, and changing the value of the domain in the hash records as standby service starting time into current time; if the query is not found, adding a hash record in Redis, wherein the key of the hash record is the URL of the first service, and the hash record comprises two domains, namely a first domain is a standby service mark, the value of the first domain is valid, a second domain is standby service starting time, and the value of the second domain is current time;
the setting of the standby service flag of the first service to invalid includes:
and inquiring the corresponding hash record from the Redis by taking the URL of the first service as a key, changing the value of a domain in the inquired hash record as a standby service mark into invalid, and changing the value of the domain in the hash record as the standby service starting time into 0.
7. The method of claim 1, wherein obtaining the number of records of the first Redis ordered set and the number of records of the second Redis ordered set comprises:
and adopting an o (1) algorithm to obtain the record number of the first Redis ordered set and the record number of the second Redis ordered set.
8. The method of claim 1, wherein the first service is an Optical Character Recognition (OCR) service.
9. A non-transitory computer readable storage medium storing instructions which, when executed by a processor, cause the processor to perform the steps of the remote service invocation method recited in any of claims 1-8.
10. A computer program product comprising computer programs or instructions, characterized in that the computer programs or instructions, when executed by a processor, implement the steps of the remote service invocation method according to any of claims 1 to 8.
11. An electronic device, comprising: a processor and a memory, wherein:
the memory stores a program configured to cause the processor to perform the steps of the remote service invocation method according to any of claims 1-8 when executed by the processor.
CN202210185406.6A 2022-02-28 2022-02-28 Remote service calling method, readable storage medium and computer program product Pending CN114546734A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210185406.6A CN114546734A (en) 2022-02-28 2022-02-28 Remote service calling method, readable storage medium and computer program product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210185406.6A CN114546734A (en) 2022-02-28 2022-02-28 Remote service calling method, readable storage medium and computer program product

Publications (1)

Publication Number Publication Date
CN114546734A true CN114546734A (en) 2022-05-27

Family

ID=81680049

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210185406.6A Pending CN114546734A (en) 2022-02-28 2022-02-28 Remote service calling method, readable storage medium and computer program product

Country Status (1)

Country Link
CN (1) CN114546734A (en)

Similar Documents

Publication Publication Date Title
CN110516971B (en) Anomaly detection method, device, medium and computing equipment
EP2723017A1 (en) Method, apparatus and system for implementing distributed auto-incrementing counting
CN109766217B (en) Vehicle machine system fault repairing method and device
CN111371841B (en) Data monitoring method and device
CN111124761B (en) Equipment restarting method, device, equipment and medium
US8719622B2 (en) Recording and preventing crash in an appliance
CN108733808B (en) Big data software system switching method, system, terminal equipment and storage medium
CN112286559A (en) Upgrading method and device for vehicle-mounted intelligent terminal
CN111125586A (en) Page updating method and device
CN109669642B (en) Node joining method, system and device of storage system and readable storage medium
CN114546734A (en) Remote service calling method, readable storage medium and computer program product
CN110930253A (en) Intelligent contract internal main key generation method and device, computer equipment and storage medium
CN115827265A (en) Transaction processing method, device, equipment and storage medium
CN109389271B (en) Application performance management method and system
CN111488117A (en) Method, electronic device, and computer-readable medium for managing metadata
CN105790975A (en) Service processing operation execution method and device
CN114691781A (en) Data synchronization method, system, device, equipment and medium
CN113810457A (en) Method and device for reporting service access exception, readable storage medium and electronic equipment
CN111625402A (en) Data recovery method and device, electronic equipment and computer readable storage medium
CN112148712A (en) Data processing method, device, equipment and medium
CN113805910B (en) Method and system for sharing data in application
CN111464357A (en) Resource allocation method and device
CN110795242A (en) Storage space management method and device, electronic equipment and storage medium
CN112463514A (en) Monitoring method and device for distributed cache cluster
CN117033084B (en) Virtual machine backup method and device, electronic equipment and storage medium

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