Data collaborative initialization method and its device, equipment, and medium

By intercepting concurrent data requests in a distributed system and coordinating the locking resources with dynamic sleep time, the problem of inefficiency of concurrent data initialization requests in a distributed system is solved, and efficient data request processing and resource utilization are achieved.

CN114327797BActive Publication Date: 2024-12-17GUANGZHOU HUADUO NETWORK TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111628409.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-28
Publication Date
2024-12-17
Estimated Expiration
2041-12-28

AI Technical Summary

Technical Problem

In a distributed system, when multiple concurrent data initialization requests are requested, the prior art is difficult to effectively coordinate and allocate lock resources, resulting in inefficiency, inaccurate sleep time, and affecting business execution efficiency.

Method used

By intercepting concurrent data acquisition requests, one request thread controls to obtain the lock and executes the data initialization transaction. Other request threads sleep according to the dynamic update sleep time. The sleep time is determined by the historical consumption time of the previous request thread to ensure that the lock is released after the transaction is completed. Coordinate the time connection of multiple request threads.

Benefits of technology

It realizes efficient coordination of concurrent data requests, avoids lock conflicts, improves system efficiency, is simple and easy to implement, saves server computing resources, and improves operational efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114327797B_ABST
    Figure CN114327797B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computer resource scheduling, and discloses a data collaborative initialization method and its device, equipment, and medium, including: intercepting multiple concurrent data acquisition requests for acquiring multiple target data, wherein at least part of the target data depends on the determination of another part of the target data; responding to each data acquisition request and running each corresponding request thread; controlling one of the data acquisition requests to obtain a control lock, and the data acquisition request that obtains the control lock starts a data initialization transaction to complete the background calculation of the multiple target data, and releases the control lock after the data initialization transaction is successfully executed; during the execution of the data initialization transaction, control other request threads that have not obtained the control lock to sleep according to the dynamically updated sleep duration, and after the sleep ends, try to obtain the corresponding target data to respond to each corresponding data acquisition request. The present application realizes precise control of the waiting time of threads in concurrent situations.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of computer resource scheduling, and in particular to a data collaborative initialization method and its corresponding device, computer equipment, and computer-readable storage medium. Background Art

[0002] With the rise of the Internet, the use of Internet products has become a normal phenomenon. Generally, Internet systems are deployed in a distributed manner. Distributed deployment can indeed bring about performance and efficiency improvements. Not only that, it also has an excellent cost-effectiveness. Compared with systems using expensive hardware configurations, distributed systems can achieve the same performance using low-cost hardware as configurations. Therefore, it has become the era of distributed systems.

[0003] However, as the user volume continues to increase at a geometric rate, distributed systems often need to handle data initialization services in concurrent scenarios, that is, they are faced with processing a large number of identical or different data initialization services at the same time. Usually, these data need to be called in parallel through multiple interfaces, and there is an inherent correlation between the data. For this reason, based on the above reasons, distributed locks are used for intermediate coordination. At the same time, only one client can obtain the lock and execute the service, while other clients cannot obtain the lock and enter a dormant waiting state until the dormancy ends. In order to avoid anomalies, the lock will be released after a limited period of time. Therefore, it is crucial to reasonably allocate the dormant time and the time to hold the lock. This is related to the efficient connection between a large number of services and affects the execution efficiency. However, there is no relevant solution in the prior art. Therefore, the applicant has made corresponding explorations in this regard. Summary of the invention

[0004] The primary purpose of the present application is to solve at least one of the above problems and to provide a data collaborative initialization method and its corresponding device, computer equipment, and computer-readable storage medium.

[0005] In order to meet the various objectives of this application, this application adopts the following technical solutions:

[0006] A data collaborative initialization method provided to meet one of the purposes of this application includes the following steps:

[0007] intercepting a plurality of concurrent data acquisition requests for acquiring a plurality of target data respectively, wherein at least some of the target data depend on the determination of another portion of the target data;

[0008] In response to each data acquisition request, each corresponding request thread is run to acquire corresponding target data;

[0009] Control one of the data acquisition requests to obtain a control lock, the data acquisition request that obtains the control lock starts a data initialization transaction to complete background calculation of the multiple target data, and releases the control lock after the data initialization transaction is successfully executed;

[0010] During the execution of the data initialization transaction, other request threads that have not obtained the control lock are controlled to sleep according to the dynamically updated sleep duration, and after the sleep period ends, attempts are made to obtain corresponding target data to respond to each corresponding data acquisition request.

[0011] In a further embodiment, controlling one of the data acquisition requests to obtain a control lock, the data acquisition request that obtains the control lock starts a data initialization transaction to complete the background calculation of the plurality of target data, and releasing the control lock after the data initialization transaction is successfully executed, comprises the following steps:

[0012] Pass the control lock to the first running request thread to exclude other request threads from obtaining the control lock;

[0013] The request thread that obtains the control lock starts a data initialization transaction, and through the transaction, multiple background intermediate components are called to calculate and determine multiple target data accordingly;

[0014] When the data initialization transaction is completed, the request thread that obtains the control lock marks the transaction completion status, stores the duration consumed by the current execution as the historical consumption duration, and releases the control lock;

[0015] Then, the data acquisition logic corresponding to the data acquisition request is executed to obtain the corresponding target data.

[0016] In a further embodiment, during the execution of the data initialization transaction, other request threads that have not obtained the control lock are controlled to sleep according to the dynamically updated sleep duration, and after the sleep ends, the corresponding target data is attempted to be obtained to respond to each corresponding data acquisition request, including the following steps:

[0017] The request thread that has not obtained the control lock is made to enter a dormant state before the transaction completion state is reached, and the dormant time is the preset historical consumption time;

[0018] When the sleep time is reached, the total sleep times of the request thread that has not obtained the control lock are counted;

[0019] The request thread that has not obtained the control lock detects whether the data initialization transaction has reached a transaction completion state after the sleep time has expired, and executes corresponding data acquisition logic to obtain the corresponding target data of the request thread after reaching the transaction completion state, otherwise the sleep process is cycled according to a preset sleep number of times.

[0020] In a preferred embodiment, the historical consumption time used to set the sleep time is the historical consumption time or the preset time generated by the previous data acquisition request.

[0021] In a further embodiment, before intercepting multiple concurrent data acquisition requests for acquiring multiple target data respectively, the following steps are included:

[0022] Obtaining a user request submitted by a client device;

[0023] Execute a first task to store original data corresponding to the user request in a database;

[0024] A second task is executed, in which a data acquisition request for acquiring a plurality of target data in the original data is triggered, so that the plurality of target data correspondingly acquired by the plurality of data acquisition requests are pushed to the client device.

[0025] In an extended embodiment, the user data is any one of user registration data, configuration data of an online store instance, and user membership data.

[0026] In a specific embodiment, during the execution of the data initialization transaction, other request threads that have not obtained the control lock are controlled to sleep according to the dynamically updated sleep duration, and after the sleep period ends, they try to obtain the corresponding target data to respond to each corresponding data acquisition request. The historical consumption time consumed by the request thread for the most recent execution of the data initialization transaction is used as the sleep duration to achieve dynamic update of the sleep duration.

[0027] A data collaborative initialization device provided to meet one of the purposes of the present application includes: a request interception module, a data acquisition module, a control lock module, and a sleep and restart module, wherein the request interception module is used to intercept multiple concurrent data acquisition requests for acquiring multiple target data, wherein at least part of the target data depends on the determination of another part of the target data; the data acquisition module is used to respond to each data acquisition request and run each corresponding request thread to acquire the corresponding target data; the control lock module is used to control one of the data acquisition requests to obtain a control lock, the data acquisition request that obtains the control lock starts a data initialization transaction to complete the background calculation of the multiple target data, and releases the control lock after the data initialization transaction is successfully executed; the sleep and restart module is used to control other request threads that have not obtained the control lock to sleep according to the dynamically updated sleep duration during the execution of the data initialization transaction, and try to obtain the corresponding target data after the sleep ends to respond to each corresponding data acquisition request.

[0028] In a further embodiment, the control lock module includes: a control lock acquisition submodule, which is used to pass the control lock to the first running request thread to exclude other request threads from obtaining the control lock; a transaction start submodule, which is used to start a data initialization transaction by the request thread that obtains the control lock, and call multiple background intermediate components through the transaction for corresponding calculations to determine multiple target data; a control lock release submodule, which is used to mark the transaction completion status by the request thread that obtains the control lock after the data initialization transaction is executed, store the time consumed by the current execution as the historical consumption time, and release the control lock; a target data submodule, which is used to subsequently execute the data acquisition logic corresponding to the data acquisition request to obtain the corresponding target data.

[0029] In a further embodiment, the sleep restart submodule includes: a sleep control submodule, used to make the request thread that has not obtained the control lock enter the sleep state before the transaction completion state is achieved, and its sleep duration is a preset historical consumption duration; a sleep statistics submodule, used to count the total number of sleep times of the request thread that has not obtained the control lock when the sleep duration is reached; a sleep judgment submodule, used to detect whether the data initialization transaction has reached the transaction completion state after the sleep duration is reached by the request thread that has not obtained the control lock, and execute the corresponding data acquisition logic to obtain the corresponding target data of the request thread after reaching the transaction completion state, otherwise loop its sleep process according to the preset sleep times.

[0030] In a preferred embodiment, the sleep determination submodule includes: a sleep duration unit, which is used to set the historical consumption duration of the sleep duration, which is the historical consumption duration or the preset duration generated by the previous data acquisition request.

[0031] In a further embodiment, the request interception module includes: a request acquisition module for acquiring a user request submitted by a client device; a first task module for executing a first task to store the original data corresponding to the user request in a database; and a second task module for executing a second task, in which a data acquisition request for acquiring multiple target data in the original data is triggered, so as to push the multiple target data obtained in response to the multiple data acquisition requests to the client device.

[0032] In a specific embodiment, the sleep and restart module uses the historical consumption time consumed by the request thread for the latest execution of the data initialization transaction as the sleep time to achieve dynamic update of the sleep time.

[0033] A computer device provided to meet one of the purposes of the present application includes a central processing unit and a memory, wherein the central processing unit is used to call and run a computer program stored in the memory to execute the steps of the data collaborative initialization method described in the present application.

[0034] A computer-readable storage medium is provided for the purpose of the present application, which stores a computer program implemented according to the data collaborative initialization method in the form of computer-readable instructions. When the computer program is called and executed by a computer, the steps included in the method are executed.

[0035] Compared with the prior art, the advantages of this application are as follows:

[0036] First, by responding to a data acquisition request that arrives at the server first and running the corresponding request thread, it is controlled to obtain the control lock and execute the data initialization transaction. Other request threads that have not obtained the control lock sleep according to the dynamically updated sleep time. The control lock is used to achieve coordination and control between multiple data acquisition requests to avoid conflicts, thereby ensuring that concurrent data requests obtain the target data in an orderly manner.

[0037] Secondly, when a request thread that has not obtained a control lock is dormant, its dormancy duration is allowed to be dynamically updated, making the dormancy time more flexible and able to adapt to changes in actual business scenarios, more accurately control the dormancy waiting time, and coordinate the time connection between the thread that has obtained the control lock and the thread that has not obtained the control lock, so that a large number of concurrent request threads can work closely together to maximize efficiency.

