Service calling method and device, electronic equipment, storage medium and program product

By opening a thread pool for the target service in the business middleware system to call the functional service in parallel, and caching the target data in the cache area, the performance problem caused by repeated requests is solved, and efficient service calls and real-time data are achieved.

CN120909810APending Publication Date: 2025-11-07BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410551585.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-06
Publication Date
2025-11-07

AI Technical Summary

Technical Problem

Existing technologies cannot effectively reduce unnecessary time consumption caused by duplicate data requests, especially in business middleware systems with multi-business scenario-based services, resulting in poor service call performance.

Method used

By creating a thread pool for the target service, multiple functional services can be called in parallel, and the target data can be cached in the cache area to avoid duplicate requests. By utilizing the data sharing mechanism between threads, the real-time performance and validity of the data can be ensured.

Benefits of technology

This effectively reduces unnecessary time consumption caused by repeated requests, improves service call performance, and ensures data real-time performance and the normal operation of business processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120909810A_ABST
    Figure CN120909810A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a service calling method and device, electronic equipment, a storage medium and a program product. The method comprises the steps that in response to a calling request, a thread pool is developed for a target service requested to be called, so that at least two threads are obtained from the thread pool, the at least two threads can be used for calling different function services in parallel, and the function services are services needing to be called for executing the target service; aiming at each obtained thread, calling a function service corresponding to the thread in the thread so as to obtain target data from the cache region and return the target data to the thread under the condition that the target data is cached in the cache region, the target data being obtained by performing a data request on a target object, and the target data being obtained by performing a data request on the target object; the target object is an object required to be requested for executing the function service; and obtaining a calling result of the target service according to the target data received by each thread, and returning the calling result to a calling party of the target service. According to the technical scheme of the embodiment of the invention, unnecessary time consumption can be effectively reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of computer technology, and in particular, to a service calling method and device, electronic equipment, storage medium and program product. BACKGROUND

[0002] With the continuous development of business, more and more system positioning has changed from the original single business system to the business middle platform system (i.e. domain product) that needs to undertake multi-business scenario service.

[0003] Under this background, capability reuse is particularly important for rapid iteration, which leads to the emergence of the technology of Business-Platform-as-a-service (BPaaS) supported by the theory of Domain-Driven Design (DDD).

[0004] Here, taking an after-sales business system as an example, based on the BPaaS technology, the system is split into independent multiple domain services to realize the after-sales domain product. However, reasonable function splitting plus the independence of domain services, this will appear the case of repeated data requests to the same object in response to the call of a service in the after-sales domain product, causing unnecessary time consumption. To this end, data caching can be used to reduce unnecessary time consumption.

[0005] In the process of implementing the present application, the inventors found that the prior art has the following technical problems: unable to effectively reduce unnecessary time consumption, which needs to be solved urgently. SUMMARY

[0006] Embodiments of the present application provide a service calling method and device, electronic equipment, storage medium and program product, which solve the problem of being unable to effectively reduce unnecessary time consumption.

[0007] According to an aspect of the present application, a service calling method can include:

[0008] In response to a call request, a thread pool is opened for a target service requested to obtain at least two threads from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function service is a service that needs to be called for executing the target service;

[0009] For each thread obtained, the function service corresponding to the thread is called in the thread to obtain target data from the cache area in the case that the cache area has the target data, and return the target data to the thread, wherein the target data is obtained by making a data request to a target object, and the target object is an object that needs to be requested for executing the function service;

[0010] According to the target data received by each thread respectively, the calling result of the target service is obtained, and the calling result is returned to the caller of the target service.

[0011] According to another aspect of the present application, a service calling device can include:

[0012] The thread obtaining module is configured to, in response to the calling request, open a thread pool for the target service to be called, and obtain at least two threads from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function service is a service to be called for executing the target service.

[0013] The target data first returning module is configured to, for each obtained thread, call the function service corresponding to the thread in the thread, and obtain the target data from the cache area and return the target data to the thread in a case that the target data is cached in the cache area, wherein the target data is obtained by making a data request to a target object, and the target object is an object to be requested for executing the function service.

[0014] The calling result returning module is configured to, according to the target data received by each thread respectively, obtain the calling result of the target service, and return the calling result to the caller of the target service.

[0015] According to another aspect of the present application, an electronic device can include:

[0016] at least one processor; and

[0017] a memory in communication with the at least one processor; wherein

[0018] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to implement the service calling method provided by any of the embodiments of the present application.

[0019] According to another aspect of the present application, a computer readable storage medium has stored thereon computer instructions for causing a processor to implement the service calling method provided by any of the embodiments of the present application.

[0020] According to another aspect of the present application, a computer program product has stored thereon a computer program for causing a processor to implement the service calling method provided by any of the embodiments of the present application.

[0021] The technical scheme of the embodiment of the application is that, in response to a calling request, a thread pool is opened for a target service requested to call, at least two threads are obtained from the thread pool, and each function service corresponding to the at least two threads is called in parallel to complete the calling of the target service; for each thread obtained, the function service corresponding to the thread is called in the thread, and in the case that target data requested from a target object corresponding to the function service is cached in a cache area, the target data is obtained from the cache area and returned to the thread, so that repeated requests for the target object are avoided; further, according to the target data received by each thread respectively, a calling result of the target service is obtained, and then the calling result is returned to the calling party of the target service. In the application scenario of calling multiple Flows in parallel (i.e. running multiple threads in parallel, and calling corresponding function services in the threads respectively), the target data requested for executing the function services is cached in the cache area accessible by the threads, so that repeated requests for the target object are avoided, i.e. unnecessary time consumption caused by repeated requests is effectively reduced, and service calling performance is improved.

[0022] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the application, nor is it used to limit the scope of the application. Other features of the application will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the application, the following will briefly introduce the drawings needed to be used in the embodiments description. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative effort on the basis of these drawings.

[0024] Figure 1 is a flow chart of a service calling method according to an embodiment of the application;

[0025] Figure 2 is a flow chart of another service calling method according to an embodiment of the application;

[0026] Figure 3 is a flow chart of another service calling method according to an embodiment of the application;

[0027] Figure 4 is a flow chart of another service calling method according to an embodiment of the application;

[0028] Figure 5 is a flow chart of an optional example of another service calling method according to an embodiment of the application;

[0029] Figure 6 is another service calling method according to an embodiment of the present application, and is a flow chart of processing of a corresponding interceptor when a target service with enabled cache is called;

[0030] Figure 7 is another service calling method according to an embodiment of the present application, and is a flow chart of processing of a corresponding interceptor when a target method with enabled cache is requested;

[0031] Figure 8 is another service calling method according to an embodiment of the present application, and is a flow chart of processing of a corresponding interceptor when a target method with enabled cache is requested; Figure 6 is a flow chart of execution of a corresponding query service single detail service;

[0032] Figure 9 is a structural block diagram of a service calling device according to an embodiment of the present application;

[0033] Figure 10 is a structural schematic diagram of an electronic device for implementing a service calling method according to an embodiment of the present application. DETAILED DESCRIPTION

[0034] In order to make the personnel in the technical field better understand the present application scheme, the technical scheme in the embodiments of the present application will be described clearly and completely below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by the personnel in the field without creative labor should belong to the protection scope of the present application.

[0035] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not have to be used to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. The case of "target", "original", and the like is similar, and will not be described here. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or device including a series of steps or units does not have to be limited to only those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to the process, method, product, or device.

[0036] Before introducing the embodiments of the present application, the data cache scheme applied in the service calling process described in the application scenario and background technology of the embodiments of the present application and the specific reasons why the scheme cannot effectively reduce unnecessary time consumption are exemplarily described, so as to better understand the following technical schemes.

[0037] For example, the after-sales business system is taken as an example here, and the after-sales business system is split into 13 sub-domains, 101 domain services and 101 extension points according to actual needs, the 13 sub-domains including a service order domain, a commodity domain, an order domain, a reason domain, a store domain, a message domain, a pick-up order domain and a receipt domain. The application aggregation layer is taken as an entrance, and the domain services are organized and coordinated in the form of nodes through data flow (Flow), to realize independent function points. The implementation layer of the interface calls the application aggregation layer to complete all business functions of the after-sales domain, and finally realizes the after-sales domain product. It can be understood that the above interface can be an interface exposed by a service in the after-sales domain product.

[0038] However, reasonable function splitting and independence of domain services will inevitably cause repetition of underlying implementation. For example, the after-sales domain product provides a query service order details service, which needs data of the above 13 sub-domains, and is divided into 3 Flows for parallel execution of combined data for performance, the 3 Flows including a query service order Flow, a query service order log Flow and a query pick-up order Flow, wherein the query service order, the query service order log and the query pick-up order are all domain services, and the underlying implementation of the two domain services of the query pick-up order and the query service order both depend on the request query service order method, such as requesting the query service order method through a remote procedure call protocol (RPC), that is, calling the query service order RPC, which causes the query service order details service to execute 2 times of the same RPC call, thereby causing unnecessary time consumption and poor performance.

[0039] It can be understood that the above 3 Flows can be executed in parallel in 3 threads. On this basis, a thread-level cache scheme can be used for data caching. Specifically, data sharing is performed within the current thread, and in combination with the open source transmittable-thread-local (TTL) technology, the child thread can also share the data in the parent thread (i.e. the main thread), which is suitable for scenarios where a major part of the business logic is executed in the main thread. However, in combination with the above example, when the query service order Flow and the query pick-up order Flow are executed in parallel, it is assumed that the query service order Flow calls the query service order RPC to obtain and cache data first, and since the data cached in a child thread cannot be used by other child threads, this makes the query pick-up order Flow still unable to use the cached data in the query service order Flow, that is, it still needs to call the query service order RPC again, thereby failing to effectively reduce the unnecessary time consumption caused by repeated requests.

[0040] To solve the above technical problems, the service calling scheme combined with data caching as set forth in the following embodiments is proposed. Next, this will be described in detail.

