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

brpcServer 异步处理 #2446

Open
yming000 opened this issue Nov 14, 2023 · 6 comments
Open

brpcServer 异步处理 #2446

yming000 opened this issue Nov 14, 2023 · 6 comments

Comments

@yming000
Copy link

用echo.proto中的Echo举例,我的需求是,在Echo()运行完后,server能够直接运行一个业务函数,求各位大佬多多指教

@leaf-potato
Copy link
Contributor

看下这个#2328 满足需求吗

@thorneliu
Copy link
Contributor

那么是在Echo 处理函数中回复了Echo response,同时启动一个线程来运行你的业务函数就行了吧

@yming000
Copy link
Author

那么是在Echo 处理函数中回复了Echo response,同时启动一个线程来运行你的业务函数就行了吧

想了解brpc有没有预留这样的借口,自己起线程,感觉在程序退出时,可能会有资源访问core问题

@yming000
Copy link
Author

看下这个#2328 满足需求吗

谢谢 我学习一下

@leaf-potato
Copy link
Contributor

那么是在Echo 处理函数中回复了Echo response,同时启动一个线程来运行你的业务函数就行了吧

想了解brpc有没有预留这样的借口,自己起线程,感觉在程序退出时,可能会有资源访问core问题

运行done->Run()后request和response都会被析构,如果在单独业务线程中会访问req和resp会有问题

@thorneliu
Copy link
Contributor

thorneliu commented Nov 27, 2023

那么是在Echo 处理函数中回复了Echo response,同时启动一个线程来运行你的业务函数就行了吧

想了解brpc有没有预留这样的借口,自己起线程,感觉在程序退出时,可能会有资源访问core问题

运行done->Run()后request和response都会被析构,如果在单独业务线程中会访问req和resp会有问题

Hi,如果是这样,你应该拓展done的生命周期,类似这样:

void ChatServiceImpl::Syn(google::protobuf::RpcController *cntl_base,
                          const HttpRequest *, HttpResponse *,
                          google::protobuf::Closure *done) {

  brpc::ClosureGuard done_guard(done);
  brpc::Controller *cntl = static_cast<brpc::Controller *>(cntl_base);

  auto job = std::make_shared<Asyncjob>();
  ...
  job->cntl = cntl;
  job->done = done_guard.release();

  infer_job_scheduler_->noNewJob(job);
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants