Replies: 8 comments 22 replies
-
Here's one way to do it. A lot of the PS member functions don't need to be write-locked. Like this one, which we use a lot:
My fuzzy and humble proposal is to reduce the scope of LockedPlanningSceneRW so it doesn't affect these const member functions. Possibly this could be done by moving the non-const member functions to a struct inside PlanningScene and only locking that struct. Does that make sense or am I crazy? |
Beta Was this translation helpful? Give feedback.
-
I think you're right with the observation that this class needs to be refactored. Is it really safe to assume that we don't need to lock all const member functions? My guess would be that during the time a function writes to data structure we need to lock it for reading as well because during the writing process this data structure is in an undefined state. Maybe it would be possible to R/W lock only the part of the planning scene that is currently written to. |
Beta Was this translation helpful? Give feedback.
-
It is unsafe to read data that another thread might be writing to. This is a classic case of a data race and can lead to hard-to-track-down bugs. When dealing with shared data, these two rules help you avoid data races:
We need to have one view of the world that is constantly updated and also used for potentially time-consuming computations like collision checking on multiple threads. The current approach of read-and-write locks has these downsides:
To address these issues, I think the right approach is to find ways to make copying less expensive (because copies of the data can be used on multiple threads simultaneously with no synchronization). To do this, we should investigate persistent data structures that are cheap to update and copy. But before we do that, we should determine what the normal access patterns are and where the performance bottlenecks are and take that information into account when designing changes to the planning scene. |
Beta Was this translation helpful? Give feedback.
-
To comment on the original issue of cleaning up the API, though. I think this can be done separately from changing the underlying data storage by separating functions that operate on a planning scene and the storage and locking of the planning scene. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
I think eliminating mutable returns would be helpful, like this:
We don't know what the user is going to do with the ACM they've retrieved, so the whole PS gets locked. If there were no mutable returns, locking might be a lot more sane. |
Beta Was this translation helpful? Give feedback.
-
Changing API w/o understanding the underlying problem doesn't seem to be very promising to me. |
Beta Was this translation helpful? Give feedback.
-
The data contained inside an std::map<std::string, std::map<std::string, AllowedCollision::Type> > entries_;
std::map<std::string, std::map<std::string, DecideContactFn> > allowed_contacts_;
std::map<std::string, AllowedCollision::Type> default_entries_;
std::map<std::string, DecideContactFn> default_allowed_contacts_; Has it been shown that copying this data is expensive and justifies synchronization primitives (lock mutexes) to be handled by the various threads accessing the PSM? The original complaint is about how the interface for the planning scene is complex due to these mutexes. I do not think it is fair to assume that mutexes are less computationally expensive than copying data structures. There are optimizations we could make to how this data is stored to make copying cheaper (make the data persistent and calculate diffs). Still, I would not be surprised if the normal size of this object is small enough that copying it is considerably less expensive than locking a mutex while interacting with it. If we must maintain the mutex we should change the interface for updating to something like this: void update(std::function<void(collision_detection::AllowedCollisionMatrix& acm)> fn); That way, the user writes a lambda or passes a function that changes the acm instead of handling the mutex themselves. |
Beta Was this translation helpful? Give feedback.
-
Saw this in the Tesseract readme. It's related.
|
Beta Was this translation helpful? Give feedback.
-
There are about 200 public member functions in the planning scene!
Currently we lock the entire PS for reading or writing. It's all-or-nothing. We can have any number of read-locks but only one write-lock at a time. Write-locks are bad.
We've encountered some limits with planning scene locking when trying to use it with a realtime control loop at ~250 Hz. How can we make PS locking more efficient?
Beta Was this translation helpful? Give feedback.
All reactions