Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize eventbus process when queue is full #391

Closed
leizhiyuan opened this issue Dec 5, 2018 · 0 comments
Closed

optimize eventbus process when queue is full #391

leizhiyuan opened this issue Dec 5, 2018 · 0 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@leizhiyuan
Copy link
Contributor

Your question

com.alipay.sofa.rpc.event.EventBus#post

/**
     * 给事件总线中丢一个事件
     *
     * @param event 事件
     */
    public static void post(final Event event) {
        if (!isEnable()) {
            return;
        }
        CopyOnWriteArraySet<Subscriber> subscribers = SUBSCRIBER_MAP.get(event.getClass());
        if (CommonUtils.isNotEmpty(subscribers)) {
            for (final Subscriber subscriber : subscribers) {
                if (subscriber.isSync()) {
                    handleEvent(subscriber, event);
                } else { // 异步
                    final RpcInternalContext context = RpcInternalContext.peekContext();
                    AsyncRuntime.getAsyncThreadPool().execute(
                        new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    RpcInternalContext.setContext(context);
                                    handleEvent(subscriber, event);
                                } catch (Exception e) {
                                    RpcInternalContext.removeContext();
                                }
                            }
                        });
                }
            }
        }
    }

if AsyncRuntime.getAsyncThreadPool().execute throw an exception because of queue is full, the current thread will break

Your scenes

maybe we need to catch this exception . subscriber which is async need to accept the lost of event.

Your advice

describe the advice or solution you'd like

Environment

  • SOFARPC version:
  • JVM version (e.g. java -version):
  • OS version (e.g. uname -a):
  • Maven version:
  • IDE version:
@leizhiyuan leizhiyuan self-assigned this Dec 5, 2018
@leizhiyuan leizhiyuan added this to the 5.5.0 milestone Dec 5, 2018
@leizhiyuan leizhiyuan added enhancement New feature or request good first issue Good for newcomers labels Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant