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

server: always handle streaming RPCs in separate goroutines to optimize serverWorker availability #7558

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@
s.handleStream(st, stream)
}

if s.opts.numServerWorkers > 0 {
if s.opts.numServerWorkers > 0 && s.isUnaryRPCMethod(stream.Method()) {
select {
case s.serverWorkerChannel <- f:
return
Expand Down Expand Up @@ -2205,3 +2205,22 @@
a.n.Store(int64(n))
return a
}

// isUnaryRPCMethod returns true if the passed in method corresponds to a registered
// unary RPC method on the server.
func (s *Server) isUnaryRPCMethod(serviceMethod string) bool {
serviceMethod = strings.TrimPrefix(serviceMethod, "/")
pos := strings.LastIndex(serviceMethod, "/")
if pos == -1 {
return false

Check warning on line 2215 in server.go

View check run for this annotation

Codecov / codecov/patch

server.go#L2215

Added line #L2215 was not covered by tests
}
service := serviceMethod[:pos]
method := serviceMethod[pos+1:]
srv, knownService := s.services[service]
if knownService {
if _, ok := srv.methods[method]; ok {
return true
}
}
return false

Check warning on line 2225 in server.go

View check run for this annotation

Codecov / codecov/patch

server.go#L2225

Added line #L2225 was not covered by tests
}
Loading