WO2020211382A1 - 基于Redis分布式锁的超时时间动态调整方法及系统 - Google Patents

基于Redis分布式锁的超时时间动态调整方法及系统 Download PDF

Info

Publication number
WO2020211382A1
WO2020211382A1 PCT/CN2019/120964 CN2019120964W WO2020211382A1 WO 2020211382 A1 WO2020211382 A1 WO 2020211382A1 CN 2019120964 W CN2019120964 W CN 2019120964W WO 2020211382 A1 WO2020211382 A1 WO 2020211382A1
Authority
WO
WIPO (PCT)
Prior art keywords
time
target
business logic
execution
timeout
Prior art date
Application number
PCT/CN2019/120964
Other languages
English (en)
French (fr)
Inventor
段火强
Original Assignee
深圳壹账通智能科技有限公司
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 深圳壹账通智能科技有限公司 filed Critical 深圳壹账通智能科技有限公司
Publication of WO2020211382A1 publication Critical patent/WO2020211382A1/zh

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

Definitions

  • This application relates to the field of distributed storage technology, and in particular to a method and system for dynamically adjusting the timeout time based on Redis distributed locks.
  • a common way to set the timeout period is to estimate the execution time of the business logic in advance, and then set the timeout period of the distributed lock based on the estimated time to execute the business logic in advance.
  • the execution time of business logic will become longer and longer. Since the timeout time cannot be dynamically adjusted, there may be cases where the execution time of business logic exceeds the previously set timeout time. This leads to premature failure of distributed locks, which in turn affects the data consistency when multiple threads access shared resources.
  • this application provides a method and system for dynamically adjusting the timeout period based on Redis distributed lock .
  • the first aspect of the embodiments of the present application discloses a method for dynamically adjusting the timeout time based on Redis distributed lock, and the method includes:
  • the timeout period is adjusted according to the target execution time.
  • the second aspect of the embodiments of the present application discloses a system for dynamically adjusting the timeout time based on Redis distributed locks, and the system includes:
  • the first obtaining unit is used to obtain the estimated execution time-consuming value of the target corresponding to the target business logic
  • a generating unit configured to generate a timeout time corresponding to the target business logic according to the target estimated execution time-consuming value and a preset timeout time generation rule
  • the second acquiring unit is configured to acquire the target business logic execution start time and target business logic execution end time corresponding to the target business logic when the target business logic executes the lock operation according to the timeout period;
  • a determining unit configured to determine the time difference between the execution start time of the target business logic and the execution end time of the target business logic as the target execution time of the target business logic
  • the adjustment unit is configured to adjust the timeout time according to the time-consuming execution of the target.
  • an electronic device in a third aspect of the embodiments of the present application, includes:
  • a memory where computer-readable instructions are stored, and when the computer-readable instructions are executed by the processor, the method as described above is implemented.
  • the fourth aspect of the embodiments of the present application discloses a computer-readable storage medium that stores a computer program, and the computer program enables a computer to execute the aforementioned method.
  • the computer-readable storage medium may be a non-volatile computer-readable storage medium.
  • the embodiments of the application are based on distributed storage technology, and the target execution time can be determined according to the target business logic execution start time and the target business logic execution end time, and the timeout period can be adjusted according to the target execution time, so as to achieve dynamic timeout Adjust to improve the applicability of the timeout period.
  • Fig. 1 is a schematic diagram showing a device for running a system for dynamically adjusting the timeout time based on a Redis distributed lock according to an exemplary embodiment
  • Fig. 2 is a flow chart showing a method for dynamically adjusting timeout time based on Redis distributed locks according to an exemplary embodiment
  • Fig. 3 is a flow chart showing another method for dynamically adjusting the timeout time based on Redis distributed lock according to an exemplary embodiment
  • Fig. 4 is a block diagram showing a system for dynamically adjusting timeout time based on Redis distributed locks according to an exemplary embodiment
  • Fig. 5 is a block diagram showing another system for dynamically adjusting a timeout time based on a Redis distributed lock according to an exemplary embodiment.
  • the implementation environment of this application can be portable mobile devices, such as smart phones, tablet computers, and desktop computers.
  • Fig. 1 is a schematic diagram of an apparatus for running a system for dynamically adjusting a timeout time based on a Redis distributed lock according to an exemplary embodiment.
  • the apparatus 100 may be the aforementioned portable mobile device.
  • the device 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 the overall operations of the device 100, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations.
  • the processing component 102 may include one or more processors 118 to execute instructions to complete all or part of the steps of the following method.
  • the processing component 102 may include one or more modules to facilitate the interaction between the processing component 102 and other components.
  • the processing component 102 may include a multimedia module to facilitate the 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 in the device 100. Examples of these data include instructions for any application or method operating on the device 100.
  • the memory 104 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, SRAM for short), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory) Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-only memory ( Read-Only Memory, ROM for short), magnetic storage, flash memory, magnetic disk or optical disk.
  • the memory 104 also stores one or more modules, and the one or more modules are configured to be executed by the one or more processors 118 to complete all or part of the steps in the method shown below.
  • the power supply component 106 provides power to various components of the device 100.
  • the power supply component 106 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 100.
  • the multimedia component 108 includes a screen that provides an output interface between the device 100 and the user.
  • 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 the user.
  • the touch panel includes one or more touch sensors to sense touch, sliding, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure related to the touch or slide operation.
  • the screen may also include an organic electroluminescence display (Organic Light Emitting Display, OLED for short).
  • the audio component 110 is configured to output and/or input audio signals.
  • the audio component 110 includes a microphone (Microphone, MIC for short).
  • the microphone is configured to receive external audio signals.
  • the received audio signal can be further stored in the memory 104 or sent via the communication component 116.
  • the audio component 110 further includes a speaker for outputting audio signals.
  • the sensor component 114 includes one or more sensors for providing the device 100 with various aspects of state evaluation.
  • the sensor component 114 can detect the open/close state of the device 100 and the relative positioning of components.
  • the sensor component 114 can also detect the position change of the device 100 or a component of the device 100 and the temperature change of the device 100.
  • the sensor component 114 may also include a magnetic sensor, a pressure sensor or a temperature sensor.
  • the communication component 116 is configured to facilitate wired or wireless communication between the apparatus 100 and other devices.
  • the device 100 can access a wireless network based on a communication standard, such as WiFi (Wireless-Fidelity, wireless fidelity).
  • the communication component 116 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel.
  • the communication component 116 further includes a near field communication (Near Field Communication, NFC for short) module to facilitate short-range communication.
  • the NFC module can be based on Radio Frequency Identification (RFID) technology, Infrared Data Association (Infrared Data Association, IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth technology and other technologies. .
  • RFID Radio Frequency Identification
  • IrDA Infrared Data Association
  • UWB Ultra Wideband
  • the apparatus 100 may be implemented by one or more Application Specific Integrated Circuits (ASIC for short), digital signal processors, digital signal processing equipment, programmable logic devices, field programmable gate arrays, The controller, microcontroller, microprocessor or other electronic components are implemented to perform the following methods.
  • ASIC Application Specific Integrated Circuits
  • digital signal processors digital signal processing equipment
  • programmable logic devices programmable logic devices
  • field programmable gate arrays The controller, microcontroller, microprocessor or other electronic components are implemented to perform the following methods.
  • Fig. 2 is a flow chart showing a method for dynamically adjusting the timeout time based on Redis distributed locks according to an exemplary embodiment. As shown in Figure 2, this method includes the following steps:
  • Step 201 Based on the timeout time of the Redis distributed lock, dynamically adjust the system to obtain the target estimated execution time consumption value corresponding to the target business logic.
  • the target business logic is the core code part that realizes a certain business function
  • the estimated execution time of the target corresponding to the target business logic is the estimated time required for the business logic to run
  • the target execution is estimated
  • the time-consuming value may be obtained in a preset database, or may also receive a human-inputted target estimated execution time-consuming value, etc., which is not limited in the embodiment of the present application.
  • Step 202 Based on the timeout time of the Redis distributed lock, the system dynamically adjusts the timeout time corresponding to the target business logic according to the target estimated execution time-consuming value and the preset timeout time generation rule.
  • the preset timeout time generation rule may be to multiply the target estimated execution time-consuming value by a certain fixed value to generate the timeout time corresponding to the target business logic, for example, the target estimation corresponding to the target business logic A
  • the execution time can be t. If the fixed value multiplied by the preset timeout time generation rule is 10, the timeout time corresponding to A generated according to t and the preset timeout time generation rule can be 10*t.
  • the timeout time corresponding to A generated according to t and the preset timeout time generation rule may also be 8*t, etc., which is not limited in the embodiment of the present application.
  • Step 203 When the target business logic performs the locking operation according to the timeout period, the system dynamically adjusts the timeout period of the Redis distributed lock to obtain the target business logic execution start time and target business logic execution end time corresponding to the target business logic.
  • the target business logic performs the lock operation according to the timeout period, that is, only one thread is allowed to execute the method corresponding to the target business logic within the timeout period, and it can be obtained during the process of executing the method corresponding to the target business logic by the thread
  • the execution start time of the target business logic to start execution, and the end time of the target business logic execution to end the execution can also be obtained.
  • Step 204 Based on the timeout time of the Redis distributed lock, the dynamic adjustment system determines the time difference between the execution start time of the target business logic and the execution end time of the target business logic as the target execution time of the target business logic.
  • 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 target business logic execution end time minus the target business logic execution start time
  • the target execution time reflects the target business logic execution time The length of time required for running in actual applications.
  • Step 205 Based on the timeout time of the Redis distributed lock, the system dynamically adjusts the timeout time according to the target execution time.
  • the timeout period can be dynamically adjusted according to the duration value required when the target business logic runs in the actual application.
  • the dynamic adjustment system based on the timeout time of the Redis distributed lock according to the target execution time to adjust the timeout time may include:
  • the dynamic adjustment system based on the timeout time of Redis distributed lock determines the target execution time as the target estimated execution time value, and executes the above-mentioned estimated execution time value based on the target and the preset timeout time generation rule to generate the target business logic corresponding The timeout period.
  • the target execution time can be determined as the target estimated execution time consumption value, and the target business logic corresponding to the target business logic can be generated according to the target estimated execution time consumption value and the preset timeout time generation rule.
  • the step of timeout time so as to realize the dynamic adjustment of the timeout time of Redis distributed lock.
  • the estimated execution time-consuming value of the target corresponding to the target business logic A can be t
  • the timeout period corresponding to A generated according to t and the preset timeout time generation rule can be 10*t, or 8*t, etc. .
  • the target business logic execution start time and target business logic execution end time when A is executed can be obtained.
  • the target business logic execution end time minus the target business logic execution start time is The target execution for the target business logic takes time t1.
  • the timeout period can be adjusted to 10*t1 or 8*t1, etc. This process can be repeated to realize the dynamic adjustment of the Redis distributed lock timeout time.
  • the target execution time can be determined according to the target business logic execution start time and the target business logic execution end time, and the timeout period can be adjusted according to the target execution time consumption to achieve dynamic adjustment of the timeout time , Improve the applicability of the timeout period.
  • Fig. 3 is a flowchart showing another method for dynamically adjusting a timeout time based on a Redis distributed lock according to an exemplary embodiment. As shown in Figure 3, this method includes the following steps:
  • Step 301 When the business online time corresponding to the business logic is within the preset time range, the system dynamically adjusts the timeout time based on the Redis distributed lock to determine the estimated execution time corresponding to each business logic according to the execution time.
  • the business online duration corresponding to the business logic is in the preset duration range. This is because if the business online duration is short, the credibility of the execution duration of the acquired business logic is not high. The duration is within the preset duration range, indicating that the execution duration of the business logic is highly reliable.
  • the dynamic adjustment system based on the timeout time of the Redis distributed lock determines the estimated execution time corresponding to each business logic according to the execution time, which may include:
  • the dynamic adjustment system based on the timeout time of the Redis distributed lock determines the execution time of each business logic when it goes online, calculates the average of the execution time, and determines the average as the estimated execution time corresponding to the business logic .
  • the average value of the execution time for each business logic is taken as the estimated business logic execution time, which is more accurate.
  • Step 302 Based on the timeout time of the Redis distributed lock, the dynamic adjustment system stores the estimated execution time corresponding to each business logic and the business logic in a preset database.
  • the preset database can store various business logics and the estimated execution time corresponding to each business logic. If the business corresponding to a certain business logic is a newly launched business, the preset database corresponding to the business logic The estimated execution time can be manually set by the relevant person in charge. If the business corresponding to another business logic is already online and needs to be re-launched after a certain update, the estimated execution time corresponding to the business logic can be set by the system according to the business online The situation is automatically generated.
  • Step 303 Based on the timeout time of the Redis distributed lock, the system dynamically adjusts the estimated execution time for the target corresponding to the target business logic in the preset database.
  • the target business logic is one or several business logics among several business logics in the preset database
  • the estimated execution time of the target is the estimated execution time corresponding to the target business logic in the preset database
  • Step 304 Based on the timeout time of the Redis distributed lock, the system dynamically adjusts the timeout time corresponding to the target business logic according to the target estimated execution time-consuming value and the preset timeout time generation rule.
  • Step 305 Based on the timeout time of the Redis distributed lock, dynamically adjust the generation time of the timeout time corresponding to the target business logic generated by the system record.
  • Step 306 Based on the timeout time of the Redis distributed lock, the system dynamically adjusts to determine whether the time difference between the current time and the generation time is greater than the preset time difference. If yes, execute step 307 to step 310, if not, end this process.
  • the timeout period can be adjusted after a certain period of time to reduce the amount of operation.
  • Step 307 When the target business logic executes the lock operation according to the timeout period, the system dynamically adjusts the timeout period of the Redis distributed lock to obtain the target business logic execution start time and target business logic execution end time corresponding to the target business logic.
  • Step 308 Based on the timeout time of the Redis distributed lock, the dynamic adjustment system determines the time difference between the execution start time of the target business logic and the execution end time of the target business logic as the target execution time of the target business logic.
  • Step 309 Based on the timeout time of the Redis distributed lock, the system dynamically adjusts the timeout time according to the target execution time.
  • the dynamic adjustment system based on the timeout time of Redis distributed locks adjusting the timeout time according to the target execution time consumption may include:
  • the timeout time dynamic adjustment system based on Redis distributed lock adjusts the timeout time according to the first average value.
  • the dynamic adjustment system based on the timeout time of the Redis distributed lock according to the target execution time to adjust the timeout time may include:
  • the system dynamically adjusts the second average value of the target execution time within the preset time period
  • the dynamic adjustment system Based on the timeout time of Redis distributed lock, the dynamic adjustment system adjusts the timeout time according to the second average value.
  • the execution time of several targets of the target business logic in the last week can be counted, or the execution time of 1000 targets of the target business logic can be counted 1000 times, and the timeout time can be adjusted according to the average value.
  • step 310 the system dynamically adjusts the timeout time based on the Redis distributed lock and stores the adjusted timeout time, the adjustment time of the adjusted timeout time, and the target business logic in the timeout time adjustment database.
  • the record of adjusting the timeout period can be stored, so that the relevant responsible personnel can predict the change of the timeout period based on the record.
  • the target execution time can be determined according to the target business logic execution start time and the target business logic execution end time, and the timeout period can be adjusted according to the target execution time consumption to achieve dynamic adjustment of the timeout time , Improve the applicability of the timeout period.
  • Fig. 4 is a block diagram showing a system for dynamically adjusting the timeout time based on Redis distributed locks according to an exemplary embodiment. As shown in Figure 4, the system includes:
  • the first obtaining unit 401 is configured to obtain the estimated execution time-consuming value of the target corresponding to the target business logic.
  • the target business logic is the core code part that realizes a certain business function
  • the estimated execution time of the target corresponding to the target business logic is the estimated time required for the business logic to run
  • the target execution is estimated
  • the time-consuming value may be obtained in a preset database, or may also receive a human-inputted target estimated execution time-consuming value, etc., which is not limited in the embodiment of the present application.
  • the generating unit 402 is configured to generate a timeout time corresponding to the target business logic according to the target estimated execution time-consuming value and the preset timeout time generation rule.
  • the preset timeout time generation rule may be to multiply the target estimated execution time-consuming value by a certain fixed value to generate the timeout time corresponding to the target business logic, for example, the target estimation corresponding to the target business logic A
  • the execution time can be t. If the fixed value multiplied by the preset timeout time generation rule is 10, the timeout time corresponding to A generated according to t and the preset timeout time generation rule can be 10*t.
  • the timeout time corresponding to A generated according to t and the preset timeout time generation rule may also be 8*t, etc., which is not limited in the embodiment of the present application.
  • the second acquiring unit 403 is configured to acquire the target business logic execution start time and target business logic execution end time corresponding to the target business logic when the target business logic executes the lock operation according to the timeout period.
  • the target business logic performs the lock operation according to the timeout period, that is, only one thread is allowed to execute the method corresponding to the target business logic within the timeout period, and it can be obtained during the process of executing the method corresponding to the target business logic by the thread
  • the execution start time of the target business logic to start execution, and the end time of the target business logic execution to end the execution can also be obtained.
  • the determining unit 404 is configured to determine the time difference between the execution start time of the target business logic and the execution end time of the target business logic as the target execution time of the target business logic.
  • 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 target business logic execution end time minus the target business logic execution start time
  • the target execution time reflects the target business logic execution time The length of time required for running in actual applications.
  • the adjusting unit 405 is configured to adjust the timeout time according to the target execution time.
  • the timeout period can be dynamically adjusted according to the duration value required when the target business logic runs in the actual application.
  • the adjusting unit 405 adjusting the timeout period according to the target execution time consumption may include:
  • the adjustment unit 405 determines the target execution time as the target estimated execution time consumption value, and executes the above-mentioned timeout time corresponding to the target business logic generation rule based on the target estimated execution time consumption value and the preset timeout time generation rule.
  • the target execution time can be determined as the target estimated execution time consumption value, and the target business logic corresponding to the target business logic can be generated according to the target estimated execution time consumption value and the preset timeout time generation rule.
  • the step of timeout time so as to realize the dynamic adjustment of the timeout time of Redis distributed lock.
  • the estimated execution time-consuming value of the target corresponding to the target business logic A can be t
  • the timeout period corresponding to A generated according to t and the preset timeout time generation rule can be 10*t, or 8*t, etc. .
  • the target business logic execution start time and target business logic execution end time when A is executed can be obtained.
  • the target business logic execution end time minus the target business logic execution start time is The target execution for the target business logic takes time t1.
  • the timeout period can be adjusted to 10*t1 or 8*t1, etc. This process can be repeated to realize the dynamic adjustment of the Redis distributed lock timeout time.
  • the adjusting unit 405 adjusting the timeout period according to the target execution time consumption may include:
  • the adjustment unit 405 counts the number of time-consuming targets for target execution
  • the adjustment unit 405 calculates the first average value of the preset number of target execution time
  • the adjusting unit 405 adjusts the timeout time according to the first average value.
  • the adjusting unit 405 adjusting the timeout period according to the target execution time consumption may include:
  • the adjustment unit 405 obtains the target execution time consumption within a preset time period
  • the adjustment unit 405 calculates the second average value of the target execution time within the preset time period
  • the adjusting unit 405 adjusts the timeout time according to the second average value.
  • the execution time of several targets of the target business logic in the last week can be counted, or the execution time of 1000 targets of the target business logic can be counted 1000 times, and the timeout time can be adjusted according to the average value.
  • the target execution time can be determined according to the target business logic execution start time and target business logic execution end time, and according to Target execution takes time to adjust the timeout period, so as to achieve dynamic adjustment of the timeout period and improve the applicability of the timeout period.
  • Fig. 5 is a block diagram showing another system for dynamically adjusting a timeout time based on a Redis distributed lock according to an exemplary embodiment.
  • Figure 5 is optimized on the basis of Figure 4. Compared with the timeout dynamic adjustment system based on Redis distributed lock shown in Figure 4, in the timeout dynamic adjustment system based on Redis distributed lock shown in Figure 5 :
  • the determining unit 404 is further configured to determine each time according to the execution time when the business online duration corresponding to the business logic is within the preset time range before the first acquiring unit 401 acquires the estimated execution time value corresponding to the target business logic.
  • the estimated execution time corresponding to a business logic is further configured to determine each time according to the execution time when the business online duration corresponding to the business logic is within the preset time range before the first acquiring unit 401 acquires the estimated execution time value corresponding to the target business logic. The estimated execution time corresponding to a business logic.
  • the business online time corresponding to the business logic is in the preset time range. This is because if the business online time is short, the credibility of the execution time of the acquired business logic is not high. If the business goes online The duration is within the preset duration range, indicating that the execution duration of the business logic is highly reliable.
  • the determining unit 404 determining the estimated execution time corresponding to each business logic according to the execution time may include:
  • the determining unit 404 determines the execution time of each business logic when it goes online, calculates an average value of the execution time, and determines the average value as the estimated execution time corresponding to the business logic.
  • the average value of the execution time for each business logic is taken as the estimated business logic execution time, which is more accurate.
  • the storage unit 406 is configured to store each business logic and the estimated execution time corresponding to the business logic in a preset database.
  • the preset database can store various business logics and the estimated execution time corresponding to each business logic. If the business corresponding to a certain business logic is a newly launched business, the preset database corresponding to the business logic The estimated execution time can be manually set by the relevant person in charge. If the business corresponding to another business logic is already online and needs to be re-launched after a certain update, the estimated execution time corresponding to the business logic can be set by the system according to the business online The situation is automatically generated.
  • the method for the first obtaining unit 401 to obtain the target estimated execution time-consuming value corresponding to the target business logic is specifically as follows:
  • the first obtaining unit 401 is configured to query the estimated execution time of the target corresponding to the target business logic in the preset database.
  • the target business logic is one or several business logics among several business logics in the preset database
  • the estimated execution time of the target is the estimated execution time corresponding to the target business logic in the preset database
  • the system for dynamically adjusting the timeout time based on Redis distributed locks shown in Figure 5 may also include:
  • the recording unit 407 is configured to record the generation time of the timeout time corresponding to the target business logic after the generation unit 402 generates the timeout time corresponding to the target business logic according to the target estimated execution time-consuming value and the preset timeout time generation rule.
  • the determining unit 408 is configured to determine whether the time difference between the current time and the generation time is greater than the preset time difference.
  • the timeout period can be adjusted after a certain period of time to reduce the amount of operation.
  • the second acquiring unit 403 is specifically configured to acquire the target business logic corresponding to the target business logic when the time difference between the current time and the generation time is greater than the preset time difference when the determining unit 408 determines The target business logic execution start time and target business logic execution end time.
  • the storage unit 406 is further configured to store the adjusted timeout time, the adjustment time for adjusting the timeout time, and the target business logic in the timeout adjustment database after the adjustment unit 405 adjusts the timeout period according to the target execution time.
  • the record of adjusting the timeout period can be stored, so that the relevant responsible personnel can predict the change of the timeout period based on the record.
  • the target execution time can be determined according to the target business logic execution start time and target business logic execution end time, and according to Target execution takes time to adjust the timeout period, so as to realize the dynamic adjustment of the timeout period and improve the applicability of the timeout period.
  • This application also provides an electronic device, which includes:
  • a memory which stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the method for dynamically adjusting the timeout time based on the Redis distributed lock as shown above is realized.
  • the electronic device may be the apparatus 100 shown in FIG. 1 that runs the system for dynamically adjusting the timeout time based on the Redis distributed lock.
  • the present application also provides a computer-readable storage medium on which a computer program is stored.
  • the computer program is executed by a processor, the timeout period based on the Redis distributed lock as shown above is realized Dynamic adjustment system.

Landscapes

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

Abstract

本申请涉及分布式存储技术领域,揭示了一种基于Redis分布式锁的超时时间动态调整方法及系统,该方法包括:获取目标业务逻辑对应的目标预估执行耗时值;根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间;当目标业务逻辑按照超时时间执行加锁操作时,获取目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间;将目标业务逻辑执行开始时间与目标业务逻辑执行结束时间的时间差值确定为目标业务逻辑的目标执行耗时;根据目标执行耗时调整超时时间。此方法下,基于分布式存储技术,可以实现超时时间的动态调整。

Description

基于Redis分布式锁的超时时间动态调整方法及系统
本申请要求于2019年04月19日提交中国专利局、申请号为201910318260.6、申请名称为“基于Redis分布式锁的超时时间动态调整方法及系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及分布式存储技术领域,特别涉及一种基于Redis分布式锁的超时时间动态调整方法及系统。
背景技术
目前,大多数应用采用集群部署的方式进行部署,在集群部署的环境下,为了保证多个线程访问共享资源时的数据一致性,往往设置有分布式锁,分布式锁用于限制一个方法在超时时间内只能被同一个线程执行,以使多个线程不会在超时时间内同时重复执行某一方法,避免了由于多个线程同时重复执行某一方法导致共享资源非正常修改以至于数据不一致的现象发生。
针对最为常见的基于Redis的分布式锁,如何设置其超时时间一直受到开发者的关注。常见的设置超时时间的方式为事先预估业务逻辑的执行耗时,再根据事先预估的业务逻辑的执行耗时设置分布式锁的超时时间。在实践中发现,随着业务的增长,业务逻辑的执行耗时会越来越长,由于超时时间无法实现动态调整,因而可能存在业务逻辑的执行耗时超过之前设置的超时时间的情况,从而导致分布式锁过早失效,进而影响多个线程访问共享资源时的数据一致性。
可见,如何实现超时时间的动态调整成为了一个亟需解决的问题。
发明内容
为了解决相关技术中存在的无法实现超时时间的动态调整以至于影响多个线程访问共享资源时的数据一致性的问题,本申请提供了一种基于Redis分布式锁的超时时间动态调整方法及系统。
本申请实施例第一方面公开一种基于Redis分布式锁的超时时间动态调整方法,所述方法包括:
获取目标业务逻辑对应的目标预估执行耗时值;
根据所述目标预估执行耗时值与预设超时时间生成规则生成所述目标业务逻辑对应的超时时间;
当所述目标业务逻辑按照所述超时时间执行加锁操作时,获取所述目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间;
将所述目标业务逻辑执行开始时间与所述目标业务逻辑执行结束时间的时间差值确定为所述目标业务逻辑的目标执行耗时;
根据所述目标执行耗时调整所述超时时间。
本申请实施例第二方面公开一种基于Redis分布式锁的超时时间动态调整系统,所述系统包括:
第一获取单元,用于获取目标业务逻辑对应的目标预估执行耗时值;
生成单元,用于根据所述目标预估执行耗时值与预设超时时间生成规则生成所述目标业务逻辑对应的超时时间;
第二获取单元,用于当所述目标业务逻辑按照所述超时时间执行加锁操作时,获取所述目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间;
确定单元,用于将所述目标业务逻辑执行开始时间与所述目标业务逻辑执行结束时间的时间差值确定为所述目标业务逻辑的目标执行耗时;
调整单元,用于根据所述目标执行耗时调整所述超时时间。
本申请实施例第三方面公开一种电子设备,所述电子设备包括:
处理器;
存储器,所述存储器上存储有计算机可读指令,所述计算机可读指令被所述处理器执行时,实现如前所述的方法。
本申请实施例第四方面公开一种计算机可读存储介质,其存储计算机程序,所述计算机程序使得计算机执行如前所述的方法。可选的,该计算机可读存储介质可以为计算机非易失性可读存储介质。
本申请的实施例基于分布式存储技术,可以根据目标业务逻辑执行开始时间和目标业务逻辑执行结束时间确定目标执行耗时,并根据目标执行耗时调整超时时间,以此实现对超时时间的动态调整,提高超时时间的适用性。
附图说明
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本申请的实施例,并于说明书一起用于解释本申请的原理。
图1是根据一示例性实施例示出的一种运行基于Redis分布式锁的超时时间动态调整系统的装置的示意图;
图2是根据一示例性实施例示出的一种基于Redis分布式锁的超时时间动态调整方法的流程图;
图3是根据一示例性实施例示出的另一种基于Redis分布式锁的超时时间动态调整方法的流程图;
图4是根据一示例性实施例示出的一种基于Redis分布式锁的超时时间动态调整系统的框图;
图5是根据一示例性实施例示出的另一种基于Redis分布式锁的超时时间动态调整系统的框图。
具体实施方式
这里将详细地对示例性实施例执行说明,其示例表示在附图中。
本申请的实施环境可以是便携移动设备,例如智能手机、平板电脑、台式电脑。
图1是根据一示例性实施例示出的一种运行基于Redis分布式锁的超时时间动态调整系统的装置示意图。装置100可以是上述便携移动设备。如图1所示,装置100可以包括以下一个或多个组件:处理组件102,存储器104,电源组件106,多媒体组件108,音频组件110,传感器组件114以及通信组件116。
处理组件102通常控制装置100的整体操作,诸如与显示,电话呼叫,数据通信,相机操作以及记录操作相关联的操作等。处理组件102可以包括一个或多个处理器118来执行指令,以完成下述的方法的全部或部分步骤。此外,处理组件102可以包括一个或多个模块,用于便于处理组件102和其他组件之间的交互。例如,处理组件102可以包括多媒体模块,用于以方便多媒体组件 108和处理组件102之间的交互。
存储器104被配置为存储各种类型的数据以支持在装置100的操作。这些数据的示例包括用于在装置100上操作的任何应用程序或方法的指令。存储器104可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(Static Random Access Memory,简称SRAM),电可擦除可编程只读存储器(Electrically Erasable Programmable Read-Only Memory,简称EEPROM),可擦除可编程只读存储器(Erasable Programmable Read Only Memory,简称EPROM),可编程只读存储器(Programmable Red-Only Memory,简称PROM),只读存储器(Read-Only Memory,简称ROM),磁存储器,快闪存储器,磁盘或光盘。存储器104中还存储有一个或多个模块,用于该一个或多个模块被配置成由该一个或多个处理器118执行,以完成如下所示方法中的全部或者部分步骤。
电源组件106为装置100的各种组件提供电力。电源组件106可以包括电源管理系统,一个或多个电源,及其他与为装置100生成、管理和分配电力相关联的组件。
多媒体组件108包括在所述装置100和用户之间的提供一个输出接口的屏幕。在一些实施例中,屏幕可以包括液晶显示器(Liquid Crystal Display,简称LCD)和触摸面板。如果屏幕包括触摸面板,屏幕可以被实现为触摸屏,以接收来自用户的输入信号。触摸面板包括一个或多个触摸传感器以感测触摸、滑动和触摸面板上的手势。所述触摸传感器可以不仅感测触摸或滑动动作的边界,而且还检测与所述触摸或滑动操作相关的持续时间和压力。屏幕还可以包括有机电致发光显示器(Organic Light Emitting Display,简称OLED)。
音频组件110被配置为输出和/或输入音频信号。例如,音频组件110包括一个麦克风(Microphone,简称MIC),当装置100处于操作模式,如呼叫模式、记录模式和语音识别模式时,麦克风被配置为接收外部音频信号。所接收的音频信号可以被进一步存储在存储器104或经由通信组件116发送。在一些实施例中,音频组件110还包括一个扬声器,用于输出音频信号。
传感器组件114包括一个或多个传感器,用于为装置100提供各个方面的状态评估。例如,传感器组件114可以检测到装置100的打开/关闭状态,组 件的相对定位,传感器组件114还可以检测装置100或装置100一个组件的位置改变以及装置100的温度变化。在一些实施例中,该传感器组件114还可以包括磁传感器,压力传感器或温度传感器。
通信组件116被配置为便于装置100和其他设备之间有线或无线方式的通信。装置100可以接入基于通信标准的无线网络,如WiFi(Wireless-Fidelity,无线保真)。在一个示例性实施例中,通信组件116经由广播信道接收来自外部广播管理系统的广播信号或广播相关信息。在一个示例性实施例中,所述通信组件116还包括近场通信(Near Field Communication,简称NFC)模块,用于以促进短程通信。例如,在NFC模块可基于射频识别(Radio Frequency Identification,简称RFID)技术,红外数据协会(Infrared Data Association,简称IrDA)技术,超宽带(Ultra Wideband,简称UWB)技术,蓝牙技术和其他技术来实现。
在示例性实施例中,装置100可以被一个或多个应用专用集成电路(Application Specific Integrated Circuit,简称ASIC)、数字信号处理器、数字信号处理设备、可编程逻辑器件、现场可编程门阵列、控制器、微控制器、微处理器或其他电子元件实现,用于执行下述方法。
图2是根据一示例性实施例示出的一种基于Redis分布式锁的超时时间动态调整方法的流程图。如图2所示,此方法包括以下步骤:
步骤201,基于Redis分布式锁的超时时间动态调整系统获取目标业务逻辑对应的目标预估执行耗时值。
本申请实施例中,目标业务逻辑为实现某业务功能的核心代码部分,目标业务逻辑对应的目标预估执行耗时值为预估的该业务逻辑运行时需要的时长值,并且目标预估执行耗时值可以在预置数据库中获取,或者也可以接收人为输入的目标预估执行耗时值等,本申请实施例中不做限定。
步骤202,基于Redis分布式锁的超时时间动态调整系统根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间。
本申请实施例中,预设超时时间生成规则可以为将目标预估执行耗时值乘上某一固定值来生成目标业务逻辑对应的超时时间,例如,与目标业务逻辑A对应的目标预估执行耗时值可以为t,如果预设超时时间生成规则中规定乘上 的固定值为10时,根据t与预设超时时间生成规则生成A对应的超时时间可以为10*t,如果预设超时时间生成规则中规定乘上的固定值为8时,根据t与预设超时时间生成规则生成A对应的超时时间也可以为8*t等,本申请实施例中不做限定。
步骤203,当目标业务逻辑按照超时时间执行加锁操作时,基于Redis分布式锁的超时时间动态调整系统获取目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间。
本申请实施例中,目标业务逻辑按照超时时间执行加锁操作,即在超时时间内仅允许一个线程执行目标业务逻辑对应的方法,并且在该线程执行目标业务逻辑对应的方法的过程中可以获取开始执行的目标业务逻辑执行开始时间,也可以获取结束执行的目标业务逻辑执行结束时间。
步骤204,基于Redis分布式锁的超时时间动态调整系统将目标业务逻辑执行开始时间与目标业务逻辑执行结束时间的时间差值确定为目标业务逻辑的目标执行耗时。
本申请实施例中,目标业务逻辑执行开始时间与目标业务逻辑执行结束时间的时间差值为目标业务逻辑执行结束时间减去目标业务逻辑执行开始时间,并且目标执行耗时反映了目标业务逻辑在实际应用中运行时需要的时长值。
步骤205,基于Redis分布式锁的超时时间动态调整系统根据目标执行耗时调整超时时间。
本申请实施例中,可以根据目标业务逻辑在实际应用中运行时需要的时长值对超时时间动态调整。
作为一种可选的实施方式,基于Redis分布式锁的超时时间动态调整系统根据目标执行耗时调整超时时间可以包括:
基于Redis分布式锁的超时时间动态调整系统将目标执行耗时确定为目标预估执行耗时值,并执行上述的根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间。
通过实施这种可选的实施方式,可以将目标执行耗时确定为目标预估执行耗时值,并重复执行根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间的步骤,从而实现对Redis分布式锁超时时间的动 态调整。
举例来说,与目标业务逻辑A对应的目标预估执行耗时值可以为t,根据t与预设超时时间生成规则生成A对应的超时时间可以为10*t,也可以为8*t等。当目标业务逻辑A按照该超时时间执行加锁操作时,可以获取A执行时的目标业务逻辑执行开始时间与目标业务逻辑执行结束时间,目标业务逻辑执行结束时间减去目标业务逻辑执行开始时间即为目标业务逻辑的目标执行耗时t1,此时可以将超时时间调整为10*t1或者8*t1等,这一过程可以重复进行,从而实现Redis分布式锁超时时间的动态调整。
上述方法下,基于分布式存储技术,可以根据目标业务逻辑执行开始时间和目标业务逻辑执行结束时间确定目标执行耗时,并根据目标执行耗时调整超时时间,以此实现对超时时间的动态调整,提高超时时间的适用性。
图3是根据一示例性实施例示出的另一种基于Redis分布式锁的超时时间动态调整方法的流程图。如图3所示,此方法包括以下步骤:
步骤301,当业务逻辑对应的业务上线时长处于预设时长范围内时,基于Redis分布式锁的超时时间动态调整系统根据执行耗时确定每一业务逻辑对应的预估执行耗时。
本申请实施例中,可以先判断业务逻辑对应的业务上线时长是否处于预设时长范围,这是由于业务上线时长较短的话获取到的业务逻辑的执行时长的可信度不高,如果业务上线时长处于预设时长范围内,说明业务逻辑的执行时长的可信度较高。
作为一种可选的实施方式,基于Redis分布式锁的超时时间动态调整系统根据执行耗时确定每一业务逻辑对应的预估执行耗时可以包括:
基于Redis分布式锁的超时时间动态调整系统确定每一业务逻辑上线时的若干执行耗时,计算该若干执行耗时的平均值,将该平均值确定为该业务逻辑对应的预估执行耗时。
通过实施这种可选的实施方式,可以在业务上线时长处于预设时长范围内时,将每一业务逻辑上线时的若干执行耗时的平均值作为预估业务逻辑执行耗时,更加准确。
步骤302,基于Redis分布式锁的超时时间动态调整系统将每一业务逻辑 与业务逻辑对应的预估执行耗时对应存储至预置数据库。
本申请实施例中,预置数据库中可以存储有各类业务逻辑与每一业务逻辑对应的预估执行耗时,如果某一业务逻辑对应的业务是新上线的业务,该业务逻辑对应的预估执行耗时可以由相关负责人员手动设置,如果另一业务逻辑对应的业务是已上线并做出一定更新需要重新上线的业务,该业务逻辑对应的预估执行耗时可以由系统根据业务上线的情况自动生成。
步骤303,基于Redis分布式锁的超时时间动态调整系统在预置数据库中查询目标业务逻辑对应的目标预估执行耗时。
本申请实施例中,目标业务逻辑为预置数据库中的若干业务逻辑中的某一或若干业务逻辑,目标预估执行耗时即为目标业务逻辑在预置数据库中对应的预估执行耗时。
步骤304,基于Redis分布式锁的超时时间动态调整系统根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间。
步骤305,基于Redis分布式锁的超时时间动态调整系统记录生成目标业务逻辑对应的超时时间的生成时间。
步骤306,基于Redis分布式锁的超时时间动态调整系统判断当前时间与生成时间的时间差值是否大于预设时间差值,如果是,执行步骤307至步骤310,如果否,结束本次流程。
本申请实施例中,由于业务逻辑执行耗时发生改变往往发生在一段时间之后,可以间隔一定时间段再去调整超时时间,以此降低运行量。
步骤307,当目标业务逻辑按照超时时间执行加锁操作时,基于Redis分布式锁的超时时间动态调整系统获取目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间。
步骤308,基于Redis分布式锁的超时时间动态调整系统将目标业务逻辑执行开始时间与目标业务逻辑执行结束时间的时间差值确定为目标业务逻辑的目标执行耗时。
步骤309,基于Redis分布式锁的超时时间动态调整系统根据目标执行耗时调整超时时间。
作为一种可选的实施方式,基于Redis分布式锁的超时时间动态调整系统 根据目标执行耗时调整超时时间可以包括:
基于Redis分布式锁的超时时间动态调整系统统计目标执行耗时的目标数量;
当目标数量达到预设数量时,基于Redis分布式锁的超时时间动态调整系统计算预设数量的目标执行耗时的第一平均值;
基于Redis分布式锁的超时时间动态调整系统根据第一平均值调整超时时间。
作为另一种可选的实施方式,基于Redis分布式锁的超时时间动态调整系统根据目标执行耗时调整超时时间可以包括:
基于Redis分布式锁的超时时间动态调整系统获取预设时间段内的目标执行耗时;
基于Redis分布式锁的超时时间动态调整系统计算预设时间段内的目标执行耗时的第二平均值;
基于Redis分布式锁的超时时间动态调整系统根据第二平均值调整超时时间。
本申请实施例中,可以统计最近一个礼拜的目标业务逻辑的若干个目标执行耗时,也可以统计1000次目标业务逻辑的1000个目标执行耗时,根据其平均值调整超时时间。
通过实施这种可选的实施方式,可以根据业务逻辑对应的业务类型不同选择按照次数或者时间来计算目标执行耗时的平均值,从而根据平均值调整超时时间,增强了超时时间调整方式的多样性。
步骤310,基于Redis分布式锁的超时时间动态调整系统将调整后的超时时间、调整超时时间的调整时间和目标业务逻辑存储至超时时间调整数据库。
本申请实施例中,可以将调整超时时间的记录存储下来,便于后续相关负责人员根据该记录预测超时时间的变化。
上述方法下,基于分布式存储技术,可以根据目标业务逻辑执行开始时间和目标业务逻辑执行结束时间确定目标执行耗时,并根据目标执行耗时调整超时时间,以此实现对超时时间的动态调整,提高超时时间的适用性。
以下是本申请的系统实施例。
图4是根据一示例性实施例示出的一种基于Redis分布式锁的超时时间动态调整系统的框图。如图4所示,该系统包括:
第一获取单元401,用于获取目标业务逻辑对应的目标预估执行耗时值。
本申请实施例中,目标业务逻辑为实现某业务功能的核心代码部分,目标业务逻辑对应的目标预估执行耗时值为预估的该业务逻辑运行时需要的时长值,并且目标预估执行耗时值可以在预置数据库中获取,或者也可以接收人为输入的目标预估执行耗时值等,本申请实施例中不做限定。
生成单元402,用于根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间。
本申请实施例中,预设超时时间生成规则可以为将目标预估执行耗时值乘上某一固定值来生成目标业务逻辑对应的超时时间,例如,与目标业务逻辑A对应的目标预估执行耗时值可以为t,如果预设超时时间生成规则中规定乘上的固定值为10时,根据t与预设超时时间生成规则生成A对应的超时时间可以为10*t,如果预设超时时间生成规则中规定乘上的固定值为8时,根据t与预设超时时间生成规则生成A对应的超时时间也可以为8*t等,本申请实施例中不做限定。
第二获取单元403,用于当目标业务逻辑按照超时时间执行加锁操作时,获取目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间。
本申请实施例中,目标业务逻辑按照超时时间执行加锁操作,即在超时时间内仅允许一个线程执行目标业务逻辑对应的方法,并且在该线程执行目标业务逻辑对应的方法的过程中可以获取开始执行的目标业务逻辑执行开始时间,也可以获取结束执行的目标业务逻辑执行结束时间。
确定单元404,用于将目标业务逻辑执行开始时间与目标业务逻辑执行结束时间的时间差值确定为目标业务逻辑的目标执行耗时。
本申请实施例中,目标业务逻辑执行开始时间与目标业务逻辑执行结束时间的时间差值为目标业务逻辑执行结束时间减去目标业务逻辑执行开始时间,并且目标执行耗时反映了目标业务逻辑在实际应用中运行时需要的时长值。
调整单元405,用于根据目标执行耗时调整超时时间。
本申请实施例中,可以根据目标业务逻辑在实际应用中运行时需要的时长值对超时时间动态调整。
作为一种可选的实施方式,调整单元405根据目标执行耗时调整超时时间可以包括:
调整单元405将目标执行耗时确定为目标预估执行耗时值,并执行上述的根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间。
通过实施这种可选的实施方式,可以将目标执行耗时确定为目标预估执行耗时值,并重复执行根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间的步骤,从而实现对Redis分布式锁超时时间的动态调整。
举例来说,与目标业务逻辑A对应的目标预估执行耗时值可以为t,根据t与预设超时时间生成规则生成A对应的超时时间可以为10*t,也可以为8*t等。当目标业务逻辑A按照该超时时间执行加锁操作时,可以获取A执行时的目标业务逻辑执行开始时间与目标业务逻辑执行结束时间,目标业务逻辑执行结束时间减去目标业务逻辑执行开始时间即为目标业务逻辑的目标执行耗时t1,此时可以将超时时间调整为10*t1或者8*t1等,这一过程可以重复进行,从而实现Redis分布式锁超时时间的动态调整。
作为一种可选的实施方式,调整单元405根据目标执行耗时调整超时时间可以包括:
调整单元405统计目标执行耗时的目标数量;
当目标数量达到预设数量时,调整单元405计算预设数量的目标执行耗时的第一平均值;
调整单元405根据第一平均值调整超时时间。
作为另一种可选的实施方式,调整单元405根据目标执行耗时调整超时时间可以包括:
调整单元405获取预设时间段内的目标执行耗时;
调整单元405计算预设时间段内的目标执行耗时的第二平均值;
调整单元405根据第二平均值调整超时时间。
本申请实施例中,可以统计最近一个礼拜的目标业务逻辑的若干个目标执行耗时,也可以统计1000次目标业务逻辑的1000个目标执行耗时,根据其平均值调整超时时间。
通过实施这种可选的实施方式,可以根据业务逻辑对应的业务类型不同选择按照次数或者时间来计算目标执行耗时的平均值,从而根据平均值调整超时时间,增强了超时时间调整方式的多样性。
可见,通过实施图4所描述的基于Redis分布式锁的超时时间动态调整系统,基于分布式存储技术,可以根据目标业务逻辑执行开始时间和目标业务逻辑执行结束时间确定目标执行耗时,并根据目标执行耗时调整超时时间,以此实现对超时时间的动态调整,提高超时时间的适用性。
图5是根据一示例性实施例示出的另一种基于Redis分布式锁的超时时间动态调整系统的框图。图5是在图4基础上优化得到的,与图4所示的基于Redis分布式锁的超时时间动态调整系统相比,在图5所示的基于Redis分布式锁的超时时间动态调整系统中:
确定单元404,还用于在第一获取单元401获取目标业务逻辑对应的目标预估执行耗时值之前,当业务逻辑对应的业务上线时长处于预设时长范围内时,根据执行耗时确定每一业务逻辑对应的预估执行耗时。
本申请实施例中,可以先判断业务逻辑对应的业务上线时长是否处于预设时长范围,这是由于业务上线时长较短的话获取到的业务逻辑的执行时长的可信度不高,如果业务上线时长处于预设时长范围内,说明业务逻辑的执行时长的可信度较高。
作为一种可选的实施方式,确定单元404根据执行耗时确定每一业务逻辑对应的预估执行耗时可以包括:
确定单元404确定每一业务逻辑上线时的若干执行耗时,计算该若干执行耗时的平均值,将该平均值确定为该业务逻辑对应的预估执行耗时。
通过实施这种可选的实施方式,可以在业务上线时长处于预设时长范围内时,将每一业务逻辑上线时的若干执行耗时的平均值作为预估业务逻辑执行耗时,更加准确。
存储单元406,用于将每一业务逻辑与业务逻辑对应的预估执行耗时对应 存储至预置数据库。
本申请实施例中,预置数据库中可以存储有各类业务逻辑与每一业务逻辑对应的预估执行耗时,如果某一业务逻辑对应的业务是新上线的业务,该业务逻辑对应的预估执行耗时可以由相关负责人员手动设置,如果另一业务逻辑对应的业务是已上线并做出一定更新需要重新上线的业务,该业务逻辑对应的预估执行耗时可以由系统根据业务上线的情况自动生成。
可选的,在图5所示的基于Redis分布式锁的超时时间动态调整系统中:
第一获取单元401用于获取目标业务逻辑对应的目标预估执行耗时值的方式具体为:
第一获取单元401,用于在预置数据库中查询目标业务逻辑对应的目标预估执行耗时。
本申请实施例中,目标业务逻辑为预置数据库中的若干业务逻辑中的某一或若干业务逻辑,目标预估执行耗时即为目标业务逻辑在预置数据库中对应的预估执行耗时。
可选的,图5所示的基于Redis分布式锁的超时时间动态调整系统还可以包括:
记录单元407,用于在生成单元402根据目标预估执行耗时值与预设超时时间生成规则生成目标业务逻辑对应的超时时间之后,记录生成目标业务逻辑对应的超时时间的生成时间。
判断单元408,用于判断当前时间与生成时间的时间差值是否大于预设时间差值。
本申请实施例中,由于业务逻辑执行耗时发生改变往往发生在一段时间之后,可以间隔一定时间段再去调整超时时间,以此降低运行量。
第二获取单元403,具体用于当判断单元408判断出当前时间与生成时间的时间差值大于预设时间差值时,当目标业务逻辑按照超时时间执行加锁操作时,获取目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间。
存储单元406,还用于在调整单元405根据目标执行耗时调整超时时间之后,将调整后的超时时间、调整超时时间的调整时间和目标业务逻辑存储至超 时时间调整数据库。
本申请实施例中,可以将调整超时时间的记录存储下来,便于后续相关负责人员根据该记录预测超时时间的变化。
可见,通过实施图5所描述的基于Redis分布式锁的超时时间动态调整系统,基于分布式存储技术,可以根据目标业务逻辑执行开始时间和目标业务逻辑执行结束时间确定目标执行耗时,并根据目标执行耗时调整超时时间,以此实现对超时时间的动态调整,提高超时时间的适用性。
本申请还提供一种电子设备,该电子设备包括:
处理器;
存储器,该存储器上存储有计算机可读指令,该计算机可读指令被处理器执行时,实现如前所示的基于Redis分布式锁的超时时间动态调整方法。
该电子设备可以是图1所示运行基于Redis分布式锁的超时时间动态调整系统的装置100。
在一示例性实施例中,本申请还提供一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时,实现如前所示的基于Redis分布式锁的超时时间动态调整系统。
应当理解的是,本申请并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围执行各种修改和改变。本申请的范围仅由所附的权利要求来限制。

Claims (20)

  1. 一种基于Redis分布式锁的超时时间动态调整方法,其特征在于,所述方法包括:
    获取目标业务逻辑对应的目标预估执行耗时值;
    根据所述目标预估执行耗时值与预设超时时间生成规则生成所述目标业务逻辑对应的超时时间;
    当所述目标业务逻辑按照所述超时时间执行加锁操作时,获取所述目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间;
    将所述目标业务逻辑执行开始时间与所述目标业务逻辑执行结束时间的时间差值确定为所述目标业务逻辑的目标执行耗时;
    根据所述目标执行耗时调整所述超时时间。
  2. 根据权利要求1所述的方法,其特征在于,在所述获取目标业务逻辑对应的目标预估执行耗时值之前,所述方法还包括:
    当业务逻辑对应的业务上线时长处于预设时长范围内时,根据所述执行耗时确定每一业务逻辑对应的预估执行耗时;
    将每一所述业务逻辑与所述业务逻辑对应的所述预估执行耗时对应存储至预置数据库。
  3. 根据权利要求2所述的方法,其特征在于,所述获取目标业务逻辑对应的目标预估执行耗时值,包括:
    在所述预置数据库中查询所述目标业务逻辑对应的目标预估执行耗时。
  4. 根据权利要求3所述的方法,其特征在于,在所述根据所述目标预估执行耗时值与预设超时时间生成规则生成所述目标业务逻辑对应的超时时间之后,所述方法还包括:
    记录生成所述目标业务逻辑对应的所述超时时间的生成时间;
    判断当前时间与所述生成时间的时间差值是否大于预设时间差值;
    如果是,执行所述的当所述目标业务逻辑按照所述超时时间执行加锁操作时,获取所述目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间。
  5. 根据权利要求1至4任一项所述的方法,其特征在于,在所述根据所 述目标执行耗时调整所述超时时间之后,所述方法还包括:
    将调整后的所述超时时间、调整所述超时时间的调整时间和所述目标业务逻辑存储至超时时间调整数据库。
  6. 根据权利要求5所述的方法,其特征在于,所述根据所述目标执行耗时调整所述超时时间,包括:
    统计所述目标执行耗时的目标数量;
    当所述目标数量达到预设数量时,计算所述预设数量的所述目标执行耗时的第一平均值;
    根据所述第一平均值调整所述超时时间。
  7. 根据权利要求5所述的方法,其特征在于,所述根据所述目标执行耗时调整所述超时时间,包括:
    获取预设时间段内的所述目标执行耗时;
    计算所述预设时间段内的所述目标执行耗时的第二平均值;
    根据所述第二平均值调整所述超时时间。
  8. 一种基于Redis分布式锁的超时时间动态调整系统,其特征在于,所述系统包括:
    第一获取单元,用于获取目标业务逻辑对应的目标预估执行耗时值;
    生成单元,用于根据所述目标预估执行耗时值与预设超时时间生成规则生成所述目标业务逻辑对应的超时时间;
    第二获取单元,用于当所述目标业务逻辑按照所述超时时间执行加锁操作时,获取所述目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间;
    确定单元,用于将所述目标业务逻辑执行开始时间与所述目标业务逻辑执行结束时间的时间差值确定为所述目标业务逻辑的目标执行耗时;
    调整单元,用于根据所述目标执行耗时调整所述超时时间。
  9. 根据权利要求8所述的系统,其特征在于,所述系统还包括:存储单元;
    所述确定单元,还用于在所述获取目标业务逻辑对应的目标预估执行耗时值之前,当业务逻辑对应的业务上线时长处于预设时长范围内时,根据所述执 行耗时确定每一业务逻辑对应的预估执行耗时;
    所述存储单元,用于将每一所述业务逻辑与所述业务逻辑对应的所述预估执行耗时对应存储至预置数据库。
  10. 根据权利要求9所述的系统,其特征在于,所述第一获取单元在获取目标业务逻辑对应的目标预估执行耗时值时,具体用于:
    在所述预置数据库中查询所述目标业务逻辑对应的目标预估执行耗时。
  11. 根据权利要求10所述的系统,其特征在于,所述系统还包括:记录单元和判断单元;
    所述记录单元,用于在所述根据所述目标预估执行耗时值与预设超时时间生成规则生成所述目标业务逻辑对应的超时时间之后,记录生成所述目标业务逻辑对应的所述超时时间的生成时间;
    所述判断单元,用于判断当前时间与所述生成时间的时间差值是否大于预设时间差值;
    所述第二获取单元,具体用于当所述判断单元判断出当前时间与生成时间的时间差值大于预设时间差值时,且当所述目标业务逻辑按照所述超时时间执行加锁操作时,获取所述目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间。
  12. 根据权利要求8至11任一项所述的系统,其特征在于,所述系统还包括:存储单元;
    所述存储单元,还用于在所述根据所述目标执行耗时调整所述超时时间之后,将调整后的所述超时时间、调整所述超时时间的调整时间和所述目标业务逻辑存储至超时时间调整数据库。
  13. 根据权利要求12所述的系统,其特征在于,所述调整单元在根据所述目标执行耗时调整所述超时时间时,具体用于:
    统计所述目标执行耗时的目标数量;
    当所述目标数量达到预设数量时,计算所述预设数量的所述目标执行耗时的第一平均值;
    根据所述第一平均值调整所述超时时间。
  14. 根据权利要求12所述的系统,其特征在于,所述调整单元在根据所 述目标执行耗时调整所述超时时间时,具体用于:
    获取预设时间段内的所述目标执行耗时;
    计算所述预设时间段内的所述目标执行耗时的第二平均值;
    根据所述第二平均值调整所述超时时间。
  15. 一种电子设备,其特征在于,所述电子设备包括:
    处理器;
    存储器,所述存储器上存储有计算机可读指令,所述计算机可读指令被所述处理器执行时,实现以下步骤:
    获取目标业务逻辑对应的目标预估执行耗时值;
    根据所述目标预估执行耗时值与预设超时时间生成规则生成所述目标业务逻辑对应的超时时间;
    当所述目标业务逻辑按照所述超时时间执行加锁操作时,获取所述目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间;
    将所述目标业务逻辑执行开始时间与所述目标业务逻辑执行结束时间的时间差值确定为所述目标业务逻辑的目标执行耗时;
    根据所述目标执行耗时调整所述超时时间。
  16. 根据权利要求15所述的电子设备,其特征在于,在所述获取目标业务逻辑对应的目标预估执行耗时值之前,所述处理器还执行以下步骤:
    当业务逻辑对应的业务上线时长处于预设时长范围内时,根据所述执行耗时确定每一业务逻辑对应的预估执行耗时;
    将每一所述业务逻辑与所述业务逻辑对应的所述预估执行耗时对应存储至预置数据库。
  17. 根据权利要求16所述的电子设备,其特征在于,所述处理器在执行所述获取目标业务逻辑对应的目标预估执行耗时值时,具体执行以下步骤:
    在所述预置数据库中查询所述目标业务逻辑对应的目标预估执行耗时。
  18. 根据权利要求17所述的电子设备,其特征在于,在所述根据所述目标预估执行耗时值与预设超时时间生成规则生成所述目标业务逻辑对应的超时时间之后,所述处理器还执行以下步骤:
    记录生成所述目标业务逻辑对应的所述超时时间的生成时间;
    判断当前时间与所述生成时间的时间差值是否大于预设时间差值;
    如果是,执行所述的当所述目标业务逻辑按照所述超时时间执行加锁操作时,获取所述目标业务逻辑对应的目标业务逻辑执行开始时间和目标业务逻辑执行结束时间。
  19. 根据权利要求15至18任一项所述的电子设备,其特征在于,在所述根据所述目标执行耗时调整所述超时时间之后,所述处理器还执行以下步骤:
    将调整后的所述超时时间、调整所述超时时间的调整时间和所述目标业务逻辑存储至超时时间调整数据库。
  20. 一种计算机可读存储介质,其特征在于,其存储计算机程序,所述计算机程序使得计算机执行权利要求1至7任一项所述的方法。
PCT/CN2019/120964 2019-04-19 2019-11-26 基于Redis分布式锁的超时时间动态调整方法及系统 WO2020211382A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910318260.6 2019-04-19
CN201910318260.6A CN110162384B (zh) 2019-04-19 2019-04-19 基于Redis分布式锁的超时时间动态调整方法及系统

Publications (1)

Publication Number Publication Date
WO2020211382A1 true WO2020211382A1 (zh) 2020-10-22

Family

ID=67638684

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/120964 WO2020211382A1 (zh) 2019-04-19 2019-11-26 基于Redis分布式锁的超时时间动态调整方法及系统

Country Status (2)

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

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113238862A (zh) * 2021-05-13 2021-08-10 京东数字科技控股股份有限公司 一种分布式任务调度方法和装置

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110162384B (zh) * 2019-04-19 2023-04-28 深圳壹账通智能科技有限公司 基于Redis分布式锁的超时时间动态调整方法及系统
CN110768861B (zh) * 2019-09-20 2021-07-06 北京字节跳动网络技术有限公司 一种获取超时阈值的方法、装置、介质和电子设备
CN112732538B (zh) * 2019-10-28 2023-10-13 腾讯科技(深圳)有限公司 一种面板性能分析方法、装置、终端及存储介质
CN110784478B (zh) * 2019-10-31 2024-04-30 深圳前海微众银行股份有限公司 超时时长的调整方法、装置、设备及计算机可读存储介质
CN111405015B (zh) * 2020-03-09 2022-09-30 中国建设银行股份有限公司 一种数据处理方法、装置、设备及存储介质
CN113282580A (zh) * 2021-04-28 2021-08-20 青岛海尔科技有限公司 用于执行定时任务的方法、存储介质及服务器
CN113824603B (zh) * 2021-11-25 2022-02-08 天津众颐科技有限责任公司 一种前端调用微服务接口时的超时时间的动态配置方法
CN114115751B (zh) * 2022-01-25 2022-04-19 苏州浪潮智能科技有限公司 一种大规模分布式存储的操作耗时自动监控方法与系统

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130152047A1 (en) * 2011-11-22 2013-06-13 Solano Labs, Inc System for distributed software quality improvement
CN104462447A (zh) * 2014-12-15 2015-03-25 北京国双科技有限公司 访问超时的数据处理方法和装置
CN107368498A (zh) * 2016-05-13 2017-11-21 阿里巴巴集团控股有限公司 优化MySQL悲观锁的锁等待超时时间的方法及装置
CN108920264A (zh) * 2018-06-12 2018-11-30 深圳市德名利电子有限公司 一种命令超时处理方法及系统
CN109144700A (zh) * 2018-09-03 2019-01-04 阿里巴巴集团控股有限公司 超时时长的确定方法、装置、服务器和数据处理方法
CN109558218A (zh) * 2018-12-04 2019-04-02 山东浪潮通软信息科技有限公司 一种基于Redis的分布式业务数据锁实现方法
CN110162384A (zh) * 2019-04-19 2019-08-23 深圳壹账通智能科技有限公司 基于Redis分布式锁的超时时间动态调整方法及系统

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
CN106131186A (zh) * 2016-07-15 2016-11-16 国网河北省电力公司电力科学研究院 一种基于Redis分布式缓存的用电信息采集接口调试方法
CN106250178B (zh) * 2016-07-26 2019-10-25 北京北森云计算股份有限公司 通过多语言云编译实现系统动态功能在线拦截扩展的方法
CN106293954A (zh) * 2016-08-08 2017-01-04 浪潮(北京)电子信息产业有限公司 一种基于分布式锁的高可用服务管理方法
CN106446037A (zh) * 2016-08-31 2017-02-22 南威软件股份有限公司 一种基于分布式锁实现Redis与MYSQL数据一致性的方法
CN106445648A (zh) * 2016-10-21 2017-02-22 天津海量信息技术股份有限公司 一种基于redis实现多worker协同的系统
CN106776720A (zh) * 2016-11-18 2017-05-31 北京奇虎科技有限公司 一种文件处理方法和装置
CN106776816A (zh) * 2016-11-24 2017-05-31 北京小米移动软件有限公司 加锁方法和装置
CN106951431A (zh) * 2016-12-16 2017-07-14 华南理工大学 一种集群监控数据采集方法
CN108287854B (zh) * 2017-01-10 2021-06-22 网宿科技股份有限公司 一种流计算中数据持久化的方法和系统
CN108694075B (zh) * 2017-04-12 2021-03-30 北京京东尚科信息技术有限公司 处理报表数据的方法、装置、电子设备和可读存储介质
US10613944B2 (en) * 2017-04-18 2020-04-07 Netapp, Inc. Systems and methods for backup and restore of distributed master-slave database clusters
CN107133369A (zh) * 2017-06-16 2017-09-05 郑州云海信息技术有限公司 一种基于redis过期键的分布式读共享缓存老化方法
CN108512716B (zh) * 2018-02-07 2020-07-28 深圳壹账通智能科技有限公司 上报设备信息的方法、系统、计算机设备和存储介质
CN108874552B (zh) * 2018-06-28 2021-09-21 杭州云毅网络科技有限公司 分布式锁执行方法、装置及系统、应用服务器和存储介质

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130152047A1 (en) * 2011-11-22 2013-06-13 Solano Labs, Inc System for distributed software quality improvement
CN104462447A (zh) * 2014-12-15 2015-03-25 北京国双科技有限公司 访问超时的数据处理方法和装置
CN107368498A (zh) * 2016-05-13 2017-11-21 阿里巴巴集团控股有限公司 优化MySQL悲观锁的锁等待超时时间的方法及装置
CN108920264A (zh) * 2018-06-12 2018-11-30 深圳市德名利电子有限公司 一种命令超时处理方法及系统
CN109144700A (zh) * 2018-09-03 2019-01-04 阿里巴巴集团控股有限公司 超时时长的确定方法、装置、服务器和数据处理方法
CN109558218A (zh) * 2018-12-04 2019-04-02 山东浪潮通软信息科技有限公司 一种基于Redis的分布式业务数据锁实现方法
CN110162384A (zh) * 2019-04-19 2019-08-23 深圳壹账通智能科技有限公司 基于Redis分布式锁的超时时间动态调整方法及系统

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113238862A (zh) * 2021-05-13 2021-08-10 京东数字科技控股股份有限公司 一种分布式任务调度方法和装置
CN113238862B (zh) * 2021-05-13 2024-04-16 京东科技控股股份有限公司 一种分布式任务调度方法和装置

Also Published As

Publication number Publication date
CN110162384B (zh) 2023-04-28
CN110162384A (zh) 2019-08-23

Similar Documents

Publication Publication Date Title
WO2020211382A1 (zh) 基于Redis分布式锁的超时时间动态调整方法及系统
US9377839B2 (en) Dynamic battery management
WO2016188060A1 (zh) 应用程序安装包的处理方法及装置
CN106415296B (zh) 自适应电池寿命延长
US9541986B2 (en) Adaptive screen timeouts based on user preferences, interaction patterns and active applications
CN107835101B (zh) 对服务器进行压力测试的方法及装置、终端
RU2712118C1 (ru) Способ управления экранным дисплеем и устройство, использующее этот способ
WO2016011743A1 (zh) 节省存储空间的方法和装置
CN110471763B (zh) 基于共享对象池的调度方法、系统、介质及电子设备
WO2017096773A1 (zh) 智能设备控制方法及装置
CN110162442B (zh) 一种系统性能瓶颈定位方法及系统
CN106897009B (zh) 移动设备时间显示方法及装置
US20150241519A1 (en) Method for managing power of electronic device and electronic device thereof
EP3073371A1 (en) Method and device for loading theme application
CN107423220A (zh) 内存泄露的检测方法及装置、电子设备
CN107885307B (zh) 设备控制方法及装置
CN109215615B (zh) 显示单元工作参数补偿方法及装置
US8934880B2 (en) Movement detection system for a portable device such as a portable phone
US20170169467A1 (en) Information push method and device
CN112363825A (zh) 一种弹性伸缩方法及装置
CN110888822B (zh) 内存处理方法、装置及存储介质
CN108391307B (zh) 基于安卓系统的功耗管控方法、装置及存储介质
KR20150008957A (ko) 단말 및 그 단말에서 어플리케이션 업데이트 방법
CN108304288B (zh) 获取带宽利用率的方法、装置及存储介质
WO2020186781A1 (zh) 测试代码移交控制方法及装置、电子设备、计算机非易失性可读存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19925206

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 020222)

122 Ep: pct application non-entry in european phase

Ref document number: 19925206

Country of ref document: EP

Kind code of ref document: A1