-
Notifications
You must be signed in to change notification settings - Fork 60
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
Refactors the socket broadcast client #329
Conversation
This commit refactors the socket broadcast client. It switches out the underlying queue to a circular buffer, that way the memory pressure of the broadcast client remains constant without needing to do work at sporadic intervals. The new structure should hopefully also make it easier for someon to reason about the websocket layer. Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Outdated
Show resolved
Hide resolved
rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Outdated
Show resolved
Hide resolved
rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
@aaronchongth, @koonpeng this is good to review again. I've added some integration tests. |
Signed-off-by: Arjo Chakravarty <[email protected]>
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.
Just a few nitpicks from me, and I saw that some files were missing EOF new lines. But overall LGTM, we can wait for an approval from KP too
rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Outdated
Show resolved
Hide resolved
rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Outdated
Show resolved
Hide resolved
rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Outdated
Show resolved
Hide resolved
rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Outdated
Show resolved
Hide resolved
// This is a horrible piece of code and defeats | ||
// the purpose of the tests. But unfortunately websocketpp | ||
// does not correctly return if a send was successful or not. | ||
// Thus packets may be lost. |
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.
For this test, we can use a promise to wait until the reconnect happens before sending the 2nd message. Something like
const std::promise<void> on_init_promise;
auto init_function(std::promise<void>& promise) {
...
promise.set_value();
}
REQUIRE_NO_THROW(on_init_promise.get_future().wait_for(1s));
// send 2nd message
Technically we can use this for test_client.cpp
as well, but this requires the use of the reconnect init function, which kind of makes the 2 tests overlap.
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.
After much hammering... I'm sorry to say there still are corner cases... It seems that sometimes on my machine the reconnection does not guarantee it stays... reconnected. Im trying to figure out if its abug in the logic or something else.
There is a minor style issue which is making the non-asan test failing. |
98a29ee
to
292a8a6
Compare
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Tests flaky even after improvements. Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Thanks @koonpeng for spotting the timing issue. It seems you were right about the server not being cleanly closed. This commit fixes that by cleanly closing the server in the test. Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
292a8a6
to
6ae8075
Compare
* Refactors the socket broadcast client This commit refactors the socket broadcast client. It switches out the underlying queue to a circular buffer, that way the memory pressure of the broadcast client remains constant without needing to do work at sporadic intervals. The new structure should hopefully also make it easier for someon to reason about the websocket layer. Signed-off-by: Arjo Chakravarty <[email protected]> * ROS-ify logging. Signed-off-by: Arjo Chakravarty <[email protected]> * Remove unessecary dependency Signed-off-by: Arjo Chakravarty <[email protected]> * Add lock Signed-off-by: Arjo Chakravarty <[email protected]> * Header guard Signed-off-by: Arjo Chakravarty <[email protected]> * Use enum for status Signed-off-by: Arjo Chakravarty <[email protected]> * Const reference to prevent copy Signed-off-by: Arjo Chakravarty <[email protected]> * Remove redundant include Signed-off-by: Arjo Chakravarty <[email protected]> * Fix move Signed-off-by: Arjo Chakravarty <[email protected]> * Move everything to one thread. Signed-off-by: Arjo Chakravarty <[email protected]> * Fixed "deadlock" Signed-off-by: Arjo Chakravarty <[email protected]> * Clean up reconnection logic Signed-off-by: Arjo Chakravarty <[email protected]> * Delete move and copy constructors. Signed-off-by: Arjo Chakravarty <[email protected]> * Remove FastAPI file Signed-off-by: Arjo Chakravarty <[email protected]> * More cleanups Signed-off-by: Arjo Chakravarty <[email protected]> * Add unit tests and fix a bunch of corner cases. Signed-off-by: Arjo Chakravarty <[email protected]> * Style Signed-off-by: Arjo Chakravarty <[email protected]> * Address feedback Signed-off-by: Arjo Chakravarty <[email protected]> * Address feedback Signed-off-by: Arjo Chakravarty <[email protected]> * Address logging feedback Signed-off-by: Arjo Chakravarty <[email protected]> * Address feedback Signed-off-by: Arjo Chakravarty <[email protected]> * Style Signed-off-by: Arjo Chakravarty <[email protected]> * Horrible hack to make tests always pass. Signed-off-by: Arjo Chakravarty <[email protected]> * Address Feedback Tests flaky even after improvements. Signed-off-by: Arjo Chakravarty <[email protected]> * Style Signed-off-by: Arjo Chakravarty <[email protected]> * Fix tests. Thanks @koonpeng for spotting the timing issue. It seems you were right about the server not being cleanly closed. This commit fixes that by cleanly closing the server in the test. Signed-off-by: Arjo Chakravarty <[email protected]> * Address feedback about logging. Signed-off-by: Arjo Chakravarty <[email protected]> * Style Signed-off-by: Arjo Chakravarty <[email protected]> --------- Signed-off-by: Arjo Chakravarty <[email protected]>
This commit refactors the socket broadcast client. It switches out the underlying queue to a circular buffer, that way the memory pressure of the broadcast client remains constant without needing to do work at sporadic intervals. The new structure should hopefully also make it easier for someone to reason about the websocket layer and help us catch bugs if they exist.
I've also included an example socket client and a test server. The following plot shows memory usage after restarting the server multiple times: