CN110162384B - Redis distributed lock-based timeout time dynamic adjustment method and system - Google Patents

Redis distributed lock-based timeout time dynamic adjustment method and system Download PDF

Info

Publication number
CN110162384B
CN110162384B CN201910318260.6A CN201910318260A CN110162384B CN 110162384 B CN110162384 B CN 110162384B CN 201910318260 A CN201910318260 A CN 201910318260A CN 110162384 B CN110162384 B CN 110162384B
Authority
CN
China
Prior art keywords
time
target
execution
timeout
service logic
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.)
Active
Application number
CN201910318260.6A
Other languages
Chinese (zh)
Other versions
CN110162384A (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.)
OneConnect Financial Technology Co Ltd Shanghai
Original Assignee
OneConnect Financial Technology Co Ltd Shanghai
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 OneConnect Financial Technology Co Ltd Shanghai filed Critical OneConnect Financial Technology Co Ltd Shanghai
Priority to CN201910318260.6A priority Critical patent/CN110162384B/en
Publication of CN110162384A publication Critical patent/CN110162384A/en
Priority to PCT/CN2019/120964 priority patent/WO2020211382A1/en
Application granted granted Critical
Publication of CN110162384B publication Critical patent/CN110162384B/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/465Distributed object oriented systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems
    • G06F16/1824Distributed file systems implemented using Network-attached Storage [NAS] architecture
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Debugging And Monitoring (AREA)
  • Electric Clocks (AREA)

Abstract

The invention relates to the technical field of distributed storage, and discloses a method and a system for dynamically adjusting timeout time based on a Redis distributed lock, wherein the method comprises the following steps: acquiring a target estimated execution consumption value corresponding to target business logic; generating timeout time corresponding to the target business logic according to the target estimated execution timeout value and a preset timeout time generation rule; when the target service logic executes locking operation according to the timeout time, acquiring target service logic execution start time and target service logic execution end time corresponding to the target service logic; determining a time difference value between the execution start time and the execution end time of the target business logic as the target execution time consumption of the target business logic; the timeout is adjusted according to the target execution time. Under the method, based on the distributed storage technology, the dynamic adjustment of the timeout time can be realized.

Description

Redis distributed lock-based timeout time dynamic adjustment method and system
Technical Field
The invention relates to the technical field of distributed storage, in particular to a method and a system for dynamically adjusting timeout time based on a Redis distributed lock.
Background
At present, most applications are deployed in a cluster deployment mode, in order to ensure data consistency when a plurality of threads access shared resources in a cluster deployment environment, a distributed lock is often arranged, and the distributed lock is used for limiting that one method can only be executed by the same thread within a timeout period, so that a plurality of threads cannot repeatedly execute a certain method within the timeout period at the same time, and the phenomenon that data is inconsistent due to abnormal modification of the shared resources caused by the fact that a plurality of threads repeatedly execute a certain method at the same time is avoided.
For the most common dis-based distributed locks, how to set their timeout times has been of interest to the developer. The common way to set the timeout time is to pre-estimate the execution time of the service logic in advance, and then set the timeout time of the distributed lock according to the pre-estimated execution time of the service logic. In practice, it is found that, as the service grows, the execution time of the service logic is longer and longer, and the timeout time cannot be dynamically adjusted, so that the execution time of the service logic may exceed the previously set timeout time, which causes premature failure of the distributed lock and further affects the data consistency when multiple threads access the shared resource.
It can be seen that how to implement dynamic adjustment of timeout becomes a problem to be solved.
Disclosure of Invention
In order to solve the problem that the data consistency is affected when a plurality of threads access shared resources due to the fact that the dynamic adjustment of the timeout time cannot be realized in the related art, the invention provides a method and a system for dynamically adjusting the timeout time based on a Redis distributed lock.
The first aspect of the embodiment of the invention discloses a timeout dynamic adjustment method based on a Redis distributed lock, which comprises the following steps:
acquiring a target estimated execution consumption value corresponding to target business logic;
generating timeout time corresponding to the target business logic according to the target estimated execution timeout value and a preset timeout time generation rule;
when the target service logic executes locking operation according to the timeout time, acquiring target service logic execution start time and target service logic execution end time corresponding to the target service logic;
determining a time difference value between the execution start time and the execution end time of the target business logic as the target execution time consumption of the target business logic;
and adjusting the timeout time according to the target execution time consumption.
In an optional implementation manner, in the first aspect of the embodiment of the present invention, before the obtaining the target estimated execution time consumption value corresponding to the target service logic, the method further includes:
when the service online time length corresponding to the service logic is within a preset time length range, determining estimated execution time consumption corresponding to each service logic according to the execution time consumption;
and storing each business logic and the estimated execution time consumption corresponding to the business logic to a preset database correspondingly.
In an optional implementation manner, in a first aspect of the embodiment of the present invention, the obtaining a target estimated execution consumption value corresponding to a target service logic includes:
inquiring the target estimated execution time consumption corresponding to the target business logic in the preset database.
In an optional implementation manner, in the first aspect of the embodiment of the present invention, after the generating the timeout period corresponding to the target service logic according to the target estimated execution consumption value and a preset timeout period generating rule, the method further includes:
recording the generation time of the timeout time corresponding to the target business logic;
judging whether the time difference between the current time and the generation time is larger than a preset time difference or not;
and if so, executing the target service logic, and acquiring the execution start time and the execution end time of the target service logic corresponding to the target service logic when the target service logic executes the locking operation according to the timeout time.
As an optional implementation manner, in the first aspect of the embodiment of the present invention, after the adjusting the timeout period according to the target execution time consumption, the method further includes:
storing the adjusted timeout time, the adjusted time for adjusting the timeout time and the target business logic into a timeout time adjustment database.
As an optional implementation manner, in the first aspect of the embodiment of the present invention, after the adjusting the timeout period according to the target execution time consumption, the method further includes:
storing the adjusted timeout time, the adjusted time for adjusting the timeout time and the target business logic into a timeout time adjustment database.
As an optional implementation manner, in the first aspect of the embodiment of the present invention, the adjusting the timeout period according to the target execution time consumption includes:
counting the number of targets consuming time for the target execution;
when the target number reaches a preset number, calculating a first average value of time consuming for executing the target in the preset number;
and adjusting the timeout time according to the first average value.
As an optional implementation manner, in the first aspect of the embodiment of the present invention, the adjusting the timeout period according to the target execution time consumption includes:
acquiring the time consumption of the target execution within a preset time period;
calculating a second average value of the time consumption of the target execution in the preset time period;
and adjusting the timeout time according to the second average value.
The second aspect of the embodiment of the invention discloses a timeout dynamic adjustment system based on Redis distributed locks, which comprises:
the first acquisition unit is used for acquiring a target estimated execution consumption value corresponding to the target business logic;
the generation unit is used for generating timeout time corresponding to the target business logic according to the target estimated execution timeout value and a preset timeout time generation rule;
the second acquisition unit is used for acquiring target service logic execution start time and target service logic execution end time corresponding to the target service logic when the target service logic executes locking operation according to the timeout time;
a determining unit, configured to determine a time difference between the execution start time of the target service logic and the execution end time of the target service logic as a target execution time consumption of the target service logic;
and the adjusting unit is used for adjusting the timeout time according to the target execution time consumption.
A third aspect of an embodiment of the present invention discloses an electronic device, including:
a processor;
a memory having stored thereon computer readable instructions which, when executed by the processor, implement a method as described above.
A fourth aspect of the embodiments of the present invention discloses a computer-readable storage medium storing a computer program that causes a computer to execute the method as described above.
The technical scheme provided by the embodiment of the invention can comprise the following beneficial effects:
the invention provides a timeout dynamic adjustment method based on a Redis distributed lock, which comprises the following steps of obtaining a target estimated execution consumption value corresponding to target business logic; generating timeout time corresponding to the target business logic according to the target estimated execution timeout value and a preset timeout time generation rule; when the target service logic executes locking operation according to the timeout time, acquiring target service logic execution start time and target service logic execution end time corresponding to the target service logic; determining a time difference value between the execution start time and the execution end time of the target business logic as the target execution time consumption of the target business logic; and adjusting the timeout time according to the target execution time consumption.
According to the method, based on the distributed storage technology, the target execution time consumption can be determined according to the target service logic execution starting time and the target service logic execution ending time, and the overtime time is adjusted according to the target execution time consumption, so that the dynamic adjustment of the overtime time is realized, and the applicability of the overtime time is improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention as claimed.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
FIG. 1 is a schematic diagram illustrating an apparatus for running a Redis distributed lock based timeout dynamic adjustment system according to one exemplary embodiment;
FIG. 2 is a flow chart illustrating a method of dynamically adjusting timeout times based on Redis distributed locks, according to an example embodiment;
FIG. 3 is a flowchart illustrating another method for dynamically adjusting timeout times based on Redis distributed locks, according to an example embodiment;
FIG. 4 is a block diagram illustrating a Redis distributed lock based timeout dynamic adjustment system according to one exemplary embodiment;
FIG. 5 is a block diagram illustrating another Redis distributed lock based timeout dynamic adjustment system according to one exemplary embodiment.
Detailed Description
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the invention. Rather, they are merely examples of apparatus and methods consistent with aspects of the invention as detailed in the accompanying claims.
The implementation environment of the invention can be a portable mobile device, such as a smart phone, a tablet computer, a desktop computer.
FIG. 1 is a schematic diagram illustrating an apparatus for running a Redis distributed lock based timeout dynamic adjustment system according to one exemplary embodiment. The apparatus 100 may be the portable mobile device described above. As shown in fig. 1, the apparatus 100 may include one or more of the following components: a processing component 102, a memory 104, a power supply component 106, a multimedia component 108, an audio component 110, a sensor component 114, and a communication component 116.
The processing component 102 generally controls overall operation of the device 100, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations, among others. The processing component 102 may include one or more processors 118 to execute instructions to perform all or part of the steps of the methods described below. Further, the processing component 102 can include one or more modules to facilitate interactions between the processing component 102 and other components. For example, the processing component 102 may include a multimedia module for facilitating interaction between the multimedia component 108 and the processing component 102.
The memory 104 is configured to store various types of data to support operations at the apparatus 100. Examples of such data include instructions for any application or method operating on the device 100. The Memory 104 may be implemented by any type of volatile or non-volatile Memory device or combination thereof, such as static random access Memory (Static Random Access Memory, SRAM), electrically erasable Programmable Read-Only Memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), erasable Programmable Read-Only Memory (Erasable Programmable Read Only Memory, EPROM), programmable Read-Only Memory (PROM), read-Only Memory (ROM), magnetic Memory, flash Memory, magnetic disk, or optical disk. Also stored in the memory 104 are one or more modules configured to be executed by the one or more processors 118 to perform all or part of the steps in the methods shown below.
The power supply assembly 106 provides power to the various components of the device 100. The power components 106 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for the device 100.
The multimedia component 108 includes a screen between the device 100 and the user that provides an output interface. In some embodiments, the screen may include a liquid crystal display (Liquid Crystal Display, LCD for short) and a touch panel. If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensor may sense not only the boundary of a touch or slide action, but also the duration and pressure associated with the touch or slide operation. The screen may also include an organic electroluminescent display (Organic Light Emitting Display, OLED for short).
The audio component 110 is configured to output and/or input audio signals. For example, the audio component 110 includes a Microphone (MIC) configured to receive external audio signals when the device 100 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may be further stored in the memory 104 or transmitted via the communication component 116. In some embodiments, the audio component 110 further comprises a speaker for outputting audio signals.
The sensor assembly 114 includes one or more sensors for providing status assessment of various aspects of the device 100. For example, the sensor assembly 114 may detect an on/off state of the device 100, a relative positioning of the assemblies, the sensor assembly 114 may also detect a change in position of the device 100 or a component of the device 100, and a change in temperature of the device 100. In some embodiments, the sensor assembly 114 may also include a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 116 is configured to facilitate communication between the apparatus 100 and other devices in a wired or wireless manner. The device 100 may access a Wireless network based on a communication standard, such as WiFi (Wireless-Fidelity). In one exemplary embodiment, the communication component 116 receives broadcast signals or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 116 further includes a near field communication (Near Field Communication, NFC) module for facilitating short range communications. For example, the NFC module may be implemented based on radio frequency identification (Radio Frequency Identification, RFID) technology, infrared data association (Infrared Data Association, irDA) technology, ultra Wideband (UWB) technology, bluetooth technology, and other technologies.
In an exemplary embodiment, the apparatus 100 may be implemented by one or more application specific integrated circuits (Application Specific Integrated Circuit, abbreviated ASIC), digital signal processors, digital signal processing devices, programmable logic devices, field programmable gate arrays, controllers, microcontrollers, microprocessors or other electronic components for executing the methods described below.
FIG. 2 is a flow chart illustrating a method of dynamically adjusting timeout times based on Redis distributed locks, according to an example embodiment. As shown in fig. 2, the method comprises the steps of:
step 201, a dynamic adjustment system obtains a target estimated execution consumption value corresponding to a target service logic based on a timeout time of the Redis distributed lock.
In the embodiment of the invention, the target service logic is a core code part for realizing a certain service function, the target estimated execution consumption value corresponding to the target service logic is an estimated time length value required by the service logic in operation, the target estimated execution consumption value can be obtained in a preset database, or the target estimated execution consumption value input by people can be received, and the like, and the embodiment of the invention is not limited.
Step 202, a timeout time dynamic adjustment system based on Redis distributed locks generates timeout time corresponding to target business logic according to a target estimated execution consumption value and a preset timeout time generation rule.
In the embodiment of the present invention, the preset timeout period generation rule may be a timeout period corresponding to the target service logic generated by multiplying the target estimated execution time consumption value by a certain fixed value, for example, the target estimated execution time consumption value corresponding to the target service logic a may be t, if the fixed value multiplied by the preset timeout period generation rule is 10, the timeout period corresponding to the generated a according to t and the preset timeout period generation rule may be 10×t, if the fixed value multiplied by the preset timeout period generation rule is 8, the timeout period corresponding to the generated a according to t and the preset timeout period generation rule may be 8*t, etc., where the embodiment of the present invention is not limited.
In step 203, when the target service logic performs the locking operation according to the timeout, the timeout dynamic adjustment system based on the Redis distributed lock obtains the target service logic execution start time and the target service logic execution end time corresponding to the target service logic.
In the embodiment of the invention, the target service logic executes the locking operation according to the timeout, namely, only one thread is allowed to execute the method corresponding to the target service logic in the timeout, and the execution start time of the target service logic which starts to be executed can be acquired in the process of executing the method corresponding to the target service logic by the thread, and the execution end time of the target service logic which ends to be executed can also be acquired.
In step 204, the timeout dynamic adjustment system based on the Redis distributed lock determines the time difference between the execution start time and the execution end time of the target service logic as the target execution time consumption of the target service logic.
In the embodiment of the invention, the time difference between the execution start time of the target business logic and the execution end time of the target business logic is the execution end time of the target business logic minus the execution start time of the target business logic, and the time consumption of the target execution reflects the time length value required by the target business logic when running in practical application.
In step 205, the timeout period dynamic adjustment system adjusts the timeout period according to the target execution time consumption based on the Redis distributed lock.
In the embodiment of the invention, the overtime time can be dynamically adjusted according to the time length value required by the target business logic when the target business logic runs in the actual application.
As an alternative embodiment, the dynamic timeout adjustment system based on the Redis distributed lock may adjust the timeout according to the target execution time consumption, including:
and the timeout time dynamic adjustment system based on the Redis distributed lock determines the target execution time consumption as a target estimated execution time consumption value, and executes the timeout time corresponding to the target business logic according to the target estimated execution time consumption value and a preset timeout time generation rule.
By implementing the alternative implementation mode, the target execution time consumption can be determined as the target estimated execution time consumption value, and the step of generating the timeout time corresponding to the target business logic according to the target estimated execution time consumption value and the preset timeout time generation rule is repeatedly executed, so that the dynamic adjustment of the Redis distributed lock timeout time is realized.
For example, the estimated execution time consumption value of the target corresponding to the target service logic a may be t, and the timeout time corresponding to the generation of a according to the t and the preset timeout time generation rule may be 10×t, 8*t, or the like. When the target service logic A executes the locking operation according to the timeout time, the target service logic execution start time and the target service logic execution end time when the target service logic A executes can be obtained, the target service logic execution end time minus the target service logic execution start time is the target execution time t1 of the target service logic, at this time, the timeout time can be adjusted to 10 x 1 or 8 x 1, and the like, and the process can be repeatedly performed, so that the dynamic adjustment of the Redis distributed lock timeout time is realized.
Under the method, based on the distributed storage technology, the target execution time consumption can be determined according to the target service logic execution start time and the target service logic execution end time, and the timeout time is adjusted according to the target execution time consumption, so that the dynamic adjustment of the timeout time is realized, and the applicability of the timeout time is improved.
FIG. 3 is a flowchart illustrating another method for dynamically adjusting timeout times based on Redis distributed locks, according to an example embodiment. As shown in fig. 3, the method comprises the steps of:
step 301, when the service online time length corresponding to the service logic is within the preset time length range, determining estimated execution time consumption corresponding to each service logic according to the execution time consumption by the time-out time dynamic adjustment system based on the Redis distributed lock.
In the embodiment of the invention, whether the service online time length corresponding to the service logic is in the preset time length range can be judged first, because the reliability of the execution time length of the service logic is not high, which is obtained if the service online time length is short, and if the service online time length is in the preset time length range, the reliability of the execution time length of the service logic is higher.
As an optional implementation manner, the determining, by the dynamic timeout period adjustment system based on the Redis distributed lock, the estimated execution time consumption corresponding to each service logic according to the execution time consumption may include:
and determining a plurality of execution time consuming times when each business logic is on line based on the timeout time dynamic adjustment system of the Redis distributed lock, calculating an average value of the plurality of execution time consuming times, and determining the average value as the estimated execution time consuming time corresponding to the business logic.
By implementing the alternative implementation mode, when the service online time length is within the preset time length range, the average value of a plurality of execution time consuming times when each service logic is online can be used as the estimated service logic execution time consuming time, and the method is more accurate.
Step 302, the timeout dynamic adjustment system based on the Redis distributed lock stores each service logic and the estimated execution time corresponding to the service logic in a preset database.
In the embodiment of the invention, the preset database can store various service logics and estimated execution time consumption corresponding to each service logic, if the service corresponding to one service logic is a new service of online, the estimated execution time consumption corresponding to the service logic can be manually set by related responsible personnel, and if the service corresponding to another service logic is an online service which needs to be online again after a certain update is made, the estimated execution time consumption corresponding to the service logic can be automatically generated by the system according to the condition of online service.
Step 303, the timeout period dynamic adjustment system based on the Redis distributed lock queries the target estimated execution time consumption corresponding to the target service logic in the preset database.
In the embodiment of the invention, the target business logic is one or a plurality of business logic in a preset database, and the target estimated execution time consumption is the estimated execution time consumption corresponding to the target business logic in the preset database.
Step 304, the timeout period dynamic adjustment system based on the Redis distributed lock generates the timeout period corresponding to the target business logic according to the target estimated execution consumption value and the preset timeout period generation rule.
Step 305, dynamically adjusting the system record generation time of the timeout time corresponding to the generated target business logic based on the timeout time of the Redis distributed lock.
Step 306, the dynamic adjustment system of timeout time based on Redis distributed lock judges whether the time difference between the current time and the generation time is larger than the preset time difference, if yes, step 307 to step 310 are executed, if no, the flow is ended.
In the embodiment of the invention, because the change of the time consumption of the service logic execution often occurs after a period of time, the time-out time can be adjusted again in a period of time, so that the running quantity is reduced.
Step 307, when the target service logic performs the locking operation according to the timeout, the timeout dynamic adjustment system based on the Redis distributed lock obtains the target service logic execution start time and the target service logic execution end time corresponding to the target service logic.
In step 308, the timeout dynamic adjustment system based on the Redis distributed lock determines the time difference between the execution start time and the execution end time of the target service logic as the target execution time consumption of the target service logic.
Step 309, the timeout period dynamic adjustment system adjusts the timeout period according to the target execution time consumption based on the Redis distributed lock.
As an alternative embodiment, the dynamic timeout adjustment system based on the Redis distributed lock may adjust the timeout according to the target execution time consumption, including:
dynamically adjusting the number of targets for which the system statistics target execution consumes time based on the timeout time of the Redis distributed lock;
when the target number reaches the preset number, the time-out time dynamic adjustment system based on the Redis distributed locks calculates a first average value of time consumption of target execution of the preset number;
the timeout time dynamic adjustment system based on the Redis distributed lock adjusts the timeout time according to the first average value.
As another alternative embodiment, the dynamic timeout adjustment system based on the Redis distributed lock may adjust the timeout according to the target execution time consumption, including:
the time-out time dynamic adjustment system based on the Redis distributed lock obtains the time consumption of target execution in a preset time period;
the method comprises the steps that a time-out time dynamic adjustment system based on a Redis distributed lock calculates a second average value of time consumption of target execution in a preset time period;
the timeout time dynamic adjustment system based on the Redis distributed lock adjusts the timeout time according to the second average value.
In the embodiment of the invention, the time consumption of executing a plurality of targets of the target business logic of the latest worship can be counted, the time consumption of executing 1000 targets of the target business logic of 1000 times can be counted, and the time-out time is adjusted according to the average value of the time consumption.
By implementing the alternative implementation mode, the average value of the target execution time consumption can be calculated according to the times or time according to different service types corresponding to the service logic, so that the time-out time is adjusted according to the average value, and the diversity of time-out time adjustment modes is enhanced.
Step 310, the timeout dynamic adjustment system based on the Redis distributed lock stores the adjusted timeout, the adjusted timeout and the target business logic to the timeout adjustment database.
In the embodiment of the invention, the record for adjusting the timeout time can be stored, so that the subsequent related responsible personnel can predict the change of the timeout time according to the record.
Under the method, based on the distributed storage technology, the target execution time consumption can be determined according to the target service logic execution start time and the target service logic execution end time, and the timeout time is adjusted according to the target execution time consumption, so that the dynamic adjustment of the timeout time is realized, and the applicability of the timeout time is improved.
The following is a system embodiment of the present invention.
FIG. 4 is a block diagram illustrating a Redis distributed lock based timeout dynamic adjustment system according to one exemplary embodiment. As shown in fig. 4, the system includes:
the first obtaining unit 401 is configured to obtain a target estimated execution consumption value corresponding to the target service logic.
In the embodiment of the invention, the target service logic is a core code part for realizing a certain service function, the target estimated execution consumption value corresponding to the target service logic is an estimated time length value required by the service logic in operation, the target estimated execution consumption value can be obtained in a preset database, or the target estimated execution consumption value input by people can be received, and the like, and the embodiment of the invention is not limited.
And the generating unit 402 is configured to generate a timeout time corresponding to the target service logic according to the target estimated execution consumption value and a preset timeout time generation rule.
In the embodiment of the present invention, the preset timeout period generation rule may be a timeout period corresponding to the target service logic generated by multiplying the target estimated execution time consumption value by a certain fixed value, for example, the target estimated execution time consumption value corresponding to the target service logic a may be t, if the fixed value multiplied by the preset timeout period generation rule is 10, the timeout period corresponding to the generated a according to t and the preset timeout period generation rule may be 10×t, if the fixed value multiplied by the preset timeout period generation rule is 8, the timeout period corresponding to the generated a according to t and the preset timeout period generation rule may be 8*t, etc., where the embodiment of the present invention is not limited.
The second obtaining unit 403 is configured to obtain, when the target service logic performs the locking operation according to the timeout time, a target service logic execution start time and a target service logic execution end time corresponding to the target service logic.
In the embodiment of the invention, the target service logic executes the locking operation according to the timeout, namely, only one thread is allowed to execute the method corresponding to the target service logic in the timeout, and the execution start time of the target service logic which starts to be executed can be acquired in the process of executing the method corresponding to the target service logic by the thread, and the execution end time of the target service logic which ends to be executed can also be acquired.
A determining unit 404, configured to determine a time difference between the execution start time of the target service logic and the execution end time of the target service logic as a target execution time consumption of the target service logic.
In the embodiment of the invention, the time difference between the execution start time of the target business logic and the execution end time of the target business logic is the execution end time of the target business logic minus the execution start time of the target business logic, and the time consumption of the target execution reflects the time length value required by the target business logic when running in practical application.
An adjusting unit 405, configured to adjust the timeout period according to the target execution time consumption.
In the embodiment of the invention, the overtime time can be dynamically adjusted according to the time length value required by the target business logic when the target business logic runs in the actual application.
As an alternative embodiment, the adjusting unit 405 may adjust the timeout period according to the target execution elapsed time, which may include:
the adjusting unit 405 determines the target execution time consumption as a target estimated execution time consumption value, and executes the above-mentioned timeout period corresponding to the target business logic generated according to the target estimated execution time consumption value and the preset timeout period generation rule.
By implementing the alternative implementation mode, the target execution time consumption can be determined as the target estimated execution time consumption value, and the step of generating the timeout time corresponding to the target business logic according to the target estimated execution time consumption value and the preset timeout time generation rule is repeatedly executed, so that the dynamic adjustment of the Redis distributed lock timeout time is realized.
For example, the estimated execution time consumption value of the target corresponding to the target service logic a may be t, and the timeout time corresponding to the generation of a according to the t and the preset timeout time generation rule may be 10×t, 8*t, or the like. When the target service logic A executes the locking operation according to the timeout time, the target service logic execution start time and the target service logic execution end time when the target service logic A executes can be obtained, the target service logic execution end time minus the target service logic execution start time is the target execution time t1 of the target service logic, at this time, the timeout time can be adjusted to 10 x 1 or 8 x 1, and the like, and the process can be repeatedly performed, so that the dynamic adjustment of the Redis distributed lock timeout time is realized.
As an alternative embodiment, the adjusting unit 405 may adjust the timeout period according to the target execution elapsed time, which may include:
the adjustment unit 405 counts the number of targets for which the target execution is time-consuming;
when the target number reaches the preset number, the adjusting unit 405 calculates a first average value of the target execution time consumption of the preset number;
the adjustment unit 405 adjusts the timeout according to the first average value.
As another alternative embodiment, the adjusting unit 405 may adjust the timeout period according to the target execution elapsed time, which may include:
the adjusting unit 405 obtains the time consumption of target execution within a preset time period;
the adjustment unit 405 calculates a second average value of the target execution time consumption within a preset period of time;
the adjustment unit 405 adjusts the timeout according to the second average value.
In the embodiment of the invention, the time consumption of executing a plurality of targets of the target business logic of the latest worship can be counted, the time consumption of executing 1000 targets of the target business logic of 1000 times can be counted, and the time-out time is adjusted according to the average value of the time consumption.
By implementing the alternative implementation mode, the average value of the target execution time consumption can be calculated according to the times or time according to different service types corresponding to the service logic, so that the time-out time is adjusted according to the average value, and the diversity of time-out time adjustment modes is enhanced.
It can be seen that, by implementing the dynamic timeout time adjustment system based on the dis distributed lock described in fig. 4, based on the distributed storage technology, the target execution time consumption can be determined according to the target service logic execution start time and the target service logic execution end time, and the timeout time can be adjusted according to the target execution time consumption, so as to dynamically adjust the timeout time, and improve the applicability of the timeout time.
FIG. 5 is a block diagram illustrating another Redis distributed lock based timeout dynamic adjustment system according to one exemplary embodiment. FIG. 5 is an optimized version of FIG. 4, as compared to the Redis-based distributed lock timeout dynamic adjustment system of FIG. 4, in the Redis-based distributed lock timeout dynamic adjustment system of FIG. 5:
the determining unit 404 is further configured to determine, before the first obtaining unit 401 obtains the estimated execution time consumption value of the target corresponding to the target service logic, when the service online time length corresponding to the service logic is within the preset time length range, the estimated execution time consumption corresponding to each service logic according to the execution time consumption.
In the embodiment of the invention, whether the service online time length corresponding to the service logic is in the preset time length range can be judged first, because the reliability of the execution time length of the service logic is not high, which is obtained if the service online time length is short, and if the service online time length is in the preset time length range, the reliability of the execution time length of the service logic is higher.
As an alternative embodiment, the determining unit 404 may determine the estimated execution time consumption corresponding to each business logic according to the execution time consumption, which may include:
the determining unit 404 determines a number of execution time consuming times when each business logic is online, calculates an average value of the number of execution time consuming times, and determines the average value as an estimated execution time consuming time corresponding to the business logic.
By implementing the alternative implementation mode, when the service online time length is within the preset time length range, the average value of a plurality of execution time consuming times when each service logic is online can be used as the estimated service logic execution time consuming time, and the method is more accurate.
And the storage unit 406 is configured to store each service logic and the estimated execution time consumption corresponding to the service logic in a preset database.
In the embodiment of the invention, the preset database can store various service logics and estimated execution time consumption corresponding to each service logic, if the service corresponding to one service logic is a new service of online, the estimated execution time consumption corresponding to the service logic can be manually set by related responsible personnel, and if the service corresponding to another service logic is an online service which needs to be online again after a certain update is made, the estimated execution time consumption corresponding to the service logic can be automatically generated by the system according to the condition of online service.
Optionally, in the Redis distributed lock-based timeout dynamic adjustment system shown in FIG. 5:
the manner in which the first obtaining unit 401 is configured to obtain the target estimated execution consumption value corresponding to the target service logic is specifically:
the first obtaining unit 401 is configured to query a preset database for time consumption of target prediction execution corresponding to the target business logic.
In the embodiment of the invention, the target business logic is one or a plurality of business logic in a preset database, and the target estimated execution time consumption is the estimated execution time consumption corresponding to the target business logic in the preset database.
Optionally, the dynamic timeout period adjustment system based on the Redis distributed lock shown in fig. 5 may further include:
a recording unit 407, configured to record, after the generating unit 402 generates the timeout time corresponding to the target service logic according to the target estimated execution consumption value and the preset timeout time generating rule, a generating time for generating the timeout time corresponding to the target service logic.
The judging unit 408 is configured to judge whether the time difference between the current time and the generation time is greater than a preset time difference.
In the embodiment of the invention, because the change of the time consumption of the service logic execution often occurs after a period of time, the time-out time can be adjusted again in a period of time, so that the running quantity is reduced.
The second obtaining unit 403 is specifically configured to obtain, when the judging unit 408 judges that the time difference between the current time and the generated time is greater than the preset time difference, a target service logic execution start time and a target service logic execution end time corresponding to the target service logic when the target service logic performs the locking operation according to the timeout time.
The storage unit 406 is further configured to store the adjusted timeout period, the adjusted timeout period for adjusting the timeout period, and the target business logic in the timeout period adjustment database after the adjustment unit 405 adjusts the timeout period according to the target execution time consumption.
In the embodiment of the invention, the record for adjusting the timeout time can be stored, so that the subsequent related responsible personnel can predict the change of the timeout time according to the record.
It can be seen that, by implementing the dynamic timeout time adjustment system based on the dis distributed lock described in fig. 5, based on the distributed storage technology, the target execution time consumption can be determined according to the target service logic execution start time and the target service logic execution end time, and the timeout time can be adjusted according to the target execution time consumption, so as to dynamically adjust the timeout time, and improve the applicability of the timeout time.
The invention also provides an electronic device, comprising:
a processor;
and a memory having stored thereon computer readable instructions which, when executed by the processor, implement a method of dynamically adjusting timeout time based on Redis distributed locks as previously described.
The electronic device may be the apparatus 100 shown in fig. 1 running a dis distributed lock based timeout dynamic adjustment system.
In an exemplary embodiment, the present invention also provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a Redis distributed lock-based timeout dynamic adjustment system as previously described.
It is to be understood that the invention is not limited to the precise arrangements and instrumentalities shown in the drawings, which have been described above, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the invention is limited only by the appended claims.

Claims (8)

1. A method for dynamically adjusting timeout time based on a dis distributed lock, the method comprising:
when the service online time length corresponding to the service logic is within a preset time length range, determining estimated execution time consumption corresponding to each service logic according to the execution time consumption corresponding to each service logic;
when the service corresponding to the service logic is the service newly on line, the estimated execution time consumption corresponding to the service logic is manually set by a responsible person;
storing each business logic and the estimated execution time consumption corresponding to the business logic to a preset database correspondingly;
inquiring target estimated execution time consumption corresponding to target business logic in the preset database;
generating timeout time corresponding to the target business logic according to the target estimated execution timeout value and a preset timeout time generation rule;
when the target service logic executes locking operation according to the timeout time, acquiring target service logic execution start time and target service logic execution end time corresponding to the target service logic;
determining a time difference value between the execution start time and the execution end time of the target business logic as the target execution time consumption of the target business logic;
and adjusting the timeout time according to the target execution time consumption.
2. The method of claim 1, wherein after the generating the timeout period corresponding to the target business logic according to the target estimated execution consumption value and a preset timeout period generation rule, the method further comprises:
recording the generation time of the timeout time corresponding to the target business logic;
judging whether the time difference between the current time and the generation time is larger than a preset time difference or not;
and if so, executing the target service logic, and acquiring the execution start time and the execution end time of the target service logic corresponding to the target service logic when the target service logic executes the locking operation according to the timeout time.
3. The method according to any one of claims 1 to 2, wherein after said adjusting said timeout time according to said target execution elapsed time, said method further comprises:
storing the adjusted timeout time, the adjusted time for adjusting the timeout time and the target business logic into a timeout time adjustment database.
4. A method according to claim 3, wherein said adjusting said timeout period according to said target execution time consumption comprises:
counting the number of targets consuming time for the target execution;
when the target number reaches a preset number, calculating a first average value of time consuming for executing the target in the preset number;
and adjusting the timeout time according to the first average value.
5. A method according to claim 3, wherein said adjusting said timeout period according to said target execution time consumption comprises:
acquiring the time consumption of the target execution within a preset time period;
calculating a second average value of the time consumption of the target execution in the preset time period;
and adjusting the timeout time according to the second average value.
6. A system for dynamically adjusting timeout time based on a dis distributed lock, the system comprising:
the determining unit is used for determining estimated execution time consumption corresponding to each business logic according to the execution time consumption corresponding to each business logic when the business online time length corresponding to the business logic is within a preset time length range;
the storage unit is used for setting the estimated execution time consumption corresponding to the service logic manually by responsible personnel when the service corresponding to the service logic is a new online service;
storing each business logic and the estimated execution time consumption corresponding to the business logic to a preset database correspondingly;
the first acquisition unit is used for inquiring target estimated execution time consumption corresponding to target business logic in the preset database;
the generation unit is used for generating timeout time corresponding to the target business logic according to the target estimated execution timeout value and a preset timeout time generation rule;
the second acquisition unit is used for acquiring target service logic execution start time and target service logic execution end time corresponding to the target service logic when the target service logic executes locking operation according to the timeout time;
a determining unit, configured to determine a time difference between the execution start time of the target service logic and the execution end time of the target service logic as a target execution time consumption of the target service logic;
and the adjusting unit is used for adjusting the timeout time according to the target execution time consumption.
7. An electronic device, the electronic device comprising:
a processor;
a memory having stored thereon computer readable instructions which, when executed by the processor, implement the method of any of claims 1 to 5.
8. A computer-readable storage medium, characterized in that it stores a computer program that causes a computer to execute the method of any one of claims 1 to 5.
CN201910318260.6A 2019-04-19 2019-04-19 Redis distributed lock-based timeout time dynamic adjustment method and system Active CN110162384B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201910318260.6A CN110162384B (en) 2019-04-19 2019-04-19 Redis distributed lock-based timeout time dynamic adjustment method and system
PCT/CN2019/120964 WO2020211382A1 (en) 2019-04-19 2019-11-26 Dynamic timeout period adjustment method and system for redis-based distributed lock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910318260.6A CN110162384B (en) 2019-04-19 2019-04-19 Redis distributed lock-based timeout time dynamic adjustment method and system

