-
Notifications
You must be signed in to change notification settings - Fork 110
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
RSDK-8663: Optimize away gostream concurrency complexity for camera clients. #4363
Conversation
@dgottlieb looks like CI is failing FYI |
Thanks -- did you otherwise review this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we pinpoint the reason why two GetImage calls are sometimes made? Is it possible to prevent that instead
test.That(t, err, test.ShouldBeNil) | ||
|
||
if _, isReadImager := cameraClient.(camera.ReadImager); isReadImager { | ||
// Success |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious syntax
Wondering why you prefer this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How this code got this way is a bit of a long story -- it wasn't due to preference. I was trying to use the "test.ShouldImplement" assertion, that I think requires reflection and additional error handling. But ultimately failed at that. So the structure of this if-statement was already there and I just had to use a type-assertion instead and do nothing in the "then" clause.
That said, I do think writing conditionals in the affirmative (i.e: avoid double negatives) reads better. And in this case, a real writer is going to write the if-statement that way -- just with a non-empty "then".
But normally I wouldn't take that to the "extreme" of having an empty "then" clause. I just left it this way because I was fed up with writing an assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha the test lib use of reflection can be super funky
Got it
@@ -118,6 +118,8 @@ func getExtra(ctx context.Context) (*structpb.Struct, error) { | |||
return ext, nil | |||
} | |||
|
|||
// RSDK-8663: This method signature is depended on by the `camera.serviceServer` optimization that | |||
// avoids using an image stream just to get a single image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see since the client Read
func is guaranteed to only call GetImage once in its body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! That's exactly how this patch works. Instead of spinning up:
- stream = camera.Stream()
- stream.Next()
- stream.Close
We first ask "Hey camera, do you have a "Read" method?" Great -- we'll just call that one time and avoid this stream non-sense.
Yes. The ticket/comments try to explain what happens. But it is hard to follow how that relates to the exact code because of the gostream layers involved.
Given this patch does prevent that with camera clients, I assume you mean in the more general case? Yes and no. Right now, the API exposed by all underlying gostream cameras are:
Beyond those two, cameras may not have any* other methods[1]. So for those that do, we can try and guess/use them. But even for the Point being, avoiding "double get image" from a bigger set of cameras requires more typing across the codebase. And the camera client was 90% of our problem today. [1] As far as I can tell -- it's not correct to blindly use
|
Thanks for that info From the writeup on the ticket:
I guess my question was more pointed towards this. There isn't a clear path forward preventing the double call originating from this background thread is there? |
I explored an avenue where ReadImage/ReadMedia would do:
Which I think is what you're asking? Where we can "atomically" get a single image and communicate to the "producer" to not (eagerly) produce the next image. I didn't find that to be possible without significantly mucking with the producerConsumer code. Which would then require a much more thorough proof of correctness/review. |
Makes sense. That sounds very involved |
No description provided.