[0038] In addition, the algorithm used in this application is simple and easy to implement, has high operating efficiency, can save server computer computing resources, and improve the utilization efficiency of computing and operating resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0040] Figure 1 A flowchart of a typical embodiment of the data collaborative initialization method of the present application;

[0041] Figure 2 A schematic diagram of the process of acquiring a control lock and initializing transaction execution in an embodiment of the present application;

[0042] Figure 3 A schematic diagram of the process of thread hibernation and restart execution in an embodiment of the present application;

[0043] Figure 4 A schematic diagram of the process of client request response in an embodiment of the present application;

[0044] Figure 5 This is a principle block diagram of the data collaborative initialization method of this application;

[0045] Figure 6 A schematic diagram of the structure of a computer device used in this application. DETAILED DESCRIPTION

[0046] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.

[0047] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0048] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.

[0049] It will be understood by those skilled in the art that the "client", "terminal" and "terminal device" used herein include both devices with wireless signal receivers, which are devices with only wireless signal receivers without transmission capabilities, and devices with receiving and transmitting hardware, which are devices with receiving and transmitting hardware capable of two-way communication on a two-way communication link. Such devices may include: cellular or other communication devices such as personal computers, tablet computers, which have single-line displays or multi-line displays or cellular or other communication devices without multi-line displays; PCS (Personal Communications Service, personal communication system), which can combine voice, data processing, fax and / or data communication capabilities; PDA (Personal Digital Assistant, personal digital assistant), which may include a radio frequency receiver, pager, Internet / intranet access, web browser, notepad, calendar and / or GPS (Global Positioning System, global positioning system) receiver; conventional laptop and / or palmtop computers or other devices, which have and / or include a conventional laptop and / or palmtop computer or other device with and / or including a radio frequency receiver. The "client", "terminal" and "terminal device" used herein may be portable, transportable, installed in a vehicle (air, sea and / or land), or suitable for and / or configured to run locally, and / or in a distributed form, at any other location on the earth and / or in space. The "client", "terminal" and "terminal device" used herein may also be a communication terminal, an Internet terminal, a music / video playing terminal, for example, a PDA, a MID (Mobile Internet Device) and / or a mobile phone with a music / video playing function, or a smart TV, a set-top box and other devices.

[0050] The hardware referred to by the names such as "server", "client", and "service node" in this application is essentially an electronic device with the equivalent capabilities of a personal computer. It is a hardware device with the necessary components revealed by the von Neumann principle, such as a central processing unit (including an arithmetic unit and a controller), a memory, an input device, and an output device. The computer program is stored in its memory, and the central processing unit calls the program stored in the external memory into the internal memory for execution, executes the instructions in the program, and interacts with the input and output devices to complete specific functions.

[0051] It should be pointed out that the concept of "server" referred to in this application can also be extended to the case of server clusters. According to the network deployment principle understood by those skilled in the art, the servers should be logically divided. In physical space, these servers can be independent of each other but can be called through interfaces, or integrated into a physical computer or a set of computer clusters. Those skilled in the art should understand this flexibility, and should not use it to restrict the implementation of the network deployment method of this application.

[0052] Unless expressly specified, one or more technical features of the present application can be deployed on a server for implementation and accessed by a client through a remote call to obtain an online service interface provided by the server, or can be directly deployed and run on a client for access.

[0053] Unless explicitly specified, the various data involved in this application can be stored remotely on a server or on a local terminal device, as long as it is suitable for being called by the technical solution of this application.

[0054] Those skilled in the art should be aware that, although the various methods of the present application are described based on the same concept and thus present commonality to each other, unless otherwise specified, these methods can be independently executed. Similarly, for each embodiment disclosed in the present application, they are all proposed based on the same inventive concept, therefore, concepts with the same expression, and concepts that are appropriately changed for convenience despite different expressions, should be understood as equivalent.

[0055] Unless the mutually exclusive relationship between the embodiments to be disclosed in this application is explicitly stated, the relevant technical features involved in each embodiment can be cross-combined to flexibly construct a new embodiment, as long as such combination does not deviate from the creative spirit of this application and can meet the needs of the prior art or solve certain deficiencies in the prior art. Those skilled in the art should be aware of this flexibility.

[0056] See also Figure 1 The data collaborative initialization method of the present application, in its typical embodiment, comprises the following steps:

[0057] Step S1100, intercepting multiple concurrent data acquisition requests for respectively acquiring multiple target data, wherein at least some of the target data depend on the determination of another part of the target data;

[0058] Online e-commerce platforms often obtain multiple target data for initialization in concurrent request scenarios, such as a large number of member users who log in for the first time after registration, triggering the acquisition of initialization target data such as default level, avatar, and new user discount at the same time; a large number of platform store users who log in for the first time after registration, triggering the acquisition of initialization default UI template, store star rating, payment method, logistics method, etc. Initialization target data. In order to obtain these target data for initialization, generally multiple interfaces are requested, that is, the data acquisition request. Usually, there may be inherent correlations between these target data, that is, some target data need to determine another part of the target data before subsequent search, calculation, matching, etc. can be performed to obtain the part of the target data. Moreover, these target data need to be displayed or loaded on the corresponding interface at the same time. Therefore, it is necessary to uniformly initialize these target data, intercept the interface for obtaining these target data accordingly, and intercept these interfaces according to URI rules by setting an interceptor. The URI is a uniform resource identifier, which is used to uniquely identify a resource. Every resource available on the Web, such as HTML documents, images, video clips, programs, etc., is located by URI.

[0059] Step S1200, responding to each data acquisition request and running each corresponding request thread to acquire corresponding target data;

[0060] A large number of users input user information and click the login button at the same time, triggering the current interface to jump and responding to various data acquisition requests required for the first loading of the jump interface. Those skilled in the art should understand that multiple threads are created accordingly, and each thread concurrently calls the corresponding interface to obtain the target data. The concurrency is essentially a physical CPU (or multiple physical CPUs) multiplexing between several threads. Furthermore, first of all, during the concurrent execution of multiple threads, the relationship between the threads needs to be coordinated accordingly. General coordination methods include waiting, waking up, and executing. Finally, when the execution of multiple threads is completed, each thread is processed at the same time to obtain the corresponding target data.

[0061] Step S1300: Control one of the data acquisition requests to obtain a control lock, the data acquisition request that obtains the control lock starts a data initialization transaction to complete the background calculation of the multiple target data, and releases the control lock after the data initialization transaction is successfully executed;

[0062] In one embodiment, the thread queue selects the thread corresponding to the corresponding data acquisition request according to the first-in-first-out principle, controls the thread to obtain the control lock in the distributed lock mechanism, and is used to control the access of multiple data acquisition requests to resources. The thread queue is first sorted according to the time when the threads arrive at the server, and then according to the thread execution priority order, and then the sorted threads are input into the thread queue. Finally, the threads in the thread queue are output according to the first-in-first-out principle. The priority here can be flexibly set by technical personnel in this field as needed.

[0063] In another embodiment, the thread that firstly controls the data acquisition request that arrives at the server obtains the control lock.

[0064] The thread corresponding to the data acquisition request that obtains the control lock, during the period when the control lock is not released, is locked by only one thread, namely, the current thread that obtains the control lock, which can execute the data initialization operation, and the corresponding threads of other concurrent threads that also need to execute the data initialization operation are dormant and waiting. Therefore, the thread that obtains the control lock correspondingly starts the data initialization transaction, and completes the corresponding initialization operations such as background calculation and acquisition of the multiple target data within the transaction. If the initialization of one of the target data fails, the transaction is deemed to have failed, and all the target data are rolled back to the state before the transaction is executed, thereby avoiding dirty data. Until, after the rollback is completed, the corresponding distributed lock release method is called to release the control lock obtained by the thread. Further, the server constructs a data initialization failure prompt and pushes it to the client that triggered the aforementioned data acquisition request; if the initialization of all the target data is successful, the transaction is deemed to have succeeded, and the control lock obtained by the thread is automatically released.

[0065] The startup data initialization transaction is atomic, and all data initialization operations in the entire transaction are required to be completed or not completed at all, and cannot be stagnant in a certain link in the middle. If an error occurs during the execution of the transaction, it will be rolled back to the state before the start of the transaction, just as if the transaction has not been executed; and it is consistent, and the integrity constraints of the database are not violated before the start of the transaction and after the end of the transaction.

[0066] Step S1400: During the execution of the data initialization transaction, other request threads that have not obtained the control lock are controlled to sleep according to the dynamically updated sleep duration, and after the sleep period ends, attempt to obtain corresponding target data to respond to each corresponding data acquisition request.

[0067] During the period when one thread currently obtains the control lock to execute the data initialization transaction, other request threads respond to the control lock acquisition failure event and sleep according to the dynamically updated sleep time. In order to avoid deadlock caused by the control lock being held by one thread for a long time and unable to be released, the control lock is automatically released after holding the control lock for a period of time. The time required for automatic release (unit: milliseconds) can be set as a preset time, which can also be the sleep time of other threads that have not obtained the control lock. Until the other request thread sleeps for the preset sleep time, it is awakened to query the execution status of the data initialization transaction. Based on this, if the transaction is executed successfully, the initialization is obtained. Multiple target data will not be intercepted by the interceptor, and the target data will be used to respond to various data acquisition requests. The target data is any one or more of the UI framework, user information, member information, store information, etc. required by the interface; if the transaction fails to execute, other threads that have not obtained the control lock will sleep again, and the number of sleep times will be increased accordingly. Once the number of sleep times exceeds the preset threshold, they will no longer sleep and trigger a response to the data acquisition request execution failure event. The server constructs a data initialization failure prompt and pushes it to the client that triggered the aforementioned data acquisition request. The sleep duration and sleep number threshold are specifically preset here, which can be flexibly set by technical personnel in this field.

[0068] Preferably, the historical consumption time consumed by the request thread for the most recent execution of the data initialization transaction is used as the sleep time to achieve dynamic update of the sleep time. Before the historical consumption time is obtained, the sleep time can use a preset value, and the preset value can be continuously updated by the new historical consumption time.

[0069] Through the disclosure of this typical embodiment, it can be seen that the present application has many advantages, including but not limited to:

[0070] First, by responding to a data acquisition request that arrives at the server first and running the corresponding request thread, it is controlled to obtain the control lock and execute the data initialization transaction. Other request threads that have not obtained the control lock sleep according to the dynamically updated sleep time. The control lock is used to achieve coordination and control between multiple data acquisition requests to avoid conflicts, thereby ensuring that concurrent data requests obtain the target data in an orderly manner.

[0071] Secondly, when a request thread that has not obtained a control lock is dormant, its dormancy duration is allowed to be dynamically updated, making the dormancy time more flexible and able to adapt to changes in actual business scenarios, more accurately control the dormancy waiting time, and coordinate the time connection between the thread that has obtained the control lock and the thread that has not obtained the control lock, so that a large number of concurrent request threads can work closely together to maximize efficiency.

[0072] In addition, the algorithm used in this application is simple and easy to implement, has high operating efficiency, can save server computer computing resources, and improve the utilization efficiency of computing and operating resources.

[0073] In a further embodiment, step S1300, controlling one of the data acquisition requests to obtain a control lock, the data acquisition request that obtains the control lock starts a data initialization transaction to complete the background calculation of the plurality of target data, and releasing the control lock after the data initialization transaction is successfully executed, comprises the following steps:

[0074] Step S1310: passing the control lock to the first running request thread to exclude other request threads from obtaining the control lock;

[0075] The control lock is passed to the first request thread that arrives at the server. In one embodiment, the control lock is a Redis distributed lock, and the Redis SETNX command is used. The SETNX (SET if Not eXist) is to execute the set method if and only if the key does not exist, set the value of the key to value, and return 1; if the given key already exists, SETNX does not take any action and returns 0. Therefore, if 1 is returned, the control lock is successfully acquired, and if 0 is returned, the control lock fails to be acquired. After the corresponding request thread successfully acquires the control lock, other request threads respond to the failure event of acquiring the control lock, and perform a sleep operation to wait for the execution of the request thread that obtains the control lock.

[0076] Step S1320: The request thread that obtains the control lock starts a data initialization transaction, and calls multiple background intermediate components through the transaction to calculate and determine multiple target data accordingly;

[0077] The request thread for the control lock is obtained, and the EXPIRE command of Redis is called to set the validity period of the key. To prevent deadlock, the validity period is set by default to the longest execution time of the thread (unit: milliseconds), which can be updated later. Further, the data initialization transaction in the database is started, which has atomicity (Atomicity), that is, all operations in the transaction are inseparable in the database, either all are completed or not executed at all, and it is an inseparable work unit (unit). Based on this, multiple background intermediate components are called through the transaction, and each interface is called in turn according to the correlation between the data. When appropriate, corresponding calculations are performed to obtain relevant intermediate data such as method parameters, judgment condition parameters, etc. The transaction can only be an overall operation in two states: failure or success. On the one hand, due to network interruption and reconnection failure during the execution of the transaction, the network delay exceeds the preset program waiting time, which makes the corresponding If the transaction is not fully executed due to service timeout and subsequent service termination, the transaction is judged to have failed, and it is necessary to roll back the operations performed by the transaction, such as making many related changes to the database or updating multiple databases at the same time, and restore the data involved in the transaction execution process to the data state when the transaction was not executed, so as to ensure the reliability of database updates and the orderly execution of programs. At the same time, in response to the data initialization failure event, the server builds an error prompt and pushes it to the client that triggers the request corresponding to the thread, and correspondingly displays it in a message notification pop-up window on the user graphical interface to avoid the data initialization failure causing incomprehensible exceptions to the user. The error prompt should be a friendly prompt, such as: data initialization loading failed, please check the network status, if the network is normal, please refresh the page and wait, etc. On the one hand, when the transaction is executed correctly and in a complete, orderly manner, it is judged that the transaction is successfully executed, and multiple target data are determined.

[0078] Step S1330: After the data initialization transaction is executed, the request thread that obtains the control lock marks the transaction completion status, stores the duration consumed by the current execution as the historical consumption duration, and releases the control lock;

[0079] When the data initialization transaction is executed, the request thread that obtains the control lock marks the transaction completion status. In order to improve the query efficiency, the preset data initialization status is updated to true and stored in the cache. The preset data initialization status represents whether the data has been initialized. True represents completion and false represents incompleteness. The default setting is false. Therefore, it is convenient for the interceptor to query the data initialization status in the cache and quickly determine whether the data required by the user has been initialized. Accordingly, the data requests that have not been initialized are uniformly intercepted, and the data requests that have been initialized are released.

[0080] Furthermore, the duration consumed by the current execution of the data initialization transaction is stored as a historical consumption duration as an empirical value (unit: milliseconds), which is used to update the validity period of the control lock, so that the thread that also executes the data initialization transaction can rationally allocate the corresponding time slice to call the computing resources, reduce the invalid occupation time of the control lock that the thread has completed the data initialization operation, and relatively release the control lock as soon as possible to other threads, so as to promote each thread to execute the data initialization operation in an orderly and rapid manner. At this point, the control lock held by the thread that has completed the data initialization transaction is released.

[0081] Step S1340: then execute the data acquisition logic corresponding to the data acquisition request to obtain the corresponding target data.

[0082] Then, in response to the data acquisition request, the getter method in the initialized data acquisition interface is called to obtain the target data obtained after data initialization. Further, the target data is used for deployment, such as building the user interface of the user module, which includes the default UI template interface layout, user membership information, and basic information; the distribution interface of the distributor module, which includes distribution level information and promotion QR code information; the store interface of the online store module, which includes level information, payment and logistics information, etc.

[0083] In this embodiment, the corresponding time slices are rationally allocated to the request thread that obtains the control lock to call the computing resources, reducing the invalid occupation time of the thread that has completed the data initialization operation but still occupies the control lock, and relatively releasing the control lock as early as possible to let other threads hold it, so as to promote each thread to execute the data initialization operation in an orderly and fast manner. Furthermore, each time the request thread that obtains the control lock executes the data initialization transaction, the historical consumption time spent can be used as the sleep time of the request thread that does not obtain the control lock, so that the request thread that does not obtain the control lock can be awakened in time after the request thread that obtains the control lock completes the data initialization transaction, reducing the stagnation time between the two, and improving the overall operation efficiency.

[0084] In a further embodiment, step S1400, during the execution of the data initialization transaction, controlling other request threads that have not obtained the control lock to sleep according to the dynamically updated sleep duration, and after the sleep ends, attempting to obtain corresponding target data to respond to each corresponding data acquisition request, includes the following steps:

[0085] Step S1410, the request thread that has not obtained the control lock is made to enter a dormant state before the transaction completion state is reached, and the dormant time is the preset historical consumption time;

[0086] The control lock is a Redis distributed lock, which is a way to control the access of concurrent request threads to shared resources. When accessing these resources, mutual exclusion is often required to prevent interference with each other to ensure consistency. It has an exclusive characteristic, that is, although it is in a concurrent period, there are multiple request threads that need the control lock at the same time. Only one request thread can obtain the control lock at the same time, and the other request threads cannot obtain it and enter a dormant state. The corresponding dormancy time is initially configured by default to avoid deadlock. The maximum execution time of the request thread that currently obtains the control lock can be estimated by a technician in this field and flexibly set. In one embodiment, the requests corresponding to the dormant request thread and the request thread that currently obtains the control lock are the same. Furthermore, according to the consumption time of the initialization transaction executed by the request thread that obtains the control lock, that is, the historical consumption time, it is configured to be the dormant time of the dormant request thread.

[0087] Step S1420: When the sleep time is reached, the request thread that has not obtained the control lock counts the total number of sleep times of the request thread;

[0088] When the sleep time is reached, the request thread for obtaining the control lock will be awakened and a corresponding trigger response will be triggered to obtain the sleep count event of the request thread, and a preset statistical sleep count counter will be called. The counter is used to determine the state of not obtaining the control lock. Each time the sleep state is entered, the sleep count is increased accordingly. The default initial value is 0. Further, the current sleep count is returned as the total sleep count for not obtaining the control lock.

[0089] Step S1430: the request thread that has not obtained the control lock detects whether the data initialization transaction reaches the transaction completion state after the sleep time is reached, and executes the corresponding data acquisition logic to obtain the corresponding target data of the request thread after reaching the transaction completion state, otherwise the sleep process is cycled according to the preset sleep times.

[0090] Since the dormant request thread and the request thread that currently obtains the control lock have the same request corresponding to them, that is, they need to execute the same data initialization transaction, therefore, after the dormant time is reached, the request thread that has not obtained the control lock will be awakened to detect whether the data initialization transaction corresponding to the request thread that currently obtains the control lock is successfully executed to reach the transaction completion state. If it is in the completion state, the corresponding target data required by the request thread that has not obtained the control lock is obtained thereafter, and reference can be made to step S1340 for no repetition. On the contrary, if it is in the uncompleted state, it will enter the dormant state again thereafter to cycle its dormant process, and increase its dormancy times accordingly. If its current dormancy times reaches the preset dormancy times, the preset dormancy times is the dormancy upper limit, that is, when the dormancy upper limit is reached, a response data initialization failure event is triggered, and the server constructs an error prompt and pushes it to the client that triggers the request corresponding to the thread, and accordingly displays it in a message notification pop-up window on the user graphical interface to avoid the data initialization failure causing anomalies that the user cannot understand. The error prompt is a friendly prompt, such as: data initialization loading failed, please check the network status, if the network is normal, please refresh the page and wait for a while, etc.

[0091] In this embodiment, through an efficient sleep mechanism, isolating the request thread that has not obtained the control lock does not affect the execution of related services by the request thread that has obtained the control lock. Furthermore, the sleep duration is set accordingly to the time required for the historical execution of the same request, so that when the current control lock is released, it is awakened in time when the sleep duration is reached to execute related services, thereby achieving a response speed similar to that of a seamless connection.

[0092] In addition, since the historical consumption time is dynamically updated after each execution of the data initialization transaction and then configured as the sleep time, the sleep time can be dynamically updated to timely reflect the response status of the computer's operating resources, thereby ensuring that the coordination efficiency between threads is improved and the execution performance is improved.

[0093] In a preferred embodiment, the historical consumption duration used to set the sleep duration is the historical consumption duration or the preset duration generated by the previous data acquisition request.

[0094] According to the historical consumption time corresponding to the execution of the data initialization transaction by the request thread that currently obtains the control lock, it is set to be the same as its request, that is, the sleep time of the request thread that has not obtained the control lock and needs to execute the same data initialization transaction is the historical consumption time, and the corresponding sleep time of other request threads that have not obtained the control lock is the preset time. The preset time can be flexibly set by those skilled in the art to avoid deadlock by estimating the maximum execution time of the request thread that currently obtains the control lock.

[0095] After the request thread that currently obtains the control lock executes steps S1310 to S1340, after it releases the control lock, it wakes up the request thread that has not obtained the control lock, wherein, on the one hand, the request thread that has not obtained the control lock and corresponds to the same request as the request thread that currently obtains the control lock executes steps S1410 to S1430, and on the other hand, the request thread that has not obtained the control lock and corresponds to a request that is different from the request thread that currently obtains the control lock responds to the control lock acquisition event, the get method in the Redis distributed lock command, determines whether the lock exists and whether it has timed out, if the current control lock exists and has timed out, further, calls the getset method in the Redis distributed lock command, sets the current control lock to empty or sets the set control lock to be equal to the current control lock, at this point, the request thread obtains the control lock, and then, similarly executes steps S1320 to S1340.

[0096] The getset method first gets the old value, then sets the new value, and returns the old value of the key. It is atomic and returns an error when the key exists but is not a string type; when the key does not exist, it returns nil, which is null in Java.

[0097] In this embodiment, by rationally setting the sleep time of the request thread that has not obtained the control lock, it is prevented from sleeping too long, reduces unnecessary loss of time resources, and relatively improves the concurrent execution efficiency.

[0098] In a further embodiment, before step S1100, intercepting multiple concurrent data acquisition requests for respectively acquiring multiple target data, the following steps are included:

[0099] Step S1000: obtaining a user request submitted by a client device;

[0100] Get the user request submitted by the client device, and the user triggers the request to submit to the server

[0101] The user enters user information and password on the login graphical user interface of his terminal device for the first time to log in, clicks the login button, jumps to the member graphical user interface, and triggers the initialization target data request required to obtain the interface, which is used to complete the initialization deployment and build the graphical user interface. The request is sent to the server of this application, and the server responds to the request after receiving it. Further, the server obtains the initialization target data request submitted by the client device.

[0102] Step S1010, executing the first task to store the original data corresponding to the user request in the database;

[0103] Execute the first task to store the user unique identifier corresponding to the user information in the user request, access the user private database, and obtain the corresponding original data user information, such as user account, user nickname, user avatar, member level, points, member interface default UI template, etc. Further, store the original data in a Redis type cache database for subsequent quick calls.

[0104] Step S1020, executing the second task, triggering a data acquisition request for acquiring multiple target data in the original data in the second task, so as to push the multiple target data corresponding to the multiple data acquisition requests to the client device.

[0105] Execute the second task, trigger a data acquisition request in the second task, start a transaction corresponding to multiple target data in the original data in the Redis cache database, call related methods in order according to the required correlation between the multiple target data, and finally, after the transaction is successfully executed, obtain the multiple target data at the same time, further, construct member information corresponding to the user in the user section of the member graphical user interface based on this, and push the member information to the client device.

[0106] In this embodiment, by enabling database transactions, the integrity and consistency of the data are guaranteed to a certain extent, ensuring that the client device obtains complete and accurate data, thereby improving the human-computer interaction experience.

[0107] See also Figure 5 The present application provides a data collaborative initialization device, which is adapted to the data collaborative initialization method of the present application for functional deployment, including: a request interception module 1100, a data acquisition module 1200, a control lock module 1300, and a sleep restart module 1400, wherein the request interception module 1100 is used to intercept multiple concurrent data acquisition requests for acquiring multiple target data, wherein at least part of the target data depends on the determination of another part of the target data; the data acquisition module 1200 is used to respond to each data acquisition request and run each corresponding request thread to acquire the corresponding target data; the control lock module 1300 is used to control one of the data acquisition requests to obtain a control lock, and the data acquisition request that obtains the control lock starts a data initialization transaction to complete the background calculation of the multiple target data, and releases the control lock after the data initialization transaction is successfully executed; the sleep restart module 1400 is used to control other request threads that have not obtained the control lock to sleep according to the dynamically updated sleep duration during the execution of the data initialization transaction, and try to obtain the corresponding target data after the sleep ends to respond to each corresponding data acquisition request.

[0108] In a further embodiment, the control lock module 1300 includes: a control lock acquisition submodule, which is used to pass the control lock to the first running request thread to exclude other request threads from obtaining the control lock; a transaction start submodule, which is used to start a data initialization transaction by the request thread that obtains the control lock, and call multiple background intermediate components through the transaction for corresponding calculations to determine multiple target data; a control lock release submodule, which is used to mark the transaction completion status by the request thread that obtains the control lock after the data initialization transaction is executed, store the time consumed by the current execution as the historical consumption time, and release the control lock; a target data submodule, which is used to subsequently execute the data acquisition logic corresponding to the data acquisition request to obtain the corresponding target data.

[0109] In a further embodiment, the sleep restart submodule 1400 includes: a sleep control submodule, used to make the request thread that has not obtained the control lock enter the sleep state before the transaction completion state is achieved, and its sleep duration is a preset historical consumption duration; a sleep statistics submodule, used to count the total number of sleep times of the request thread that has not obtained the control lock when the sleep duration is reached; a sleep judgment submodule, used to detect whether the data initialization transaction has reached the transaction completion state after the sleep duration is reached by the request thread that has not obtained the control lock, and execute the corresponding data acquisition logic to obtain the corresponding target data of the request thread after reaching the transaction completion state, otherwise the sleep process is cycled according to the preset sleep times.

[0110] In a preferred embodiment, the sleep determination submodule includes: a sleep duration unit, which is used to set the historical consumption duration of the sleep duration, which is the historical consumption duration or the preset duration generated by the previous data acquisition request.

[0111] In a further embodiment, the request interception module 1100 includes: a request acquisition module for acquiring a user request submitted by a client device; a first task module for executing a first task to store the original data corresponding to the user request in a database; and a second task module for executing a second task, in which a data acquisition request for acquiring multiple target data in the original data is triggered, so as to push the multiple target data obtained in response to the multiple data acquisition requests to the client device.

[0112] In a specific embodiment, the sleep and restart module uses the historical consumption time consumed by the request thread for the latest execution of the data initialization transaction as the sleep time to achieve dynamic update of the sleep time.

[0113] In order to solve the above technical problems, the present application also provides a computer device. Figure 6As shown, a schematic diagram of the internal structure of a computer device. The computer device includes a processor, a computer-readable storage medium, a memory, and a network interface connected via a system bus. Among them, the computer-readable storage medium of the computer device stores an operating system, a database, and computer-readable instructions. The database may store a control information sequence. When the computer-readable instructions are executed by the processor, the processor can implement a data collaborative initialization method. The processor of the computer device is used to provide computing and control capabilities to support the operation of the entire computer device. The memory of the computer device may store computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor can execute the data collaborative initialization method of the present application. The network interface of the computer device is used to connect and communicate with a terminal. Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0114] In this embodiment, the processor is used to execute Figure 5 The memory stores the program code and various data required to execute the above modules or submodules. The network interface is used to transmit data between user terminals or servers. The memory in this embodiment stores the program code and data required to execute all modules / submodules in the live gift resource update of this application, and the server can call the program code and data of the server to execute the functions of all submodules.

[0115] The present application also provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the data collaborative initialization method of any embodiment of the present application.

[0116] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments of the present application can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a computer-readable storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0117] To sum up, the present application allocates control locks to orderly manage the execution of data initialization business in concurrent scenarios, further accurately controls the waiting time of threads, and promptly reflects the response status of computer running resources, thereby ensuring the improvement of coordination efficiency between threads and improving execution performance.

[0118] Those skilled in the art will appreciate that the various operations, methods, steps, measures, and schemes in the processes discussed in this application may be alternated, altered, combined, or deleted. Further, other steps, measures, and schemes in the various operations, methods, and processes discussed in this application may also be alternated, altered, rearranged, decomposed, combined, or deleted. Further, the steps, measures, and schemes in the prior art that are similar to those disclosed in this application may also be alternated, altered, rearranged, decomposed, combined, or deleted.

[0119] The above is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A data collaborative initialization method, characterized in that: The steps include: intercepting a plurality of concurrent data acquisition requests for acquiring a plurality of target data respectively, wherein at least some of the target data depend on the determination of another portion of the target data; In response to each data acquisition request, each corresponding request thread is run to acquire corresponding target data; Control one of the data acquisition requests to obtain a control lock, the data acquisition request that obtains the control lock starts a data initialization transaction to complete background calculation of the multiple target data, and releases the control lock after the data initialization transaction is successfully executed; During the execution of the data initialization transaction, other request threads that have not obtained the control lock are controlled to sleep according to the dynamically updated sleep duration, and after the sleep period ends, attempt to obtain corresponding target data to respond to each corresponding data acquisition request; The controlling one of the data acquisition requests obtains a control lock, the data acquisition request that obtains the control lock starts a data initialization transaction to complete the background calculation of the multiple target data, and the control lock is released after the data initialization transaction is successfully executed, including the following steps: Pass the control lock to the first running request thread to exclude other request threads from obtaining the control lock; The request thread that obtains the control lock starts a data initialization transaction, and through the transaction, multiple background intermediate components are called to calculate and determine multiple target data accordingly; When the data initialization transaction is completed, the request thread that obtains the control lock marks the transaction completion status, stores the time consumed by the current execution as the historical consumption time, and releases the control lock; Then, the data acquisition logic corresponding to the data acquisition request is executed to obtain the corresponding target data.

2. The data collaborative initialization method according to claim 1, characterized in that: During the execution of the data initialization transaction, other request threads that have not obtained the control lock are controlled to sleep according to the dynamically updated sleep duration, and after the sleep ends, corresponding target data are attempted to be obtained to respond to each corresponding data acquisition request, including the following steps: The request thread that has not obtained the control lock is made to enter a dormant state before the transaction completion state is reached, and the dormant time is the preset historical consumption time; When the sleep time is reached, the total sleep times of the request thread that has not obtained the control lock are counted; The request thread that has not obtained the control lock detects whether the data initialization transaction reaches the transaction completion state after the sleep time is reached, and executes the corresponding data acquisition logic to obtain the corresponding target data of the request thread after reaching the transaction completion state, otherwise the sleep process is cycled according to the preset sleep times.

3. The data collaborative initialization method according to claim 2, characterized in that: In the step of making the request thread that has not obtained the control lock enter a dormant state before the transaction completion state is reached, and the dormant period is a preset historical consumption period, the historical consumption period used to set the dormant period is the historical consumption period or the preset period generated by the previous data acquisition request.

4. The data collaborative initialization method according to any one of claims 1 to 3, characterized in that: Before intercepting multiple concurrent data acquisition requests for acquiring multiple target data, the following steps are included: Obtaining a user request submitted by a client device; Execute a first task to store original data corresponding to the user request in a database; A second task is executed, in which a data acquisition request for acquiring a plurality of target data in the original data is triggered, so that the plurality of target data corresponding to the plurality of data acquisition requests are pushed to the client device.

5. The data collaborative initialization method according to claim 4, characterized in that: In the step of executing the first task to store the original data corresponding to the user request in the database, the user data is any one of user registration data, configuration data of the online store instance, and user membership data.

6. The data collaborative initialization method according to claim 1, characterized in that: During the execution of the data initialization transaction, other request threads that have not obtained the control lock are controlled to sleep according to the dynamically updated sleep duration. After the sleep period ends, corresponding target data are attempted to be obtained to respond to each corresponding data acquisition request. The historical consumption time consumed by the request thread for the most recent execution of the data initialization transaction is used as the sleep duration to realize dynamic update of the sleep duration.

7. A data collaborative initialization device, characterized in that: include: a request interception module, used to intercept a plurality of concurrent data acquisition requests for respectively acquiring a plurality of target data, wherein at least some of the target data depend on the determination of another portion of the target data; A data acquisition module, used to respond to each data acquisition request and run each corresponding request thread to acquire corresponding target data; A control lock module, used for controlling one of the data acquisition requests to obtain a control lock, the data acquisition request that obtains the control lock starts a data initialization transaction to complete the background calculation of the multiple target data, and releases the control lock after the data initialization transaction is successfully executed; A sleep restart module, used to control other request threads that have not obtained the control lock to sleep according to the dynamically updated sleep duration during the execution of the data initialization transaction, and try to obtain corresponding target data after the sleep ends to respond to each corresponding data acquisition request; Wherein, the control lock module includes: A control lock acquisition submodule is used to transfer the control lock to the first request thread to be run, so as to exclude other request threads from obtaining the control lock; A transaction initiation submodule, used for initiating a data initialization transaction by a request thread that obtains the control lock, and calling multiple background intermediate components through the transaction for corresponding calculation to determine multiple target data; A control lock release submodule, which is used to mark the transaction completion status by the request thread that obtains the control lock after the data initialization transaction is executed, store the time consumed by the current execution as the historical consumption time, and release the control lock; The target data submodule is used to subsequently execute the data acquisition logic corresponding to the data acquisition request to obtain the corresponding target data.

8. A computer device comprising a central processing unit and a memory, characterized in that: The central processing unit is used to call and run the computer program stored in the memory to execute the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: It stores a computer program implemented according to the method described in any one of claims 1 to 6 in the form of computer-readable instructions, and when the computer program is called and executed by a computer, the steps included in the corresponding method are executed.