[0041] Figure 1 is a flowchart of a service calling method provided in an embodiment of the present application. The embodiment can be applicable to the case of service calling, especially the case of service calling through multi-thread or multi-Flow parallel processing. The method can be executed by a service calling device provided in the embodiment of the present application, which can be implemented in the form of software and / or hardware, and can be integrated on an electronic device, which can be various user terminals or servers, especially servers deploying target services.

[0042] Referring to Figure 1 , the method of the embodiment of the present application specifically includes the following steps:

[0043] S110, in response to the calling request, a thread pool is opened for the target service to be called to obtain at least two threads from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function service is a service to be called for executing the target service.

[0044] The calling request can be understood as a request for calling the target service initiated by a calling party, and the calling party can be understood as a machine (such as a server or a user terminal, etc.) requesting to call the target service. In response to the calling request, a thread pool is opened for the target service, and the thread pool includes two or more threads.

[0045] The function service can be understood as a service with a certain function to be called for executing the target service. In combination with the application scenarios that can be involved in the embodiment of the present application, it can be a domain service obtained based on the BPaaS technology. The number of function services can be two or more, which is related to the actual situation and is not limited here. Taking the above example as an example, in the after-sales field product, if the target service is a query service order details service, the function services can include a query service order service, a query service order log service, and a query pick-up order service.

[0046] On this basis, further, the number of threads corresponding to the number of services is acquired from the thread pool; then, each thread is one-to-one corresponding to each function service, so that the number of function services of the number of services can be called in parallel based on the number of threads, that is, the parallel calling of the number of function services of the number of services is realized, so as to ensure the calling performance of the target service. Continue to take the above example, 3 threads-thread 1, thread 2 and thread 3 can be acquired from the thread pool, thread 1 is assigned to the query service single service, thread 2 is assigned to the query service single log service, and thread 3 is assigned to the query pick-up single service, so that the query service single service can be called in thread 1, the query service single log service can be called in thread 2, and the query pick-up single service can be called in thread 3 in combination with subsequent steps.

[0047] S120, for each thread acquired, calling the function service corresponding to the thread in the thread to acquire the target data from the cache area in the case that the cache area has the target data, and returning the target data to the thread, wherein the target data is obtained by making a data request to a target object, and the target object is an object requested for executing the function service.

[0048] Wherein, the corresponding function service is called in each thread acquired respectively to obtain the calling result (i.e. target data) returned by the corresponding function service after being called. Each thread runs in parallel, so that each function service is executed in parallel. Here, taking any thread X in each thread as an example, the function service X corresponding to the thread X is called in the thread X, so as to receive the calling result returned by the function service X after being called.

[0049] On this basis, the function service X after being called, for executing the function service X, needs to make a data request to a target object X, that is, the target object X is an object requested for executing the function service X, which can be a target method, a target middleware or a target database, etc., which is related to the actual situation, and is not limited here.

[0050] It should be noted that in the application scenario involved in the embodiment of the application, at least two function services of the number of function services correspond to the same target object, so that after a function service in the at least two function services has made a data request to the target object and cached the requested target data in the cache area, the remaining function services can directly acquire the target data from the cache area without repeatedly requesting the target data, thereby effectively reducing unnecessary time consumption caused by repeated requests. The cache area can be a cache area in an electronic device running each thread, and each thread can access the cache area.

[0051] Therefore, after the function service X is invoked, it can be determined whether the target data is cached in the cache area, the target data being obtained by making a data request to the target object X, the target object X at least corresponding to the function service X. If the target data is cached in the cache area, it indicates that another function service Y corresponding to the target object X exists in addition to the function service X, and the function service Y has requested the target data from the target object X and cached the target data in the cache area before the function service X. Therefore, the target data can be directly obtained from the cache area, and the target data is returned to the thread X, completing the invocation of the function service X.

[0052] On this basis, the service invocation method can further include: in the case that the target data is not cached in the cache area, making a data request to the target object, and caching the target data returned by the target object in the cache area and returning the thread. In other words, in the case that the target data is not cached in the cache area, it indicates that the function service Y does not request the target data from the target object X, and then the function service X makes a data request to the target object X, and caches the requested target data in the cache area, so that the function service Y can subsequently directly obtain the target data from the cache area without repeatedly requesting the target object X, thereby effectively reducing unnecessary time consumption.

[0053] S130, obtaining the invocation result of the target service according to the target data respectively received by each thread, and returning the invocation result to the invoker of the target service.

[0054] Among them, after the corresponding function services are respectively invoked in each thread and the target data respectively returned by each function service is received, the invocation result of the target service can be obtained according to the target data, and then the invocation result is returned to the invoker of the target service, completing the invocation of the target service.

[0055] After the invocation result is returned to the invoker, the target data cached in the cache area can be optionally cleared, which can ensure that the target data obtained in response to subsequent invocation requests is real-time data, and can avoid effective use of the limited cache space in the cache area.

[0056] The technical scheme of the embodiment of the present application is that, in response to a calling request, a thread pool is opened for a target service requested to call, at least two threads are obtained from the thread pool, and each function service corresponding to the at least two threads is called in parallel to complete the calling of the target service; for each thread obtained, the function service corresponding to the thread is called in the thread, and in the case that target data requested from a target object corresponding to the function service is cached in a cache area, the target data is obtained from the cache area and returned to the thread, so that repeated requests for the target object are avoided; further, according to the target data received by each thread respectively, a calling result of the target service is obtained, and then the calling result is returned to the calling party of the target service. In the application scenario of parallel calling of multiple Flows (i.e. parallel running of multiple threads, and calling of corresponding function services in the threads respectively), the target data requested for execution of the function service is cached in the cache area accessible by each thread, so that repeated requests for the target object are avoided, i.e. unnecessary time consumption caused by repeated requests is effectively reduced, and service calling performance is improved.

[0057] Before introducing the following embodiments, a brief description of the data cached in the cache area is given. In order to avoid invalid occupation of the cache area, the data cached in the cache area can be cleared. There are two commonly used data clearing schemes, one of which is to set an expiration time for the data, so that the data is cleared when the expiration time is reached; the other is to clear the data when the electronic device is restarted. However, before the data is cleared, it cannot be guaranteed that such data cached (such as order status, service order status or commodity amount, etc.) remains unchanged, which leads to the fact that the data cached in the cache area is not necessarily real-time data, and further causes abnormal business process.

[0058] In order to solve the above technical problem, the service calling scheme described in the following embodiments is proposed. Next, this will be described in detail.

[0059] Figure 2 is a flowchart of another service calling method provided in the embodiment of the present application. The present embodiment is optimized on the basis of the above technical schemes. In the present embodiment, the obtaining of the target data from the cache area in the case that the target data is cached in the cache area can include: obtaining the target data from the cache area in the case that the target data requested in the response process of the calling request is cached in the cache area. The explanation of the same or corresponding terms as in the above embodiments is not repeated here.

[0060] Referring to Figure 2 , the method of the present embodiment can specifically include the following steps:

[0061] S210, in response to the calling request, a thread pool is opened for the target service requested to obtain at least two threads from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function service is a service required to be called for executing the target service.

[0062] S220, for each thread obtained, the function service corresponding to the thread is called in the thread to obtain the target data from the cache area in the case that the target data requested to the target object in the response process of the calling request is cached in the cache area, and return the target data to the thread, wherein the target object is an object required to be requested for executing the function service.

[0063] The target data is the data requested to the target object in the process of responding to the current calling request, and does not include the data requested in the process of responding to the historical calling request, thereby ensuring the real-time of the target data obtained from the cache area.

[0064] S230, according to the target data received by each thread respectively, the calling result of the target service is obtained, and the calling result is returned to the caller of the target service.

[0065] The technical scheme of the embodiment of the application limits that the target data can be obtained from the cache area only in the case that the target data is the data requested in the process of responding to the current calling request, otherwise the target object needs to be requested again, thereby ensuring that the target data in the return thread is real-time data, thereby ensuring the accuracy of the calling result returned to the caller.

[0066] In other words, the above service calling process is a calling process acting on the service (or said interface exposed by the service to the outside) life cycle, thereby ensuring the data real-time, and further ensuring the normal business process.

[0067] Figure 3 is a flowchart of another service calling method provided in the embodiment of the application. The embodiment is optimized on the basis of the above technical schemes. In the embodiment, for the parent thread of the thread, after responding to the calling request, the above service calling method further includes: generating a tracking identifier for the calling request in the parent thread, and storing the tracking identifier into the parent thread; after calling the function service corresponding to the thread in the thread, the above service calling method further includes: in the case that the tracking identifier is stored in the parent thread, obtaining the tracking identifier from the parent thread, and judging whether the target data corresponding to the tracking identifier is cached in the cache area. Wherein, the explanation of the same or corresponding terms as in the above embodiments is not repeated here.

[0068] Referring to Figure 3 The method of the embodiment can specifically include the following steps:

[0069] S310, in response to the invocation request, generating a trace identifier for the invocation request in the parent thread, and storing the trace identifier in the parent thread.

[0070] Wherein, after receiving the invocation request, a thread can be started for this time of invocation process for the target service, which is called the parent thread here, in order to correspond to the threads in the thread pool subsequently opened in the parent thread. The threads in the thread pool are the child threads of the parent thread.

[0071] A unique trace identifier (traceId) is generated for the invocation request in the parent thread, so that the invocation request this time can be represented based on the traceId subsequently. Further, the traceId is stored in the parent thread, for example, based on TTL technology, that is, put into TTL. The advantage of such setting is that since the child threads can share the data in the parent thread, the traceId can be obtained from the parent thread when the child threads are subsequently run.

[0072] S320, a thread pool is opened for the target service requested in the parent thread, to obtain at least two threads from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function service is a service that needs to be called for executing the target service.

[0073] S330, for each thread obtained, the function service corresponding to the thread is called in the thread to execute S340 and S350 in the thread.

[0074] S340, in the case where the trace identifier is stored in the parent thread, the trace identifier is obtained from the parent thread, and it is judged whether the target data corresponding to the trace identifier is cached in the cache area, wherein the target data is obtained by making a data request to a target object, and the target object is an object that needs to be requested for executing the function service.

[0075] Since the traceId obtained from the parent thread represents the invocation request this time, the target data corresponding to the traceId is the data requested in the process of responding to the invocation request this time. In this way, it can be judged whether the target data corresponding to the traceId is cached in the cache area, so as to obtain the target data with real-time performance from the cache area in the case of yes, in combination with the subsequent steps.

[0076] S350, in the case where the target data is cached in the cache area, the target data is obtained from the cache area, and the target data is returned to the thread.

[0077] S360, in the parent thread, the invocation result of the target service is obtained according to the target data received by each thread respectively, and the invocation result is returned to the invoker of the target service.

[0078] Wherein, the sub-thread can return the target data to the parent thread after receiving the target data returned by the invoked function service, or the parent thread directly reads the target data from the sub-thread, so that in the parent thread, the calling result can be obtained according to the target data received by each sub-thread, and then the calling result is returned to the calling party, completing the target service calling.

[0079] On this basis, optionally, further, the traceId stored in the parent thread can be cleared, for example, TTL is cleared, so as to avoid invalid occupation of storage space.

[0080] The technical scheme of the embodiment of the application generates a unique traceId for the current calling request in the parent thread, and a thread pool is opened in the parent thread, so that the sub-thread in the thread pool can obtain the traceId from the parent thread, and it is judged based on the traceId whether the cache area has cached the target data in real time (i.e. requested in the process of responding to the current calling request), thereby ensuring the accurate judgment of the target data.

[0081] An optional technical scheme, the above service calling method further comprises:

[0082] In the case of detecting the second cache mark for the target object, it is judged whether the trace identifier is stored in the parent thread.

[0083] Wherein, the second cache mark can represent that the target data requested from the target object needs to be cached, so after detecting the second cache mark, it can be further judged whether the traceId is stored in the parent thread, so as to obtain the cached data from the cache area in the case of yes. In other words, in the case of not detecting the second cache mark, it means that the target data requested from the target object does not need to be cached, so the cache area is not likely to have cached target data, and therefore there is no need to judge whether the traceId exists or not, and the target data can be directly requested.

[0084] The above technical scheme can judge whether the traceId exists when there is a possibility of caching the target data by detecting the second cache mark, thereby ensuring the effectiveness of the judgment action; and by setting the second cache mark, the target object that needs to be cached can be flexibly controlled, and the flexibility is better.

[0085] Another optional technical scheme, judging whether the cache area has cached the target data corresponding to the trace identifier comprises:

[0086] The request parameters applied when requesting the target object for executing the function service are obtained, and it is judged whether the cache area has cached the target data corresponding to the trace identifier and the request parameters.

[0087] Wherein, considering that the target data returned by the target object is not the same when requesting the same target object based on different request parameters. Therefore, when calling a certain function service, in order to ensure that the target data obtained from the cache area matches the function service, the request parameters applied when requesting the target object for the execution function service are obtained first, and then it is judged whether the target data corresponding to the traceId and the request parameters is cached in the cache area, so as to ensure the accuracy of the target data judgment.

[0088] For example, it is assumed that the data is cached in the cache area based on the nested structure concurrentHashMap, specifically concurrentHashMap<traceId, concurrentHashMap<request parameter, return value>>. Wherein, the outer key is traceId, the inner key is the request parameter (i.e. the method parameter), and the inner value is the return value (i.e. the method parameter, that is, the target data). In actual application, optionally, the return value can be deep copied and placed in the cache area to prevent the business logic from being modified.

[0089] Figure 4 is the flowchart of another service calling method provided in the embodiment of the application. The embodiment is optimized based on the above technical solutions. In the embodiment, optionally, a trace identifier is generated for the calling request in the parent thread, and the trace identifier is stored in the parent thread, including: in the case where the first cache mark for the target service is detected, a trace identifier is generated for the calling request in the parent thread, and the trace identifier is stored in the parent thread. Wherein, the explanations of the same or corresponding terms as in the above embodiments are not repeated here.

[0090] Referring to Figure 4 , the method of the embodiment can specifically include the following steps:

[0091] S410, in response to the calling request, in the case where the first cache mark for the target service is detected, a trace identifier is generated for the calling request in the parent thread, and the trace identifier is stored in the parent thread.

[0092] Wherein, the first cache mark can represent that data caching needs to be performed in the target service calling process, so that the traceId can be generated after the first cache mark is detected, so that subsequent steps related to data caching can be performed based on the traceId, thereby ensuring the effectiveness of the traceId generation.

[0093] S420, a thread pool is opened for the target service called by the request in the parent thread, and at least two threads are obtained from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function service is a service that needs to be called for executing the target service.

[0094] S430, for each thread acquired, calling the function service corresponding to the thread in the thread to execute S440 and S450 in the thread.

[0095] S440, in the case that the tracking identifier is stored in the parent thread, obtaining the tracking identifier from the parent thread, and judging whether the target data corresponding to the tracking identifier is cached in the cache area, wherein the target data is obtained by making a data request to a target object, and the target object is an object that needs to be requested for executing the function service.