Publications (2)

Publication Number Publication Date
CN110162384A CN110162384A (en) 2019-08-23
CN110162384B true CN110162384B (en) 2023-04-28

Family

ID=67638684

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910318260.6A Active CN110162384B (en) 2019-04-19 2019-04-19 Redis distributed lock-based timeout time dynamic adjustment method and system

Country Status (2)

Country Link
CN (1) CN110162384B (en)
WO (1) WO2020211382A1 (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110162384B (en) * 2019-04-19 2023-04-28 深圳壹账通智能科技有限公司 Redis distributed lock-based timeout time dynamic adjustment method and system
CN110768861B (en) * 2019-09-20 2021-07-06 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for obtaining overtime threshold
CN112732538B (en) * 2019-10-28 2023-10-13 腾讯科技(深圳)有限公司 Panel performance analysis method, device, terminal and storage medium
CN110784478B (en) * 2019-10-31 2024-04-30 深圳前海微众银行股份有限公司 Method, device, equipment and computer readable storage medium for adjusting timeout duration
CN111405015B (en) * 2020-03-09 2022-09-30 中国建设银行股份有限公司 Data processing method, device, equipment and storage medium
CN113282580A (en) * 2021-04-28 2021-08-20 青岛海尔科技有限公司 Method, storage medium and server for executing timed task
CN113238862B (en) * 2021-05-13 2024-04-16 京东科技控股股份有限公司 Distributed task scheduling method and device
CN113824603B (en) * 2021-11-25 2022-02-08 天津众颐科技有限责任公司 Dynamic configuration method for overtime time when front-end calls micro-service interface
CN114115751B (en) * 2022-01-25 2022-04-19 苏州浪潮智能科技有限公司 Automatic operation time consumption monitoring method and system for large-scale distributed storage

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106250178A (en) * 2016-07-26 2016-12-21 北京北森云计算股份有限公司 The method that system dynamics function intercepts extension online is realized by the compiling of multilingual cloud
CN106446037A (en) * 2016-08-31 2017-02-22 南威软件股份有限公司 Method for realizing consistency of Redis and MYSQL data based on distributed lock
CN106776816A (en) * 2016-11-24 2017-05-31 北京小米移动软件有限公司 Locking method and device
CN106951431A (en) * 2016-12-16 2017-07-14 华南理工大学 A kind of cluster monitoring collecting method
CN107133369A (en) * 2017-06-16 2017-09-05 郑州云海信息技术有限公司 A kind of distributed reading shared buffer memory aging method based on the expired keys of redis
CN108694075A (en) * 2017-04-12 2018-10-23 北京京东尚科信息技术有限公司 Handle method, apparatus, electronic equipment and the readable storage medium storing program for executing of report data
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium

Family Cites Families (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8972488B2 (en) * 2010-09-28 2015-03-03 Redis Labs Ltd. System, methods, and media for providing in-memory non-relational databases
WO2013078269A1 (en) * 2011-11-22 2013-05-30 Solano Labs, Inc. System of distributed software quality improvement
CN104462447B (en) * 2014-12-15 2018-04-03 北京国双科技有限公司 Access the data processing method and device of time-out
CN107368498B (en) * 2016-05-13 2020-08-04 阿里巴巴集团控股有限公司 Method and device for optimizing lock waiting timeout of MySQ L pessimistic lock
CN106131186A (en) * 2016-07-15 2016-11-16 国网河北省电力公司电力科学研究院 A kind of power information acquisition interface adjustment method based on Redis distributed caching
CN106293954A (en) * 2016-08-08 2017-01-04 浪潮(北京)电子信息产业有限公司 A kind of High Availabitity service management based on distributed lock
CN106445648A (en) * 2016-10-21 2017-02-22 天津海量信息技术股份有限公司 System for achieving multi-worker coordination based on redis
CN106776720A (en) * 2016-11-18 2017-05-31 北京奇虎科技有限公司 A kind of document handling method and device
CN108287854B (en) * 2017-01-10 2021-06-22 网宿科技股份有限公司 Method and system for data persistence in stream calculation
US10613944B2 (en) * 2017-04-18 2020-04-07 Netapp, Inc. Systems and methods for backup and restore of distributed master-slave database clusters
CN108512716B (en) * 2018-02-07 2020-07-28 深圳壹账通智能科技有限公司 Method, system, computer device and storage medium for reporting device information
CN108920264B (en) * 2018-06-12 2020-08-28 深圳市德明利技术股份有限公司 Command timeout processing method and system
CN109144700B (en) * 2018-09-03 2022-09-23 创新先进技术有限公司 Method and device for determining timeout duration, server and data processing method
CN109558218A (en) * 2018-12-04 2019-04-02 山东浪潮通软信息科技有限公司 A kind of distributed service data lock implementation method based on Redis
CN110162384B (en) * 2019-04-19 2023-04-28 深圳壹账通智能科技有限公司 Redis distributed lock-based timeout time dynamic adjustment method and system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106250178A (en) * 2016-07-26 2016-12-21 北京北森云计算股份有限公司 The method that system dynamics function intercepts extension online is realized by the compiling of multilingual cloud
CN106446037A (en) * 2016-08-31 2017-02-22 南威软件股份有限公司 Method for realizing consistency of Redis and MYSQL data based on distributed lock
CN106776816A (en) * 2016-11-24 2017-05-31 北京小米移动软件有限公司 Locking method and device
CN106951431A (en) * 2016-12-16 2017-07-14 华南理工大学 A kind of cluster monitoring collecting method
CN108694075A (en) * 2017-04-12 2018-10-23 北京京东尚科信息技术有限公司 Handle method, apparatus, electronic equipment and the readable storage medium storing program for executing of report data
CN107133369A (en) * 2017-06-16 2017-09-05 郑州云海信息技术有限公司 A kind of distributed reading shared buffer memory aging method based on the expired keys of redis
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium

Also Published As

Publication number Publication date
CN110162384A (en) 2019-08-23
WO2020211382A1 (en) 2020-10-22

Similar Documents

Publication Publication Date Title
CN110162384B (en) Redis distributed lock-based timeout time dynamic adjustment method and system
CN109857551B (en) Service resource scheduling method and device based on cloud computing and electronic equipment
CN110045965B (en) Application management method and mobile terminal
US9377839B2 (en) Dynamic battery management
US11683396B2 (en) Efficient context monitoring
US10671131B2 (en) Predictive control systems and methods
CN110471763B (en) Scheduling method, system, medium and electronic equipment based on shared object pool
CN113365106B (en) Multimedia resource generation method and device, electronic equipment and storage medium
US20130055273A1 (en) Terminal and application management method thereof
US20180260298A1 (en) Method and Device for Reporting Mobile Terminal Behaviors
KR20130024801A (en) Terminal and method for managing application thereof
CN104601675A (en) Server load balancing method and device
CN108538258B (en) Method and device for adjusting backlight current and display equipment
CN107885307B (en) Equipment control method and device
CN108038050B (en) Performance adjusting method and device, storage medium and electronic equipment
CN106921733B (en) Cluster notification pushing method and device and electronic equipment
CN110046095B (en) System integration method and device based on test flow improvement
CN113344367A (en) Equipment load adjusting method, device, equipment, storage medium and product
CN108737523B (en) Method and device for associating application module with account, hardware device and medium
CN106686702B (en) Network connection processing method and terminal
CN107894902B (en) Equipment control method and device
CN110365734B (en) Request processing method and device when server-side interface is abnormal
CN115793837A (en) Power consumption acquisition method and device, electronic equipment and storage medium
CN115796497A (en) Task allocation method and device, electronic equipment and readable storage medium
CN115114029A (en) Abnormal file positioning method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 201, room 518000, building A, No. 1, front Bay Road, Qianhai Shenzhen Guangdong Shenzhen Hong Kong cooperation zone (Qianhai business secretary)

Applicant after: ONECONNECT FINANCIAL TECHNOLOGY Co.,Ltd. (SHANGHAI)

Address before: 518000 Guangdong city of Shenzhen province Qianhai Shenzhen Hong Kong cooperation zone before Bay Road No. 1 building 201 room A

Applicant before: ONECONNECT FINANCIAL TECHNOLOGY Co.,Ltd. (SHANGHAI)

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant