[Open Source] A Powerful, Flexible Configuration, High-Performance Asynchronous Arrangement Framework (Multi-Thread Management)

Open SourceProcess Management
2026-06-28 03:02 1 次浏览 • 0 次下载 0KB
[Open Source] A Powerful, Flexible Configuration, High-Performance Asynchronous Arrangement Framework (Multi-Thread Management)

1. Project Overview

What is this framework

Gobrs-Async is a powerful, highly configurable, full-link exception callback, memory optimization, and exception state management framework with high performance asynchronous orchestration. It provides enterprises with the ability to dynamically orchestrate tasks in complex application scenarios. For complex scenarios, asynchronous thread complexity, task dependency, and exception state difficulty in control;Gobrs-Async was born for this

2. Open Source License

Licensed under Apache-2.0

3. Screenshots

Why write this project

In the process of developing complex enterprise business, it is inevitable to encounter the call of various enterprise business data, and complex enterprise data dependency relationships will appear, which will increase the complexity of the code. As shown in the figure below:

In e-commerce platform business, various enterprise data may depend on Product data and need to depend on special attributes of Item data. (Some friends will ask, why Product data is not from the same enterprise as Item data? Enterprise business development is diverse, and different business enterprise design methods are different. Can we not interface with each other? So we need to provide technical support for such complex and variable enterprise business data, which is what a qualified developer should do.) Moreover, Item data is an HTTP service, but Product is an RPC service. If we develop it according to the Future development method, we may develop it like this

    // Parallel processing tasks Product 、 Item's tasks
    @Resource
    List<ParaExector> paraExectors;

    // Tasks dependent on Product and Item
    @Resource
    List<SerExector> serExectors;

    public void testFuture(HttpServletRequest httpServletRequest) {
        DataContext dataContext = new DataContext();
        dataContext.setHttpServletRequest(httpServletRequest);
        List<Future> list = new ArrayList<>();
        for (AsyncTask asyncTask : paraExectors) {
            Future<?> submit = gobrsThreadPoolExecutor.submit(() -> {
                asyncTask.com.gobrs.async.com.gobrs.async.test.task(dataContext, null);
            });
            list.add(submit);
        }
        for (Future future : list) {
            try {
                future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }

        List<Future> ser = new ArrayList<>();
        for (AsyncTask asyncTask : serExectors) {
            Future<?> submit = gobrsThreadPoolExecutor.submit(() -> {
                asyncTask.com.gobrs.async.com.gobrs.async.test.task(dataContext, null);
            });
            ser.add(submit);
        }
        for (Future future : ser) {
            try {
                future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }

Existing Issues

The example above shows that Product data is obtained through RPC, and Item data is obtained through HTTP services. Everyone knows that RPC performance is higher than HTTP performance. However, using the Future method, get will block and wait for Item data to return before executing further. In this way, data such as book and video, decoration, and purchase limits will wait for Item data to return, but these middle platforms do not rely on Item return data, so it will produce waiting time and affect the overall QPS of the system.

Origin

  • The author summarizes the experience and usage of open-source middleware source code and secondary development experience.
  • User experience and usage, including business requirements

Gobrs-Async core capabilities

4. Feature Overview

What can be solved

What cannot be solved.CompletableFutureHow to understand it?

TraditionalFuture、CompleteableFutureCan complete task scheduling to a certain extent and can pass the result to the next task. For example, CompletableFuture has a then method, but it cannot do callback for each execution unit. For example, A is executed successfully, and B is executed afterwards. I hope A has a callback result after execution, which can help me monitor the current execution status or log something. If it fails, I can also record an exception message.

At this point, CompleteableFuture is powerless.

Gobrs-AsyncThe framework provides such a callback function. And if it is successful, failed, abnormal, or timed out in various scenarios, it provides the ability to manage thread tasks!

Scene Overview

Scene One

Description  After task A is executed, continue to execute B, C, D

Scene Two

Description  After task A is executed, execute B and then execute C, D

Scene Three

Description  After task A is executed, execute B, E and then follow the process of B to execute C, D, G. E's process executes F, G

There are more scenarios, if you want to understand the task arrangement concept in detail, please read the document carefully, or navigate to the official website through the resource index to understand the overall situation!

Industry Comparison

After searching for many task asynchronous arrangement frameworks on open-source platforms, it was found that none of them were very ideal. The only asynchronous arrangement framework that is currently quite useful is asyncTool. However, when using it, it was found that the API was not very useful. Moreover, frequent creation of WorkerWrapper objects was a bit uncomfortable to use. For business scenarios that are more complex, in the development process, it is necessary to write more WorkerWrapper code, and the framework cannot intercept global exceptions. It can only be caught by the result method of each task. It cannot stop all global asynchronous tasks when any task appears an exception. At the same time, it cannot intercept exceptions when a global exception occurs. If you need to implement the function of sending alarm emails when stopping global tasks flow, asyncTool is powerless.

asyncTool itself has very powerful functions, and the author of asyncTool and I are both working in JD as R&D personnel. The scenarios involved are similar. There will be many business scenarios with complex middle platform interface call relationships. Therefore, for the current business scenario, it is necessary to explore more technical fields. Technology should serve business and land in business scenarios.

I want to give the project a simple and memorable name, similar to Eureka, Nacos, Redis. After repeated consideration, I decided to name it:Gobrs-Async

Function

asyncTool

Gobrs-Async

sirector

Multi-Task Processing

Yes

Yes

Yes

Single-Task Exception Callback

Yes

Yes

No

Global Exception Interruption

No

Yes

No

Configurable Task Flow

No

Yes

No

Custom Exception Interceptor

No

Yes

No

Memory Optimization

No

Yes

No

Optional Task Execution

No

Yes

No

It solves what problems

When calling various middle platforms, it is inevitable to encounter multiple middle platforms that are mutually dependent. In real development, the following scenarios will be encountered.

Common parallel scenarios 1 Client requests the server interface, and the interface needs to call the interfaces of N other microservices

For example, when requesting my shopping cart, it needs to call the user's RPC, product details' RPC, inventory RPC, and coupon RPC, etc. At the same time, these services have mutual dependency relationships, such as must first get the product ID before requesting the inventory RPC service to get the inventory information. Finally, after getting all the results, or exceeding the timeout, the results are summarized and returned to the client.

2 Parallel execution of N tasks, and the subsequent execution of the next task is determined by the execution results of 1-N tasks

For example, users can log in through email, phone number, or username, and the login interface is only one. When the user initiates a login request, we need to parallelly query the database according to email, phone number, and username at the same time. As long as one of them is successful, it is considered successful, and the next step can be executed. Instead of first trying to see if the email is successful, then trying the phone number……

For example, some interfaces limit the number of parameters that can be passed in each batch, and each query can only retrieve information about up to 10 products. If I have 45 products to query, I can divide them into 5 groups and query them in parallel, and then aggregate the results of these 5 groups. It depends on whether you require all queries to be successful or not, or whether you can return the results to the client regardless of how many groups are successful.

For example, there is an interface that requires 5 pre-task processing. Among them, 3 are mandatory and must be executed before the next step, while the other 2 are non-mandatory and can be executed only after the 3 mandatory tasks are completed. If the other 2 tasks are completed successfully, their results will be used; otherwise, default values will be used.

3. Tasks that require thread isolation.

Like multiple groups of tasks, each group is independent and unrelated to the other groups. Each group requires an independent thread pool, and each group is an independent execution unit.

4. Single-machine workflow task scheduling.

5. Other tasks that require sequential scheduling.

What are its features?

Gobrs-Async considers the development habits of many users during development and applies it to e-commerce production environments, such as JD.com, which has undergone rigorous high-concurrency testing. The framework also features simplified and flexible configuration, global customizable interruptible exception handling, memory optimization, flexible access methods, and SpringBoot Start access methods. It also considers the development habits of users, and only needs to inject the GobrsTask Spring Bean to achieve full-process access.

Gobrs-Async project directory and simplified version:

  • gobrs-async-example: Gobrs-Async access instance, providing test cases.
  • gobrs-async-starter: Gobrs-Async framework core components.

Gobrs-Async was designed with the development habits of users in mind, without relying on any middleware. It has also done a good job of encapsulating concurrent frameworks. The main development and design useCountDownLatch 、ReentrantLock 、volatile and other series of concurrent technologies.

5. Tech Stack

Overall architecture


Task Triggerer

Task Flow Starter, responsible for starting task execution flow

Rule Parsing Engine

Responsible for parsing user-configured rules, while combining with Spring, and parsing the configured Spring Bean  into TaskBean, and then loading the task decorator through the parsing engine, and then assembling it into a task tree

Task Starter

Responsible for starting tasks through the task tree parsed by the parsing engine, combined with JUC  and concurrent framework scheduling to implement unified management of tasks, core methods include

  • Trigger Task Loader, preparing the environment for loading tasks

Task Loader

Responsible for loading task flow, starting to call task executor to execute core process

  • load core task process method, blocking and waiting for the entire task process
  • getBeginProcess, getting the start process of subtasks
  • completed Task Completed
  • error Interrupted Task Task Flow Interrupted
  • error Task Failed

Task Executor

Final Task Execution, Each Task Corresponds to OneTaskActuator  Task Interception, Exception, Execution, Thread Reuse, etc. Necessary Conditions Judgment Are All Handled Here

  • prepare Task Preprocessing
  • preInterceptor Unified Task Preprocessing
  • task Core Task Method, Business Execution Content
  • postInterceptor Unified Postprocessing
  • onSuccess Task Execution Successful Callback
  • onFail Task Execution Failed Callback

Task Bus

Task Flow Transmission Bus, Including Request Parameters, Task Loaders, Response Results, This Object Exposes to Users, Gets Matching Business Data Information, Such as: Return Results, Proactive Task Flow Interruption, etc. Functions Need Task Bus (TaskSupport) Support

Core Class Diagram

#1
资源直链https://github.com/dromara/gobrs-async/archive/refs/heads/master-v2.zip
去下载
星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare