Method and device for implementing different-to-same conversion of distributed applications
By forming a waiting thread in the waiting queue and using the thread wake-up method, the resource waste and memory overflow problems caused by loop waiting in distributed applications are solved, and the synchronous return of asynchronous response results is achieved, reducing the probability of system errors.
Patent Information
- Application Number
- CN202110913117.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-10
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-08-10
AI Technical Summary
In the prior art, the different to the same implementation method in distributed applications adopts loop waiting, which leads to large resource consumption, which easily leads to waste of CPU resources and memory overflow, and in severe cases, it can lead to system paralysis.
By forming a waiting thread in the waiting queue, and using the thread wake-up method, the corresponding waiting thread is awakened according to the business identity identification, and the business processing results are returned to the user, avoiding loop waiting.
It effectively avoids the risk of memory overflow, reduces the probability of errors in distributed application systems, and improves the robustness and user experience of the system.
Smart Images

Figure CN113641472B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed technology, and in particular to a method and device for implementing the different-to-same conversion of distributed applications. Background Art
[0002] In distributed application scenarios, there are three calling methods: synchronous calling: the caller continues to wait for the return result during the calling process; asynchronous calling: the caller does not directly wait for the return result during the calling process, but performs other tasks, and the result return form is usually a callback function; different conversion: during the asynchronous calling process, the caller continues to wait until the call result is obtained.
[0003] From the user's perspective, for businesses that could have been processed in real time, users want to get the corresponding business results after clicking a button, rather than being told that the business has been accepted and then jumping to a page to find out through a query. In order to effectively improve user friendliness, distributed applications all use a different-to-same calling method. The different-to-same implementation method in the prior art generally uses a circular wait, but the circular wait is very performance-consuming. During the circular wait, it is necessary to continuously access the location of shared resources such as the memory where the business results are stored, which consumes a lot of resources and affects other businesses. When the business volume is large, it is easy to cause a waste of CPU resources, which can seriously lead to memory overflow, thereby causing the distributed application system to crash and all transactions to fail. Summary of the invention
[0004] The embodiment of the present invention provides a method for implementing the conversion of different distributed applications to the same distributed application, so as to avoid the risk of memory overflow and reduce the error probability of the distributed application system. The method includes:
[0005] After the first application service receives the user request, the request thread sends a service request message to other application services; the service request message includes a service serial number;
[0006] Receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity; the business identity records the host number and the request thread number of the request thread;
[0007] Receive business response messages asynchronously sent back by other application services, and determine the corresponding business identity according to the business serial number in the business response message;
[0008] Determine a thread wakeup method according to the business identity identifier;
[0009] By utilizing the thread awakening method, the corresponding waiting thread in the waiting queue is awakened according to the request thread number recorded in the business identity identifier, and the business processing result is returned to the user.
[0010] A method for implementing the conversion of different distributed applications into the same distributed application in a specific embodiment includes:
[0011] A preset identification storage database stores the corresponding relationship between the business serial number and the business identity identification.
[0012] Specifically, receiving the acceptance result fed back by other application services, generating a business identity, and forming a waiting thread in the waiting queue according to the business identity, including:
[0013] Receive the acceptance result from other application services. If the acceptance result is successful, generate a business identity.
[0014] The thread information and business identity of the request thread are saved in the waiting queue, the request thread is blocked, and a waiting thread is formed in the waiting queue.
[0015] In a specific embodiment, determining a thread wakeup method according to the service identity identifier includes:
[0016] Decompose the business identity to obtain the host number where the request thread is located;
[0017] Determine the component number of the host according to the host number;
[0018] According to the component number, a thread wake-up method bound to the component is determined.
[0019] Accordingly, the method for implementing the different-to-same conversion of distributed applications in another specific embodiment further includes:
[0020] A wake-up method storage database is preset, and the wake-up method storage database stores a correspondence between a host number, a component number, and a thread wake-up method.
[0021] In the specific embodiment of the present invention, the method for implementing the distributed application with different conversion and sameness is implemented in that the waiting queue is implemented in an array manner.
[0022] The business identity also records the array index of the waiting thread corresponding to the request thread in the waiting queue.
[0023] Accordingly, the thread awakening method is used to awaken the corresponding waiting thread in the waiting queue according to the request thread number recorded in the business identity, including:
[0024] The thread awakening method is called with the array index as a parameter to awaken the waiting thread corresponding to the request thread number recorded in the business identity in the waiting queue.
[0025] In a specific embodiment, returning the business processing result to the user includes:
[0026] After the waiting thread is awakened, the service response message is obtained according to the service response message serial number;
[0027] Assemble the business response message, obtain the business processing result, and return the business processing result to the user.
[0028] In a specific embodiment of the present invention, the first application service includes a plurality of hosts;
[0029] The first host is used for:
[0030] After receiving the user request, the request thread sends a request message to other application services;
[0031] Receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity;
[0032] By using the thread awakening method, according to the request thread number recorded in the business identity, the corresponding waiting thread in the waiting queue is awakened, and the business processing result is returned to the user;
[0033] Any other host for:
[0034] Receive business response messages asynchronously sent back by other application services, and determine the corresponding business identity according to the business serial number in the business response message;
[0035] A thread wake-up method is determined according to the service identity.
[0036] In another specific embodiment, the method for implementing the different-to-same conversion of distributed applications further includes:
[0037] When the first application service receives a service request message sent by a request thread of another application service, it feeds back the acceptance result to the other application service;
[0038] A service response message is generated according to the service request message, and the service response message is asynchronously transmitted to other application services.
[0039] Specifically, according to the service request message, a service response message is generated, including:
[0040] According to the service request message, obtain the service serial number;
[0041] Use the business serial number as the message header to generate a business response message.
[0042] The embodiment of the present invention further provides a distributed application different conversion same implementation device, which is used to avoid the risk of memory overflow and reduce the error probability of the distributed application system. The device includes:
[0043] A service request module, which is used for the first application service to send a service request message to other application services after receiving a user request; the service request message includes a service serial number;
[0044] The thread waiting module is used to receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity; the business identity records the host number and the request thread number of the request thread;
[0045] The response message processing module is used to receive the business response message asynchronously returned by other application services, and determine the corresponding business identity according to the business serial number in the business response message;
[0046] A thread wake-up method determination module, used to determine a thread wake-up method according to the service identity identifier;
[0047] The thread awakening module is used to use the thread awakening method to wake up the corresponding waiting thread in the waiting queue according to the request thread number recorded in the business identity identifier, and return the business processing result to the user.
[0048] The apparatus for implementing the different-to-same conversion of distributed applications in a specific embodiment further includes:
[0049] The identification storage preset module is used to preset an identification storage database, in which the corresponding relationship between the business serial number and the business identity identification is stored.
[0050] Specifically, the thread waiting module is specifically used for:
[0051] Receive the acceptance result from other application services. If the acceptance result is successful, generate a business identity.
[0052] The thread information and business identity of the request thread are saved in the waiting queue, the request thread is blocked, and a waiting thread is formed in the waiting queue.
[0053] In a specific embodiment of the present invention, the thread wake-up method determination module is specifically used to:
[0054] Decompose the business identity to obtain the host number where the request thread is located;
[0055] Determine the component number of the host according to the host number;
[0056] According to the component number, a thread wake-up method bound to the component is determined.
[0057] Accordingly, the apparatus for implementing the different-to-same conversion of distributed applications in another specific embodiment further includes:
[0058] The wake-up method preset module is used to preset a wake-up method storage database, wherein the wake-up method storage database stores the correspondence between the host number, the component number and the thread wake-up method.
[0059] In a specific embodiment, the waiting queue is implemented in an array manner.
[0060] The business identity also records the array index of the waiting thread corresponding to the request thread in the waiting queue.
[0061] Accordingly, the thread wake-up module is specifically used for:
[0062] The thread awakening method is called with the array index as a parameter to awaken the waiting thread corresponding to the request thread number recorded in the business identity in the waiting queue.
[0063] In a specific embodiment, the thread wake-up module is specifically used to:
[0064] After the waiting thread is awakened, the service response message is obtained according to the service response message serial number;
[0065] Assemble the business response message, obtain the business processing result, and return the business processing result to the user.
[0066] Furthermore, the distributed application conversion implementation device in another specific embodiment further includes: a service feedback module, which is used to:
[0067] When the first application service receives a service request message sent by a request thread of another application service, it feeds back the acceptance result to the other application service;
[0068] A service response message is generated according to the service request message, and the service response message is asynchronously transmitted to other application services.
[0069] Specifically, the business feedback module is specifically used to:
[0070] According to the service request message, obtain the service serial number;
[0071] Use the business serial number as the message header to generate a business response message.
[0072] An embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method for implementing the distributed application in a different-to-same manner when executing the computer program.
[0073] An embodiment of the present invention also provides a computer-readable storage medium, which stores a computer program for executing the above-mentioned method for implementing the distributed application in a different-to-same manner.
[0074] In the embodiment of the present invention, after the first application service receives the user request, the request thread sends a service request message to other application services; wherein the service request message includes a service serial number; the acceptance result fed back by other application services is received, a service identity is generated, and a waiting thread is formed in a waiting queue according to the service identity; the service identity records the host number and the request thread number of the request thread; the service response message asynchronously transmitted back by other application services is received, and the corresponding service identity is determined according to the service serial number in the service response message; the thread awakening method is determined according to the service identity; the thread awakening method is used to awaken the corresponding waiting thread in the waiting queue according to the request thread number recorded in the service identity, and the service processing result is returned to the user. By forming a waiting thread and adopting a blocking thread method, the synchronous return of the asynchronous response result is realized, thereby avoiding the risk of memory overflow caused by the circular waiting method, and thus reducing the error probability of the distributed application system. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0076] Figure 1 It is a schematic diagram of a method for implementing different conversions of distributed applications in an embodiment of the present invention.
[0077] Figure 2 It is a schematic diagram of a method for implementing different conversions of distributed applications in a specific embodiment of the present invention.
[0078] Figure 3 Schematic diagram of a method for implementing step 102 in a specific embodiment of the present invention.
[0079] Figure 4 FIG. 1 is a schematic diagram of a method for implementing step 104 in a specific embodiment of the present invention.
[0080] Figure 5 It is a schematic diagram of a method for implementing different-to-same conversion of distributed applications in another specific embodiment of the present invention.
[0081] Figure 6 Schematic diagram of a method for implementing step 105 in a specific embodiment of the present invention.
[0082] Figure 7 The present invention is a schematic diagram of an implementation process of generating a service response message according to a service request message in another specific embodiment of the present invention.
[0083] Figure 8 It is a schematic diagram of the overall architecture of the different-to-same implementation scheme of distributed applications in a specific example of the present invention.
[0084] Fig. 9 It is a business process diagram of a distributed application system in a specific example of the present invention.
[0085] Fig.10 It is a schematic diagram of the processing process in which the request thread and the response message processing thread are not on the same host in a specific example of the present invention.
[0086] Fig.11 Schematic diagram of a device for implementing different conversions of distributed applications in an embodiment of the present invention.
[0087] Fig.12 It is a schematic diagram of a device for implementing different conversions of distributed applications in a specific embodiment of the present invention.
[0088] Fig.13 It is a schematic diagram of a device for implementing different conversions of distributed applications in another specific embodiment of the present invention.
[0089] Fig.14 It is a schematic diagram of a device for implementing different conversions of distributed applications in another specific embodiment of the present invention. DETAILED DESCRIPTION
[0090] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0091] The embodiment of the present invention provides a method for implementing the conversion of different distributed applications to the same distributed application, so as to avoid the risk of memory overflow and reduce the error probability of the distributed application system. Figure 1 As shown, the method includes:
[0092] Step 101: After the first application service receives the user request, the request thread sends a service request message to other application services; the service request message includes a service serial number;
[0093] Step 102: receiving the acceptance result fed back by other application services, generating a business identity, and forming a waiting thread in a waiting queue according to the business identity; wherein the business identity records the host number and the request thread number of the request thread;
[0094] Step 103: Receive a service response message asynchronously returned by other application services, and determine a corresponding service identity according to the service serial number in the service response message;
[0095] Step 104: Determine a thread wakeup method according to the service identity identifier;
[0096] Step 105: Using the thread awakening method, according to the request thread number recorded in the service identity, awaken the corresponding waiting thread in the waiting queue, and return the service processing result to the user.
[0097] Depend on Figure 1 It can be known from the process shown that in the embodiment of the present invention, after the first application service receives the user request, the request thread sends a business request message to other application services; wherein the business request message includes a business serial number; the acceptance result fed back by other application services is received, a business identity is generated, and a waiting thread is formed in the waiting queue according to the business identity; the business identity records the host number and the request thread number of the request thread; the business response message asynchronously transmitted back by other application services is received, and the corresponding business identity is determined according to the business serial number in the business response message; the thread wake-up method is determined according to the business identity; the thread wake-up method is used to wake up the corresponding waiting thread in the waiting queue according to the request thread number recorded in the business identity, and the business processing result is returned to the user. By forming a waiting thread and adopting a blocking thread method, the synchronous return of the asynchronous response result is realized, thereby avoiding the risk of memory overflow caused by the circular waiting method, and thus reducing the error probability of the distributed application system.
[0098] In the specific implementation, there are multiple application services in the distributed application system. First, after the first application service receives the user request, the request thread sends a service request message to other application services. Among them, the service request message contains a service serial number, which is the service field corresponding to the user request and is generally stored in the message header of the service request message.
[0099] After the request thread sends a service request message to other application services, it receives the acceptance result fed back by other application services, generates a service identity, and forms a waiting thread in the waiting queue according to the service identity. The service identity records the host number and the request thread number of the request thread. Specifically, there is a one-to-one correspondence between the service serial number and the service identity. In a specific embodiment, a method for implementing the different conversion of distributed applications is also provided, such as Figure 2 As shown, in Figure 1 On the basis of
[0100] Step 201: Preset the identification storage database.
[0101] The identification storage database stores the corresponding relationship between the business serial number and the business identity.
[0102] Specifically, the acceptance result fed back by other application services is received, a business identity is generated, and a waiting thread is formed in the waiting queue according to the business identity. Figure 3 As shown, including:
[0103] Step 301: Receive the acceptance result fed back by other application services. If the acceptance result is successful, generate a business identity;
[0104] Step 302: Save the thread information and business identity of the request thread to the waiting queue, block the request thread, and form a waiting thread in the waiting queue.
[0105] After forming a waiting thread, receiving the business response message asynchronously returned by other application services, and determining the corresponding business identity according to the business serial number in the business response message. Specifically, the business identity corresponding to the business serial number can be obtained by querying the business serial number in a preset identification storage database.
[0106] After determining the corresponding business identity, determine the thread wake-up method based on the business identity. Figure 4 As shown, including:
[0107] Step 401: disassemble the business identity to obtain the host number where the request thread is located;
[0108] Step 402: Determine the component number of the host according to the host number;
[0109] Step 403: Determine the thread wakeup method bound to the component according to the component number.
[0110] In a specific embodiment, different component names are registered for hosts in a distributed application system through enterprise-level component technology. The component names correspond to the host numbers one by one. The component number of the host can be obtained through the host number, and the specified thread on the host can be awakened through the unique method bound to the component. Therefore, another specific embodiment provides a method for implementing the same implementation of different conversion of distributed applications, such as Figure 5 As shown, in Figure 1 On the basis of
[0111] Step 501: Preset the wake-up method storage database.
[0112] The wake-up method storage database stores the corresponding relationship between the host number, the component number and the thread wake-up method.
[0113] After determining the thread wake-up method, the thread wake-up method is used to wake up the corresponding waiting thread in the waiting queue according to the request thread number recorded in the business identity, and the business processing result is returned to the user.
[0114] Among them, after the first application service receives the business response message asynchronously returned by other application services, it generally stores the business response message in a unified manner in the database and only records the business response message serial number. Therefore, the business processing result is returned to the user. The specific implementation process is as follows: Figure 6 As shown, including:
[0115] Step 601: After the waiting thread is awakened, the service response message is obtained according to the service response message serial number;
[0116] Step 602: Assemble the service response message, obtain the service processing result, and return the service processing result to the user.
[0117] In a specific embodiment, to wake up a specified waiting thread on the host, it is necessary to locate the information of the waiting thread in the waiting queue through the request thread number recorded in the business identity identifier. In order to further reduce the time of searching for the thread, the waiting queue in the specific embodiment is implemented in an array manner, and the business identity identifier also records the array index of the waiting thread corresponding to the request thread in the waiting queue.
[0118] Accordingly, the implementation process of step 105 includes: taking the array index as a parameter, calling the thread awakening method, and awakening the waiting thread corresponding to the request thread number recorded in the service identity in the waiting queue.
[0119] In the specific implementation process, the first application service includes multiple hosts, and the different conversion methods of the distributed application are not implemented on the same host. Specifically, the first host is used to:
[0120] After receiving the user request, the request thread sends a request message to other application services;
[0121] Receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity;
[0122] Using the thread wake-up method, according to the request thread number recorded in the business identity, the corresponding waiting thread in the waiting queue is woken up, and the business processing result is returned to the user;
[0123] Any other host for:
[0124] Receive business response messages asynchronously sent back by other application services, and determine the corresponding business identity according to the business serial number in the business response message;
[0125] Determine the thread wake-up method based on the business identity.
[0126] In addition, a method for implementing the distributed application in a different manner and the same manner provided in another specific implementation of the present invention further includes:
[0127] When the first application service receives a service request message sent by a request thread of another application service, it feeds back the acceptance result to the other application service;
[0128] Generate a business response message based on the business request message, and transmit the business response message asynchronously to other application services.
[0129] That is, when the first application service is used as a service processor of other application services, it needs to receive the service request message sent by the request thread of other application services, feedback the acceptance result, and asynchronously transmit the service response message to other application services. In other words, in a specific embodiment, after the first application service receives the user request, when the request thread sends the service request message to other application services, the other application services are used to feedback the acceptance result to other application services; generate a service response message according to the service request message, and asynchronously transmit the service response message to other application services.
[0130] Among them, the implementation process of generating a business response message according to the business request message is as follows: Figure 7 As shown, including:
[0131] Step 701: Obtain a service serial number according to the service request message;
[0132] Step 702: Use the service serial number as the message header to generate a service response message.
[0133] In this way, the business serial number is transmitted in the message, thereby ensuring that the business response message can correspond to the business identity identifier, and then after receiving the business response message, the designated waiting thread can be awakened.
[0134] A specific example is given below to illustrate how the embodiment of the present invention performs the different conversion of distributed applications to the same implementation.
[0135] Application service A sends a service request through the public API of application service B, but this API can only return success / failure (hereinafter referred to as acceptance result). The actual processing result (hereinafter referred to as business result) is returned asynchronously through another communication method later. In order to improve the user experience, the asynchronously returned business result needs to be returned to the customer synchronously, that is, the acceptance result is transparent from the user's perspective. In this application scenario, the existing methods for implementing different-to-same conversion include:
[0136] Circular waiting: Application service A calls application service B with a request, and keeps querying in a loop until there is a business result (timeout can be set). The business result can be in memory, or in redis cache or MySQL database. However, circular waiting is very performance-consuming. During the circular waiting process, it is necessary to continuously access the location of shared resources such as memory where the business result is stored, which consumes a lot of resources and affects other businesses. When the business volume is large, it is easy to waste CPU resources, and even lead to memory overflow, which will cause system paralysis and all transactions to fail.
[0137] Dubbo blocking thread: Application service A generates a unique request ID internally and sends it to application service B. If the request is successful, application service A uses Map to store the corresponding relationship and blocks the business thread to wait. Application service A receives the asynchronous business result, finds the corresponding request thread by ID, and wakes up the corresponding thread. Dubbo blocking thread is currently a more reasonable solution, but in this method, the request ID needs to be sent to a third-party server, which has strong coupling. In actual applications, third-party services need to provide services to different requesters, and adding dedicated technical fields involves a large transformation, which does not meet actual needs. At the same time, when using Map to store the corresponding relationship, the time complexity is O(n) when the host searches for the corresponding thread, which takes a long time. In addition, in multi-threaded application scenarios, Map has problems such as pointer exceptions when storing and deleting thread information, and the operation is complicated. In actual applications, there are certain risks in the business flow process.
[0138] Drawing on the experience of the above two methods, this example provides a distributed application conversion solution that aims to achieve the following functions:
[0139] (1) Realize the synchronous return of asynchronous response results without affecting performance and ensuring the correct operation of business processes;
[0140] (2) In distributed application scenarios, the request thread and the response thread are most likely not on the same host. Under this premise, the request thread and the response thread on different hosts are matched to ensure that the asynchronous response result is correctly returned to the caller;
[0141] (3) Under the premise of ensuring that the asynchronous response results are returned correctly, the time complexity of the asynchronous response to synchronous process is reduced, which effectively reduces the waiting time of the caller and improves user-friendliness.
[0142] Therefore, the design idea is as follows Figure 8As shown in the figure, we refer to the solution of Dubbo blocking thread, adopt the blocking thread method, realize the synchronous return of asynchronous response results, effectively avoid the problems such as memory overflow caused by circular waiting, and improve the robustness of the system. In order to ensure that the request threads and threads processing asynchronous response results on different hosts match, it is necessary to save the information of all waiting threads on each host, and at the same time, it is necessary to design a unique ID to identify the request and response of a business. In order to reduce the coupling between application service A and application service B, this ID needs to be saved in this distributed application system and needs to be shared by all hosts.
[0143] In the process of asynchronous to synchronous conversion, in addition to the normal message flow, the most time-consuming part is the process of the thread processing the asynchronous business results finding and waking up the corresponding waiting thread. Therefore, it is necessary to design a solution with a time complexity of O(1) to minimize the user's waiting time. Therefore, the wait-notify mechanism in this specific example is designed.
[0144] Specifically, in actual use, on the basis of realizing the suspension and awakening of threads, the mechanism must also support the awakening of specified threads, otherwise the result message cannot be correctly returned to the client. Through comparative analysis, the ReentrantLock+Condition method was finally selected to implement the wait-notify mechanism. ReentrantLock is used to control the reading and writing of the waiting queue (storing the threads waiting for the request service message) shared by the same host to ensure that the information of each waiting thread is correctly saved, and the wait and signal methods of Condition are used to realize the waiting and awakening of threads.
[0145] like Fig. 9 As shown, in the distributed application system, each host randomly receives the business request initiated by the user, and randomly processes the business response returned by the application service B. In order to match the request thread with the response thread, a unique ID (business identity) needs to be set. This ID needs to record the host where the request thread is located and its own thread number. The thread that processes the response message wakes up the specified thread on the specified host number according to this ID.
[0146] In order for the thread that processes the response message to obtain the ID information, the request thread needs to inform application service B of the ID through the message, and then let application service B bring it back. Since the ID information is a purely technical field, and application service B does not only provide services for application service A due to its own service attributes, it is unreasonable to pass the ID by modifying the message. Therefore, it is necessary to bind the ID to the business field, which is the business serial number.
[0147] In actual applications, the request thread will generate a business serial number NO1 and store it in the message header. When application service B sends a response message, it will put NO1 in the message header and send it back. Through the one-to-one correspondence between NO1 and ID, the ID can be transferred between the request thread and the thread that processes the response message. In order to allow all hosts to obtain the correspondence between the business serial number and the ID, this specific example uses database storage. The thread that processes the response message can find the ID information of the waiting thread in the database through the business serial number.
[0148] After the thread processing the response message obtains the host number and thread information of the corresponding waiting thread, it needs to go to the waiting queue of the specified host to obtain the thread information and wake up. The most direct way is to wake up the specified thread by calling a unique method on the host.
[0149] This specific example uses enterprise-level component technology to register different component names for hosts in a distributed application system. The component names correspond to the host numbers one by one. The thread that processes the response message can obtain the component number of the host through the host number in the ID, and wake up the specified thread on the host through the unique method bound to the component.
[0150] In order to wake up the specified thread on the host, it is necessary to locate the information of the waiting thread in the waiting queue through the ID. In order to reduce the time of searching for the thread, this specific example uses an array to implement the waiting queue, and the array index storing the thread information is also stored in the ID. The time complexity of implementing the thread search logic is O(1), which minimizes the user waiting time and improves the system availability.
[0151] Fig.10 This shows the process when the request thread and the response message processing thread are not on the same host:
[0152] (1) After receiving user request 2, host 1 in application service A sends a request message (user request 2) to application service B. After receiving a receipt of successful acceptance, it generates an ID and saves its own request thread information in the waiting queue, and the thread is suspended.
[0153] (2) Application service B asynchronously transmits the business response result back. Host 2 in application service A processes the response message. Host 2 stores the response message in the database and searches for ID_2 based on the business request serial number recorded in the response message. It then decomposes ID_2 to obtain the host number, thread number, and array index. It searches for the component method to be called based on the host number, calls the method with the response message serial number and array index as parameters, and wakes up the waiting thread of host 1.
[0154] (3) The wake-up thread wakes up the designated waiting thread in the waiting queue of host 1 and informs the waiting thread of the response message serial number. After being awakened, the waiting thread reads the database according to the response message serial number, assembles the response message and returns it to the user.
[0155] In addition, in order to prevent the waiting queue from being full due to the delay in returning the response message, this specific example also designs a reasonable timeout mechanism. Since the thread suspended using Condition does not support automatic interruption of waiting, it is necessary to actively release resources through the program. In this specific example, the timeout mechanism is implemented by saving the thread suspension time in the information recorded in the waiting queue. When a new request finds that the waiting queue is full, it traverses the waiting queue and clears the timed waiting threads.
[0156] This specific example uses component technology, ReentrantLock+Condition, cache and other technologies to implement a mechanism for synchronous transmission of asynchronous response messages, effectively reducing the number of repeated submissions or repeated queries by users, and effectively improving user friendliness. By reasonably designing the matching mode of waiting threads and response threads in the process of different-to-same conversion, the user waiting time is minimized to ensure that the entire process is processed within the user's waiting range.
[0157] It can be seen that the advantages of the distributed application different-to-same implementation solution provided in this specific example include:
[0158] In the past, when users wanted to query business results, they were generally informed that the business had been accepted, and then jumped to the page to find out through query, which was a poor user experience. This solution starts from the user's perspective and can get the corresponding business results after clicking a button, which can effectively improve user friendliness.
[0159] From a performance perspective, by blocking the waiting thread, waking up the response message processing thread, and then returning the response message to the user along with the response of the request message handler, the asynchronous response message processing thread is matched with the corresponding waiting thread, avoiding the risks of memory overflow caused by polling and reducing the probability of system errors.
[0160] Component technology is used to directly locate the host where the waiting thread is located, avoiding the time waste caused by polling. An array is used to store the waiting threads, and the waiting threads are directly located through the array index, which controls the time complexity to O(1) and minimizes the thread matching time.
[0161] The implementation of the above specific application is only an example, and the remaining implementation methods will not be described in detail one by one.
[0162] Based on the same inventive concept, the embodiment of the present invention further provides a distributed application different conversion same implementation device. Since the principle of the problem solved by the distributed application different conversion same implementation device is similar to the distributed application different conversion same implementation method, the implementation of the distributed application different conversion same implementation device can refer to the implementation of the distributed application different conversion same implementation method, and the repeated parts will not be repeated. The specific structure is as follows: Fig.11 As shown:
[0163] The service request module 1101 is used for the first application service to send a service request message to other application services after receiving the user request; wherein the service request message includes a service serial number;
[0164] The thread waiting module 1102 is used to receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity; the business identity records the host number and the request thread number of the request thread;
[0165] The response message processing module 1103 is used to receive the service response message asynchronously transmitted by other application services, and determine the corresponding service identity according to the service serial number in the service response message;
[0166] The thread wake-up method determination module 1104 is used to determine the thread wake-up method according to the service identity identifier;
[0167] The thread awakening module 1105 is used to use a thread awakening method to awaken the corresponding waiting thread in the waiting queue according to the request thread number recorded in the business identity identifier, and return the business processing result to the user.
[0168] The distributed application in the specific embodiment has different conversion and same implementation devices, such as Fig.12 As shown, in Fig.11 On the basis of
[0169] The identification storage preset module 1201 is used to preset an identification storage database, wherein the identification storage database stores the correspondence between the service serial number and the service identity.
[0170] In a specific embodiment, the thread waiting module 1102 is specifically used for:
[0171] Receive the acceptance result from other application services. If the acceptance result is successful, generate a business identity.
[0172] The thread information and business identity of the request thread are saved in the waiting queue, the request thread is blocked, and a waiting thread is formed in the waiting queue.
[0173] Specifically, the thread wake-up method determination module 1104 is specifically used to:
[0174] Disassemble the business identity and obtain the host number where the request thread is located;
[0175] According to the host number, determine the component number of the host;
[0176] According to the component number, determine the thread wake-up method bound to the component.
[0177] Accordingly, the different conversion and same implementation device of the distributed application provided in this specific embodiment is as follows: Fig.13 As shown, in Fig.11 On the basis of
[0178] The wake-up method preset module 1301 is used to preset a wake-up method storage database, wherein the wake-up method storage database stores the correspondence between the host number, the component number and the thread wake-up method.
[0179] In another specific embodiment, the waiting queue is implemented in an array manner. The business identity also records the array index of the waiting thread corresponding to the request thread in the waiting queue. Accordingly, the thread wake-up module 1104 is specifically used to:
[0180] The above thread wake-up method is called with the array index as a parameter to wake up the waiting thread corresponding to the request thread number recorded in the business identity in the waiting queue.
[0181] During the specific implementation process, the thread wake-up module 1104 in the embodiment of the present invention is specifically used to:
[0182] After the waiting thread is awakened, the business response message is obtained according to the business response message serial number;
[0183] Assemble the business response message, obtain the business processing result, and return the business processing result to the user.
[0184] In addition, in another specific embodiment, a distributed application is implemented in a different manner, such as Fig.14 As shown, in Fig.11 On the basis of
[0185] The service feedback module 1401 is used to:
[0186] When the first application service receives a service request message sent by a request thread of another application service, it feeds back the acceptance result to the other application service;
[0187] Generate a business response message based on the business request message, and transmit the business response message asynchronously to other application services.
[0188] Specifically, the service feedback module 1401 is specifically used to:
[0189] According to the service request message, obtain the service serial number;
[0190] Use the business serial number as the message header to generate a business response message.
[0191] An embodiment of the present invention further provides an electronic device, which can implement all steps in the method for implementing the distributed application in the above embodiment. For example, the electronic device can perform the following steps:
[0192] After the first application service receives the user request, the request thread sends a service request message to other application services;
[0193] Receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity;
[0194] Receive business response messages asynchronously sent back by other application services, and determine the corresponding business identity according to the business serial number in the business response message;
[0195] Determine the thread wake-up method based on the business identity;
[0196] Using the thread wake-up method, according to the request thread number recorded in the business identity, the corresponding waiting thread in the waiting queue is woken up, and the business processing result is returned to the user.
[0197] From the above description, it can be seen that the electronic device provided by the embodiment of the present application, after receiving the user request through the first application service, the request thread sends a business request message to other application services; wherein the business request message contains a business serial number; receiving the acceptance result fed back by other application services, generating a business identity identifier, and forming a waiting thread in the waiting queue according to the business identity identifier; the business identity identifier records the host number and the request thread number where the request thread is located; receiving the business response message asynchronously returned by other application services, and determining the corresponding business identity identifier according to the business serial number in the business response message; determining the thread wake-up method according to the business identity identifier; using the thread wake-up method, according to the request thread number recorded in the business identity identifier, wake up the corresponding waiting thread in the waiting queue, and return the business processing result to the user. By forming a waiting thread and adopting a blocking thread method, the synchronous return of the asynchronous response result is realized, thereby avoiding the risk of memory overflow caused by the circular waiting method, and thus reducing the error probability of the distributed application system.
[0198] The embodiment of the present invention also provides a computer-readable storage medium capable of implementing all the steps in the method for implementing the distributed application in the above embodiment. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, all the steps of the method for implementing the distributed application in the above embodiment are implemented. For example, when the processor executes the computer program, the following steps are implemented:
[0199] After the first application service receives the user request, the request thread sends a service request message to other application services; wherein the service request message includes a service serial number;
[0200] Receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity; the business identity records the host number and request thread number of the request thread;
[0201] Receive business response messages asynchronously sent back by other application services, and determine the corresponding business identity according to the business serial number in the business response message;
[0202] Determine the thread wake-up method based on the business identity;
[0203] Using the thread wake-up method, according to the request thread number recorded in the business identity, the corresponding waiting thread in the waiting queue is woken up, and the business processing result is returned to the user.
[0204] From the above description, it can be known that the computer-readable storage medium provided by the embodiment of the present invention, after receiving the user request through the first application service, the request thread sends a business request message to other application services; wherein the business request message contains a business serial number; receiving the acceptance result fed back by other application services, generating a business identity identifier, and forming a waiting thread in the waiting queue according to the business identity identifier; the business identity identifier records the host number and the request thread number where the request thread is located; receiving the business response message asynchronously returned by other application services, and determining the corresponding business identity identifier according to the business serial number in the business response message; determining the thread wake-up method according to the business identity identifier; using the thread wake-up method, according to the request thread number recorded in the business identity identifier, wake up the corresponding waiting thread in the waiting queue, and return the business processing result to the user. By forming a waiting thread and adopting a blocking thread method, the synchronous return of the asynchronous response result is realized, thereby avoiding the risk of memory overflow caused by the circular waiting method, and thus reducing the error probability of the distributed application system.
[0205] In summary, the method and device for implementing the different-to-same conversion of distributed applications provided by the embodiments of the present invention have the following advantages:
[0206] After the first application service receives the user request, the request thread sends a service request message to other application services; wherein the service request message includes a service serial number; the acceptance result fed back by other application services is received, a service identity is generated, and a waiting thread is formed in the waiting queue according to the service identity; the service identity records the host number and the request thread number of the request thread; the service response message asynchronously transmitted back by other application services is received, and the corresponding service identity is determined according to the service serial number in the service response message; the thread awakening method is determined according to the service identity; the thread awakening method is used to awaken the corresponding waiting thread in the waiting queue according to the request thread number recorded in the service identity, and the service processing result is returned to the user. By forming a waiting thread and adopting a blocking thread method, the synchronous return of the asynchronous response result is realized, thereby avoiding the risk of memory overflow caused by the circular waiting method, and thus reducing the error probability of the distributed application system.
[0207] Although the present invention provides method operation steps as described in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-creative labor. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the actual device or client product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, in a parallel processor or multi-threaded processing environment).
[0208] It should be understood by those skilled in the art that the embodiments of this specification may be provided as methods, devices (systems) or computer program products. Therefore, the embodiments of this specification may take the form of complete hardware embodiments, complete software embodiments or embodiments combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0209] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as a combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0210] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0211] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0212] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. In this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such a process, method, article or device. The orientation or position relationship indicated by the terms "upper", "lower", etc. is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present invention. Unless otherwise expressly specified and limited, the terms "installed", "connected" and "connected" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be a connection between the two components. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to the specific circumstances. It should be noted that the embodiments of the present invention and the features in the embodiments can be combined with each other in the absence of conflict. The present invention is not limited to any single aspect, nor to any single embodiment, nor to any combination and / or permutation of these aspects and / or embodiments. Moreover, each aspect and / or embodiment of the present invention can be used alone or in combination with one or more other aspects and / or embodiments thereof.
[0213] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and specification of the present invention.
Claims
1. A method for implementing the same implementation of different conversion of distributed applications, characterized in that: include: After the first application service receives the user request, the request thread sends a service request message to other application services; The service request message includes a service serial number; Receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity; the business identity records the host number and the request thread number of the request thread; Receive business response messages asynchronously sent back by other application services, and determine the corresponding business identity according to the business serial number in the business response message; Determine a thread wakeup method according to the business identity identifier; By utilizing the thread awakening method, the corresponding waiting thread in the waiting queue is awakened according to the request thread number recorded in the business identity identifier, and the business processing result is returned to the user.
2. The method for implementing the distributed application conversion from different to the same as claimed in claim 1, characterized in that: Also includes: A preset identification storage database stores the corresponding relationship between the business serial number and the business identity identification.
3. The method for implementing the distributed application conversion from different to the same as claimed in claim 1, characterized in that: Receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity, including: Receive the acceptance result from other application services. If the acceptance result is successful, generate a business identity. The thread information and business identity of the request thread are saved in the waiting queue, the request thread is blocked, and a waiting thread is formed in the waiting queue.
4. The method for implementing the distributed application conversion from different to the same as claimed in claim 1, characterized in that: Determining a thread wakeup method according to the business identity identifier includes: Decompose the business identity to obtain the host number where the request thread is located; Determine the component number of the host according to the host number; According to the component number, a thread wake-up method bound to the component is determined.
5. The method for implementing the distributed application conversion from different to the same as claimed in claim 4, characterized in that: Also includes: A wake-up method storage database is preset, and the wake-up method storage database stores a correspondence between a host number, a component number, and a thread wake-up method.
6. The method for implementing the distributed application conversion from different to the same as claimed in claim 1, characterized in that: The waiting queue is implemented in an array manner.
7. The method for implementing the distributed application conversion from different to the same as claimed in claim 6, characterized in that: The business identity also records the array index of the waiting thread corresponding to the request thread in the waiting queue.
8. The method for implementing the distributed application conversion from different to the same as claimed in claim 7, characterized in that: Using the thread awakening method, according to the request thread number recorded in the business identity, awakening the corresponding waiting thread in the waiting queue includes: The thread awakening method is called with the array index as a parameter to awaken the waiting thread corresponding to the request thread number recorded in the business identity in the waiting queue.
9. The method for implementing the distributed application conversion from different to the same as claimed in claim 1, characterized in that: Return the business processing results to the user, including: After the waiting thread is awakened, the service response message is obtained according to the service response message serial number; Assemble the business response message, obtain the business processing result, and return the business processing result to the user.
10. The method for implementing the distributed application conversion from different to the same as claimed in claim 1, characterized in that: The first application service includes a plurality of hosts; The first host is used for: After receiving the user request, the request thread sends a request message to other application services; Receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity; By using the thread awakening method, according to the request thread number recorded in the business identity, the corresponding waiting thread in the waiting queue is awakened, and the business processing result is returned to the user; Any other host for: Receive business response messages asynchronously sent back by other application services, and determine the corresponding business identity according to the business serial number in the business response message; A thread wake-up method is determined according to the service identity.
11. The method for implementing the distributed application conversion from different to the same as claimed in claim 1, characterized in that: Also includes: When the first application service receives a service request message sent by a request thread of another application service, it feeds back the acceptance result to the other application service; A service response message is generated according to the service request message, and the service response message is asynchronously transmitted to other application services.
12. The method for implementing the distributed application conversion from different to the same as claimed in claim 11, characterized in that: Generate a service response message based on the service request message, including: According to the service request message, obtain the service serial number; Use the business serial number as the message header to generate a business response message.
13. A distributed application different conversion same implementation device, characterized in that: include: A service request module, which is used for the request thread to send a service request message to other application services after the first application service receives the user request; The service request message includes a service serial number; The thread waiting module is used to receive the acceptance results fed back by other application services, generate a business identity, and form a waiting thread in the waiting queue according to the business identity; the business identity records the host number and the request thread number of the request thread; The response message processing module is used to receive the business response message asynchronously returned by other application services, and determine the corresponding business identity according to the business serial number in the business response message; A thread wake-up method determination module, used to determine a thread wake-up method according to the service identity identifier; The thread awakening module is used to use the thread awakening method to wake up the corresponding waiting thread in the waiting queue according to the request thread number recorded in the business identity identifier, and return the business processing result to the user.
14. The distributed application different-to-same implementation device according to claim 13, characterized in that: Also includes: The identification storage preset module is used to preset an identification storage database, in which the corresponding relationship between the business serial number and the business identity identification is stored.
15. The distributed application different-to-same implementation device according to claim 13, characterized in that: The thread waiting module is specifically used for: Receive the acceptance result from other application services. If the acceptance result is successful, generate a business identity. The thread information and business identity of the request thread are saved in the waiting queue, the request thread is blocked, and a waiting thread is formed in the waiting queue.
16. The distributed application different-to-same implementation device according to claim 13, characterized in that: The thread wake-up method determination module is specifically used for: Decompose the business identity to obtain the host number where the request thread is located; Determine the component number of the host according to the host number; According to the component number, a thread wake-up method bound to the component is determined.
17. The distributed application different-to-same implementation device according to claim 16, characterized in that: Also includes: The wake-up method preset module is used to preset a wake-up method storage database, wherein the wake-up method storage database stores the correspondence between the host number, the component number and the thread wake-up method.
18. The distributed application different-to-same implementation device according to claim 13, characterized in that: The waiting queue is implemented in an array manner.
19. The distributed application different-to-same implementation device according to claim 13, characterized in that: Also includes: Business feedback module, used to: When the first application service receives a service request message sent by a request thread of another application service, it feeds back the acceptance result to the other application service; A service response message is generated according to the service request message, and the service response message is asynchronously transmitted to other application services.
20. The distributed application different-to-same implementation device according to claim 19, characterized in that: The business feedback module is specifically used for: According to the service request message, obtain the service serial number; Use the business serial number as the message header to generate a business response message.
21. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 12 is implemented.
22. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Asynchronous production line type graph query method and asynchronous production line type graph query system
CN105260374A
Method for converting HTTP synchronous requests to asynchronous processing, and server
CN108319508A