Repository navigation
Conversation
…engths The first publisher on a topic currently determines the publisher queue length for all publishers from that node on that topic. For this reason, the test fails currently.
|
Can one of the admins verify this patch? |
…backs This fixes ros#450 and makes the unit test pass for me. It involves retaining the requested queue_size in the SubscriberCallbacks struct and counting the max_queue_ member of Publication up/down appropriately.
|
The second commit (4c0035d) makes the unit test pass for me. |
|
I am not sure if the sum of all publisher queue length arguments is the final solution for the problem. It definitely make the queue bigger and problems less likely to occur though. But consider the following simple example:
Using a single queue with a length of 11 will not give you the result both publishers would expect. |
What exactly do you expect to happen here? The publishing is done in the The only thing you do with the queue length in my experience is turning it up when the publisher thread can't keep up. You never turn it down to limit the rate, since it can't guarantee that. It's not message frequency, it's more like a "load expectation" for the Perhaps we would have to change the fixed queue length to something like checking the message frequency and dropping messages if the frequency is too high, but that is a big API change. In my opinion quite impossible at this point ;-) |
There was a problem hiding this comment.
Please avoid any non-crucial changes like moving code around.
|
One way or the other: neither the max or sum of queue sizes will make the actual behavior match the publishers expectations. The first publisher "expects" that he can queue messages if the subscriber is several seconds behind. But exactly that is not going to happen when the second publisher is present. Increasing the queue size to the sum of all sizes will make it less likely to be a problem though. As long as we agree that this is only a partial workaround everything is good. |
…backs This fixes ros#450 and makes the unit test pass for me. It involves retaining the requested queue_size in the SubscriberCallbacks struct and counting the max_queue_ member of Publication up/down appropriately.
Yes, that's what I meant in my last comment. The queue size constraint does not mix well with the optimization of placing all messages of a topic in one queue and sending them out together. I still can't think of a better solution if we do not want to get rid of this optimization and keep separate queues (and connections!) for each publisher. But I have removed the claim of doing it 'properly' from the PR title ;-) |
|
I will wait for our CI server to catch up and when it passes all tests it can be merged. |
|
Test passed. |
|
@xqms One case this patch seems to not address is that the |
|
@jonbinney @mikeferguson FYI Can you imagine any cases where this patch might have negative side effects (especially for high level packages)? |
|
I see the benefit to doing a sum of the queue sizes over the current behavior or doing a max of the queue sizes. However, I am weary of this this change causing increased resource usage in very particular scenarios. I think we should bring in some outside review on this one. I am +0 to this since the result is still a flawed concept at the expense of a considerable behavior change. This is a good example of why we need to break API with ROS 2.0. |
|
@dirk-thomas this could do funny things if people rely on the current behavior (of the queue-size being set with the first advertise). Consider the case where I have 10 different filter classes, each of which take an image and publish a filtered image. Then in some main loop of my node i might have: To make things easy, someone may create a separate publisher in each filter class, but for the same topic and with the same queue_size. If that queue_size is 100, this PR would make the total queue size 1000, which could be a LOT of memory. That said, I don't know of any specific existing ROS package which follows this pattern. As has been pointed out above, having a separate queue for each publisher seems to be the "Right" thing to do. This would mean that if I have two classes which publish on the same topic, they will behave the same whether i start them in separate roscpp nodes, or if i combine them into a single running roscpp node. (I realize there's an implementation effort with that) I would consider switching to either sum of queue sizes or switching to separate queues to be pretty big changes, not just quick workarounds. |
|
@jonbinney This PR is exactly proposing this: using the sum of queue sizes. I am not sure if I understand you correctly - do you consider that to be a quick workaround which you don't like to see? The increased memory usage is indeed a consequence. I think the increases memory usage is an acceptable trade off compared to a better behavior for a use case like this:
Both work well when being used independently but when used together they don't work at all - at least when A is registered before B. Having separate queues would indeed be the clean solution but due to the necessary refactoring that will very likely be out of scope. |
|
My point was just that the increase in memory usage when switching to the sum of queue sizes could be extreme. In my example, switching to sum of queue sizes would multiply memory usage by 10. |
|
(factor of 10) |
|
The other half of the behavior which isn't clear is that if the Publisher's are destroyed then the queue size will go back down, (@dirk-thomas will have to confirm that) so it might have fluctuating queue size which may also be bad if the queue is staying full. I agree that changing the implementation to have a queue for each publisher is not in the scope of this issue nor something we could do for Indigo. |
|
Agreed, we should not try to do the split queues for indigo. My hunch is that it is best to stick with the current behavior for indigo, since even switching to sum of queue sizes could break things (cause lots of memory usage) and since sum of queue sizes isn't the "right" fix anyway. Edit: "not try" |
|
The queue size should go down again when publishers are removed: https://github.com/ros/ros_comm/pull/450/files#diff-7e9728328ffc5c67a41abae998836bb2R126 The pending question is to handle |
|
Whenever the queue size is reduced I think the rest of the code base won't correctly reduce the size of the queue: e.g. TransportSubscriberLink::enqueueMessage assumes to only remove one message before adding a new one while it will now need to remove old messages until the length of the queue is smaller then the updated max size. |
|
I seem to have messed up the commit anyway, sorry. Please wait a moment while I fix this mess. |
|
Okay, now it's ready for review. Sorry for the noise. @dirk-thomas: I integrated your suggestion with the local variable.
Do you think throwing away old messages until the queue has the correct size is okay? I was kind of wondering about this and decided not to do it since I wasn't sure. Of course, the 'correct' solution is to throw away any messages published by this publisher, but that's not possible without separate queues. |
The old behavior of TransportSubscriberLink::enqueueMessage() was to remove one message to make room for a new message. Since the queue size is variable now, change that.
|
Here's a commit for dropping messages until the queue size is okay again, in case we decide that is the better approach. |
|
Test passed. |
|
We have discussed this intensively and do see a big chance for regressions. The problem is that the API is designed to allow the Publisher being used as a kind of singleton (per topic) so different code parts access the same instance - sometime just to get access to the publishers properties. This patch would change the behavior of the API dramatically and will likely cause hard-to-detect regressions in several higher level packages. Also the Python client library would need be updated to provide similar behavior. Due to this uncertainty and big impact the PR won't be merged for the upcoming release of Indigo. I do understand that the answer is not great for you since it means the current behavior (which is far from being good) will stick around in ROS for longer. But as the maintainer and having to guarantee stability of these core functionalities I am too uncomfortable to merge this change into Indigo. I am not sure how the upgrade path can look like. We could consider to apply it for the next ROS distribution (j-turtle). Since the development cycle for it is very long it would give us the chance to identify problems and try to address them. |
|
I see, I understand your point about the regressions. Is the consensus still that the best solution would be separate queues for each publisher? Maybe we can make that happen in time for j-turtle? |
|
Even the separate queue approach would break the currently documented behavior and how packages use the API. We could go for it but I am not sure if it is worth the effort. For the new ROS 2 related development this is being addresses already so we might not spend a lot of time implementing this change for ROS 1. |
|
Alright, then I'm fine with closing this PR. The issue is easy to work around once you understand what is going on. And we can wait with a proper solution until ROS 2. |
|
Thank you for your effort anyway. |
Currently, all
ros::Publisheron a single topic share a message queue with the length of the queue determined by the first publisher. On advertising,TopicManagertries to find a previousPublicationfor the advertised topic and only adds the callbacks to it, discarding any other options the caller provided (see here).There are often cases in which this behavior does not make sense. Each "advertiser" of the topic probably provides a reasonable queue length for his messages. So the internal queue length of
Publicationshould probably be the sum of all requested queue lengths.This PR currently contains a unit test for that case (which currently fails). If you agree that the current behavior is not desired, I will try to bring in a patch for discussion.