Skip to content

Conversation

@stefanadranca
Copy link
Collaborator

Motivation:

These are 2 of the RPCs on the worker service that we need for benchmarking.

Modifications:

  • Created the WorkerService struct that has a GRPCClient and a GRPCServer property
  • Implemented the 'coreCount' and 'quitWorker' RPCs

Result:

  • The driver will be able to request 'quitWorker' and 'coreCount' from the workers

Motivation:

These are 2 of the RPCs on the worker service that we need for benchmarking.

Modifications:

- Created the WorkerService struct that has a GRPCClient and a GRPCServer property
- Implemented the 'coreCount' and 'quitWorker' RPCs

Result:

- The driver will be able to request 'quitWorker' and 'coreCount' from the workers
@stefanadranca stefanadranca marked this pull request as ready for review March 19, 2024 10:04
@stefanadranca stefanadranca requested a review from glbrntt March 19, 2024 10:04
Comment on lines 21 to 23
struct WorkerService: Grpc_Testing_WorkerService.ServiceProtocol {
var testClient: GRPCClient? = nil
var testServer: GRPCServer? = nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work when we add other RPCs because we need this type to be Sendable. This means we need to turn the struct into a class and protect this state using a lock. You can wrap the state up in a struct State and then use a NIOLockedValueBox to hold the state (you'll need to import NIOConcurrencyHelpers).

if let testClient = self.testClient {
testClient.close()
} else if let testServer = self.testServer {
testServer.stopListening()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will also need to flip the atomic that we'll set on the benchmark service here.

@stefanadranca stefanadranca requested a review from glbrntt March 19, 2024 13:00
Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two nits, looks good otherwise


@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
final class WorkerService: Grpc_Testing_WorkerService.ServiceProtocol, Sendable {
let state: NIOLockedValueBox<State>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, and the State struct can be private

request: ServerRequest.Single<Grpc_Testing_WorkerService.Method.QuitWorker.Input>
) async throws -> ServerResponse.Single<Grpc_Testing_WorkerService.Method.QuitWorker.Output> {

if let role = self.state.withLockedValue({ $0.role }) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any reason to delay setting the $0.role back to nil, we can just do it in one go:

let role = self.state.withLockedValue { 
  defer { $0.role = nil }
  return $0.role
}

@glbrntt glbrntt added the version/v2 Relates to v2 label Mar 19, 2024
@glbrntt glbrntt merged commit 800fadc into grpc:main Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

version/v2 Relates to v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants