-
Notifications
You must be signed in to change notification settings - Fork 111
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
[Data-565] Fix for flaky join pointcloud naive test #1505
[Data-565] Fix for flaky join pointcloud naive test #1505
Conversation
0066921
to
1605092
Compare
pointcloud/merging.go
Outdated
// one last read to flush out any potential last data | ||
lastBatches := len(finalPoints) | ||
logger.Debugf("number of last batches: %d", lastBatches) | ||
for i := 0; i < lastBatches; i++ { | ||
lastPoints := <-finalPoints | ||
logger.Debugf("number of points in batch %d: %d", i, len(lastPoints)) | ||
for _, p := range lastPoints { | ||
myErr := pcTo.Set(p.P, p.D) | ||
if myErr != nil { | ||
err = myErr | ||
} | ||
} | ||
} |
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.
This is the fix, essentially
a81421d
to
3679fd6
Compare
|
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'm okay with this fixing the flake but if this code is used a lot, I'd love if we can benchmark it and possibly simplify it greatly.
var pcTo PointCloud | ||
var err error | ||
|
||
dataLastTime := false // if there was data in the channel in the previous loop, continue reading. |
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.
this may be a naive question and can be discussed later, but how fast is this code compared to a simpler version. This feels very complicated.
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 will make a ticket for simplifying this merging function.
var err error | ||
|
||
dataLastTime := false // if there was data in the channel in the previous loop, continue reading. | ||
for dataLastTime || atomic.LoadInt32(&activeReaders) > 0 { |
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.
why is this looping like this versus waiting on a channel and/or waitgroup?
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.
From what i understand, this code generates a thread for each pointcloud source, splits each pointcloud into 8 subset pointclouds and puts each into a seperate thread, and then does the necessary transforms before dumping all the points into a final point cloud.
So there are nCamera*8 threads all feeding into one channel. Then there is this loop, which is reading from that channel into this final point cloud. Is it waiting for all threads to finish pushing data in the channel before it exits the for loop.
for _, p := range ps { | ||
if pcTo == nil { | ||
if p.D == nil { | ||
pcTo = NewAppendOnlyOnlyPointsPointCloud(len(cloudFuncs) * 640 * 800) |
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.
what's the 640*800 for? should it be a const?
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.
To answer your question, this code was written in a rush to fulfill fast pointcloud merging for a demo. 640*800 is the resolution of the cubeEye cameras, so this was a pre-allocation for the number of points generated by the system of cubeEye cameras
The bug was an edge-case when reading the batches of points from a channel into the final point cloud would not read all the points in the channel.
The loop would continue reading data into the final point cloud if
dataLastTime || atomic.LoadInt32(&activeReaders) > 0
If there was no data in the channel, then the loop would wait 5 ms and then would set
dataLastTime = false
.There was a situation where
dataListTime
was false, butatomic.LoadInt32(&activeReaders)
had become 0 only within those 5 ms whendataLastTime
was being set to false, meaning there was still some last minute data in the channel. The solution is to do one last read to make sure all of the data is out of the pipeline.