[0096] S450, in the case that the target data is cached in the cache area, obtaining the target data from the cache area, and returning the target data to the thread.

[0097] S460, in the parent thread, obtaining the calling result of the target service according to the target data received by each thread respectively, and returning the calling result to the caller of the target service.

[0098] The technical scheme of the embodiment of the application can generate traceId when data caching is needed by detecting the first cache marker, thereby ensuring the effectiveness of the generation action; and by setting the first cache marker, the target service that needs to perform data caching can be flexibly controlled, i.e., the business scenario that needs to perform data caching can be flexibly controlled, rather than performing data caching in any business scenario, and the flexibility is better.

[0099] An optional technical scheme, the service calling method further comprises:

[0100] In the case that the tracking identifier is not stored in the parent thread, making a data request to the target object, and returning the target data returned by the target object to the thread.

[0101] In the case that traceId is not stored in the parent thread, it indicates that data caching is not needed in the target service calling process, and after making a data request to the target object and receiving the target data returned, the target data can be directly returned without being cached in the cache area, thereby avoiding invalid occupation of the cache space.

[0102] In order to better understand the above-mentioned various technical schemes as a whole, they will be exemplarily described below in combination with specific examples. Exemplarily, the above examples are continued to be referred to, and the target service is a query service order details service, the target service (i.e., the domain service) is a query service order service, a query service order log service and a query pick-up order service, the target object is a query order method, a query service order method and a query service order log method, the first cache marker is represented by an EnableOmniCache annotation, and the second cache marker is represented by an OmniCache annotation, for example, and the specific content can be referred to in Figures 5-8.

[0103] Referring to Figure 5 , the query service order details service which needs to be cached is annotated with EnableOmniCache, and the query order method and the query service order method which need to be cached are annotated with OmniCache, so that the cached method is not requested repeatedly under the same request parameters in the life cycle of the query service order details service (i.e. one call request), the request time is reduced, and the business scenarios which need to be cached can be flexibly controlled.

[0104] On this basis, further, when the query service order details service is called by the calling party, since the query service order details service has been annotated with EnableOmniCache, the EnableOmniCache interceptor can be started, i.e. each step in Figure 6 is executed. In the execution process, if the query order method or the query service order method needs to be requested, since the requested method has been annotated with OmniCache, the OmniCache interceptor can be started, i.e. each step in Figure 7 is executed. Thus, after the calling result of the query service order details service is obtained, the calling result is returned to the calling party.

[0105] In the case of starting the EnableOmniCache interceptor, as shown in Figure 6 , 1) a unique traceId is generated for the calling request in the parent thread, and the traceId is put into the TTL. 2) the query service order details service is executed, and the specific execution process can be referred to in Figure 8 . After the execution of the query service order details service is completed, 3) the cached target data in the cache area is cleared. 4) the TTL is cleared.

[0106] For the execution process of the query service order details service, refer to Figure 8 . The thread pool is opened in the parent thread, and 3 sub-threads are obtained from the thread pool, and then the sub-threads are respectively allocated to the query service order service, the query service order log service and the query pick-up order service, and 3 Flow which are executed in parallel are obtained. It should be noted that in Figure 8In the middle, the query service order service is split into five modules, namely, query service order, query commodity, query order, query message, and query reason, and each module is executed in parallel. Further, for the execution of the five modules, RPC requests are respectively made for the query service order method and the query order method; for the execution of the query service order log service, an RPC request is made for the query service order log method; and for the execution of the query service order service, an RPC request is made for the query service order method. After the execution of each domain service and the return of the corresponding target data to the sub-thread, the parent thread performs model conversion according to the target data received by each sub-thread, and returns the calling result in combination with the RPC request for the query order method.

[0107] For the target method (such as the query order method or the query service order method) that has been marked with the OmniCache annotation, when the target method is requested, the steps in Figure 7 may be executed. Specifically, as shown in Figure 7 , it is determined whether there is a traceId corresponding to the current calling request in the TTL. If not, it indicates that the target service requested by the calling request does not need to be cached, and the target method is directly executed and the target data obtained after the execution is returned. If there is, the following steps are executed.

[0108] By traceId+request parameters applied when requesting the target method, it is determined whether there is corresponding target data cached in the cache area. If there is, it indicates that the target method has been requested in the response process of the current calling request, and the target data can be directly obtained from the cache area and returned without repeated requests. If not, the target method is executed, and the target data obtained after the execution is cached in the cache area to avoid subsequent repeated requests, and then the target data is returned.

[0109] In practical applications, the above implementation process can be packaged as a component, that is, a service-level cache component for the query service order detail service. On this basis, according to the analysis above, the service-level cache component is a component that acts in the life cycle of the query service order detail service (i.e., has real-time requirements for data), can use cached data across threads, and can flexibly control whether to enable caching according to the business scenario.

[0110] Figure 9 A structural block diagram of a service calling device provided in the embodiments of the present application is shown in FIG. 12. The device is used to execute the service calling method provided in any of the embodiments. The device and the service calling method of each embodiment belong to the same inventive concept. Details not described in the embodiments of the service calling device can be referred to the embodiments of the service calling method. See Figure 9The apparatus can specifically include: a thread obtaining module 510, a target data first returning module 520, and a calling result returning module 530.

[0111] The thread obtaining module 510 is configured to, in response to the calling request, open a thread pool for the target service requested to call, and obtain at least two threads from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function service is a service that needs to be called for executing the target service.

[0112] The target data first returning module 520 is configured to, for each thread obtained, call the function service corresponding to the thread in the thread, so as to obtain the target data from the cache area in a case where the target data is cached in the cache area, and return the target data to the thread, wherein the target data is obtained by making a data request to a target object, and the target object is an object that needs to be requested for executing the function service.

[0113] The calling result returning module 530 is configured to obtain a calling result of the target service according to the target data received by each thread respectively, and return the calling result to a caller of the target service.

[0114] Optionally, the service calling apparatus further includes:

[0115] The target data second returning module is configured to, after calling the function service corresponding to the thread in the thread, make a data request to the target object in a case where the target data is not cached in the cache area, cache the target data returned by the target object to the cache area, and return the thread.

[0116] Optionally, the target data first returning module 520 includes:

[0117] The target data obtaining unit is configured to, in a case where the target data requested in the response process of the calling request is cached in the cache area, obtain the target data from the cache area.

[0118] On this basis, optionally, for a parent thread of the thread, the service calling apparatus further includes:

[0119] The tracking identifier storage module is configured to, after responding to the calling request, generate a tracking identifier for the calling request in the parent thread, and store the tracking identifier in the parent thread.

[0120] The target data judging module is configured to, after calling the function service corresponding to the thread in the thread, obtain the tracking identifier from the parent thread in a case where the tracking identifier is stored in the parent thread, and judge whether the target data corresponding to the tracking identifier is cached in the cache area.

[0121] On this basis, optionally, the tracking identifier storage module includes:

[0122] The tracking identifier storage unit is configured to generate a tracking identifier for the invocation request in the parent thread and store the tracking identifier in the parent thread when the first cache mark for the target service is detected.

[0123] On this basis, the service invocation device can further include:

[0124] The target data third return module is configured to make a data request for the target object in the parent thread when the tracking identifier is not stored in the parent thread, and return the target data returned by the target object to the thread.

[0125] Alternatively, the service invocation device can further include:

[0126] The tracking identifier judgment module is configured to judge whether the tracking identifier is stored in the parent thread when the second cache mark for the target object is detected.

[0127] Alternatively, the target data judgment module can include:

[0128] The target data judgment unit is configured to obtain the request parameter applied when the target object is requested to execute the function service, and judge whether the target data corresponding to the tracking identifier and the request parameter is cached in the cache area.

[0129] Alternatively, the service invocation device can further include:

[0130] The tracking identifier clearing module is configured to clear the tracking identifier stored in the parent thread after the invocation result is returned to the invoker of the target service; and / or,

[0131] The target data clearing module is configured to clear the target data cached in the cache area after the invocation result is returned to the invoker of the target service.

[0132] On the basis of any of the above service invocation devices, the function service can be a domain service obtained based on a business process as a service technology.

[0133] The service calling device provided by the embodiment of the present application can obtain at least two threads from a thread pool in response to a calling request, so that the at least two threads can be used to call each function service corresponding to the target service in parallel, and the target service calling is completed; the target data first returning module is used to call the corresponding function service in each thread, and the target data is obtained from the cache area and returned to the thread when the target data requested from the target object corresponding to the function service is cached in the cache area, so that the repeated request for the target object is avoided; the calling result returning module is used to obtain the calling result of the target service according to the target data received by each thread, and then the calling result is returned to the calling party of the target service. In the application scenario of calling multiple flows in parallel (i.e., running multiple threads in parallel, and calling the corresponding function service in each thread), the target data requested for executing the function service is cached in the cache area accessible by each thread, so that the repeated request for the target object is avoided, the unnecessary time consumption caused by the repeated request is reduced, and the service calling performance is improved.

[0134] The service calling device provided by the embodiment of the present application can execute the service calling method provided by any embodiment of the present application, and has the corresponding function modules and beneficial effects of the execution method.

[0135] It should be noted that in the embodiments of the service calling device, each unit and module included is only divided according to the function logic, but is not limited to the above division, as long as the corresponding function can be realized; in addition, the specific names of each functional unit are only for the convenience of mutual differentiation, and do not limit the protection scope of the present application.

[0136] Figure 10 A structural schematic diagram of an electronic device 10 that can be used to implement embodiments of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, tablets, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular telephones, smart phones, wearable devices (such as headsets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not intended to limit the implementations of the present application described and / or claimed in this document.

[0137] As Figure 10As shown, the electronic device 10 includes at least one processor 11, and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., communicatively connected to the at least one processor 11, where the memory stores a computer program executable by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or loaded into the random access memory (RAM) 13 from the storage unit 18. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0138] Various components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc., an output unit 17, such as various types of displays, a speaker, etc., a storage unit 18, such as a magnetic disk, an optical disk, etc., and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.

[0139] The processor 11 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs various methods and processes described above, such as the service invocation method.

[0140] In some embodiments, the service invocation method can be implemented as a computer program tangibly embodied in a computer readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded onto the RAM 13 and executed by the processor 11, one or more steps of the service invocation method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the service invocation method by any other appropriate means, such as by means of firmware.

[0141] The various embodiments of the systems and techniques described above can be implemented in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a load programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0142] Computer programs used to implement the processes of the application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer program

[0143] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store computer programs for use by or in connection with an instruction execution system, apparatus, or device. Computer-readable storage media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium will include one or more lines of a program of instructions in a transitory signal, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0144] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.

[0145] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0146] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. A server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system, to solve the defects of large management difficulty and weak business scalability in traditional physical host and VPS service.

[0147] It should be understood that the various forms of flow shown above can be re-ordered, added to, or deleted from without departing from the scope of the present disclosure. For example, the steps recited in the present disclosure can be executed in parallel, executed in sequence, or executed in a different order, as long as the desired results of the present disclosure are achieved, and the present disclosure is not limited herein.

[0148] The specific embodiments described above are not intended to be limiting, and persons skilled in the art will appreciate that various modifications, combinations, sub-combinations and alternatives can be made to the specific embodiments without departing from the spirit and principles of the disclosure. Accordingly, the disclosure is not limited to the specific embodiments described above, but only by the scope of the appended claims.

Claims

1. A service invocation method, characterized by, The method comprises: in response to a calling request, a thread pool is opened for a target service requested by the calling request to obtain at least two threads from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function services are services that need to be called for executing the target service; for each thread obtained, the function service corresponding to the thread is called in the thread to obtain target data from a cache area in a case where the target data is cached in the cache area, and the target data is returned to the thread, wherein the target data is obtained by making a data request to a target object, and the target object is an object that needs to be requested for executing the function service; according to the target data respectively received by each thread, a calling result of the target service is obtained, and the calling result is returned to a caller of the target service.

2. The method of claim 1, wherein, After the function service corresponding to the thread is called in the thread, the method further comprises: in a case where the target data is not cached in the cache area, making a data request to the target object, and caching the target data returned by the target object in the cache area and returning the target data to the thread.

3. The method of claim 1, wherein, The target data is obtained from the cache area in a case where the target data is cached in the cache area, comprising: in a case where target data requested in a response process of the calling request is cached in the cache area, the target data is obtained from the cache area.

4. The method of claim 3, wherein, For a parent thread of the thread, after the calling request is responded to, the method further comprises: generating a tracking identifier for the calling request in the parent thread, and storing the tracking identifier in the parent thread; after the function service corresponding to the thread is called in the thread, the method further comprises: in a case where the tracking identifier is stored in the parent thread, obtaining the tracking identifier from the parent thread, and determining whether target data corresponding to the tracking identifier is cached in the cache area.

5. The method of claim 4, wherein, The tracking identifier for the calling request is generated in the parent thread, and the tracking identifier is stored in the parent thread, comprising: in a case where a first cache mark for the target service is detected, the tracking identifier for the calling request is generated in the parent thread, and the tracking identifier is stored in the parent thread.

6. The method of claim 5, wherein, Further comprising: in a case where the tracking identifier is not stored in the parent thread, making a data request to the target object, and returning the target data returned by the target object to the thread.

7. The method of claim 4, wherein, Further comprising: in a case where a second cache mark for the target object is detected, it is determined whether the tracking identifier is stored in the parent thread.

8. The method of claim 4, wherein, The determination of whether the target data corresponding to the tracking identifier is cached in the cache area comprises: obtaining a request parameter applied when the target object is requested for executing the function service, and determining whether target data corresponding to the tracking identifier and the request parameter is cached in the cache area.

9. The method of claim 4, wherein, After the calling result is returned to the caller of the target service, the method further comprises: clearing the tracking identifier stored in the parent thread; and / or clearing the target data cached in the cache area.

10. The method according to any one of claims 1-9, characterized in that, The function service is a domain service obtained based on a business process as a service technology.

11. A service invocation apparatus characterized by comprising: The method comprises the steps of: a thread obtaining module, configured to, in response to a calling request, open a thread pool for a target service requested to be called, and obtain at least two threads from the thread pool, wherein the at least two threads are used to call different function services in parallel, and the function service is a service required to be called for executing the target service; a target data first returning module, configured to, for each thread obtained, call a function service corresponding to the thread in the thread, and obtain target data from a cache area in a case that the cache area has the target data, and return the target data to the thread, wherein the target data is obtained by making a data request to a target object, and the target object is an object required to be requested for executing the function service; a calling result returning module, configured to obtain a calling result of the target service according to target data respectively received by the each thread, and return the calling result to a caller of the target service.

12. An electronic device, comprising: The method comprises the steps of: at least one processor; and a memory connected in communication with the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the service calling method according to any one of claims 1-10.

13. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions, and the computer instructions are used to enable the processor to execute the service calling method according to any one of claims 1-10.

14. A computer program product, characterised in that, The computer program product comprises a computer program, and the computer program is used to enable the processor to execute the service calling method according to any one of claims 1-10.