Prevent grpc service method to be called by multiple clients at the same time
See original GitHub issueI have a @GRpcService annotated class which overrides my service rpc methods. Is there a configuration that I can made in order to prevent concurrent access on that method?
My code look something like this:
@GRpcService
public class MyClass extends MyServiceImplBase {
@Override
@Transactional
public void myServiceMethod(request, responseObserver) {
// run a select query that retrieves a row from db
// set retrieved to true in database for the retrieved row
// save updated row to database
}
}
The problem is that If I have 2 grpc clients calling this method at the same time the method will return the same row.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Multiple clients connected to a single server gRPC-java
The gRPC server is multithreaded and will simultaneously accept connections from multiple clients. You can quickly try this out with the hello ...
Read more >Performance best practices with gRPC | Microsoft Learn
Highly concurrent apps generally perform better with server GC. If a gRPC client app is sending and receiving a high number of gRPC...
Read more >When having multiple clients with their own stream request ...
I have a code where there are multiple threads , executing the same rpc method ( server streaming) , within which a new...
Read more >Performance Best Practices - gRPC
A user guide of both general and language-specific best practices to improve performance.
Read more >Consuming a gRPC Service - Quarkus
The service name, method and type can be found in the tags. Disabling metrics collection. To disable the gRPC client metrics when quarkus-micrometer...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can use traditional Java synchronization mechanisms to protect critical sections, including DB transactions, nothing grpc-special. Also I recommend to read this section carefully https://github.com/LogNet/grpc-spring-boot-starter#grpc-response-observer-and-spring-transactional-caveats
What is strange is that before using the lock mechanism If I was calling the GRpcService method concurrently 5 times, 5 out of 5 times I would get the same row returned. After I’ve added the lock mechanism and moved the update row method into it’s own service I’m getting the same row 2 out of 5 times.
My code in order to test this looks something like this: