Comments (5)
This was indeed the problem. Thank you! Keep up the good work with the library!
from asio-grpc.
Hi, thank you for reporting the issue. I have trouble reproducing it. This email conversion in gRPC suggests that you might be doing two asynchronous operations in parallel that are not allowed to be in parallel. E.g. writing and finishing a writer
at the same time.
I do not know what you mean by handle one request at a time
, since you are using agrpc::repeatedly_request
there will be one coroutine for each request from the client. In other words, the following code will co_spawn a coroutine for each client request, all those coroutines will be processed in parallel:
asio::awaitable<void> handle_request(grpc::ServerContext& server_context, auto& request, auto& writer, agrpc::GrpcContext& grpc_context)
{
// This function will be called for each request from the client as soon as the request has been made, even while
// a previous request is still being processed by `handle_request`.
// It is executing on a thread of the system_context.
co_return;
}
void register_handler(asio::system_context& ctx, agrpc::GrpcContext& grpc_context, MarketDataAlert::AsyncService& service)
{
agrpc::repeatedly_request(&MarketDataAlert::AsyncService::Requestsubscribe, service,
asio::bind_executor(grpc_context,
[&]<class T>(agrpc::RepeatedlyRequestContext<T>&& context)
{
asio::co_spawn(
ctx,
[&, context = std::move(context)]()
{
auto&& [server_context, request, responder] = context.args();
return std::invoke(handle_request, server_context, request, responder, grpc_context);
},
asio::detached);
}));
}
from asio-grpc.
Thank you for the very quick response! I'll take a look on the link you have sent. What I meant by "handle one request at a time", is that the first request is processed and receives it's messages but the following requests all receive a unable to connect to server, which I assume is because it is occupied by the first request, which is on the while(request_ok) loop. In other words, i can only have one stream active at a time. It is also happening with the code you provided.
This is the error received/generated by the client application: Message: failed to connect to all addresses subscribe rpc failed.
In other words, the following code will co_spawn a coroutine for each client request, all those coroutines will be processed in parallel
I thought that this would happen too, but apparently is not. I can only start another rpc call when the previous one finishes. Could this be a performance issue? I mean by this is: could my system be too slow to co_spawn and process the new request while the other one is running?
from asio-grpc.
I suspect that something is blocking the GrpcContext. E.g. in your example:
while(request_ok) {
// If `fill_response` performs blocking operations, e.g. holding a lock on a mutex or calling some long
// CPU-intensive task then the entire GrpcContext will be blocked, because `agrpc::write` resumes
// in the thread of the GrpcContext. If that is the case then explicitly switch back to the system_context
// before doing such tasks.
co_await asio::post(asio::bind_executor(ctx, asio::use_awaitable));
co_await fill_response(server_context, request, response, instrumentId);
// do some work
request_ok = co_await agrpc::write(writer, response,
boost::asio::bind_executor(grpc_context, boost::asio::use_awaitable));
}
//after done work
bool finish_ok = co_await agrpc::finish(writer, grpc::Status::OK, boost::asio::bind_executor(grpc_context, boost::asio::use_awaitable));
I have just adjusted one of the unit test to deliberately verify that repeatedly_request can handle multiple requests at the same time which succeeds on all tested platforms/compilers.
from asio-grpc.
Great, I am glad we figured it out and thank you for the kind words.
from asio-grpc.
Related Issues (20)
- GRPC_CALL_ERROR_TOO_MANY_OPERATIONS Error on Concurrent Write Operations HOT 2
- Lifetime issue in the docs HOT 2
- Example with small changes crashes HOT 6
- Why I get const correctness problems HOT 16
- Generic server example without manual buffer serializaiton? HOT 4
- Using asynchronous gRPC server and client on same context HOT 9
- Asio-gRPC seems to have TSAN warnings HOT 8
- How to detect client closed connection HOT 6
- Can I call ServerBuilder::BuildAndStart() after GrpcContext::run() HOT 2
- Questions on how to switch from an GrpcContext to io_context and back HOT 6
- How to shutdown grpc clients HOT 1
- Clarification Needed on Thread Context Switch in writer() Function (example streaming-server.cpp) HOT 8
- assertion failed: !started_ HOT 2
- Can I use asio-grpc inside an existing boost::asio application? HOT 7
- The agrpc::GrpcContext hangs forever HOT 13
- an upgrade from 2.5.1 to 2.9.1 leads to build errors HOT 6
- build fails with latest boost 1.84 HOT 4
- [Question]: Slowly receiveing client in long-lived streaming HOT 1
- InvokeHandler conflicts with Objective-C/C++ defines HOT 1
- Need some basic help! HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asio-grpc.