-
Notifications
You must be signed in to change notification settings - Fork 211
Feature/rec faster callbacks #2573
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
Draft
KerstinKeller
wants to merge
4
commits into
master
Choose a base branch
from
feature/rec_faster_callbacks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| This license file applies to everything in this repository except that which | ||
| is explicitly annotated as being written by other authors, i.e. the Boost | ||
| queue (included in the benchmarks for comparison), Intel's TBB library (ditto), | ||
| dlib::pipe (ditto), | ||
| the CDSChecker tool (used for verification), the Relacy model checker (ditto), | ||
| and Jeff Preshing's semaphore implementation (used in the blocking queue) which | ||
| has a zlib license (embedded in lightweightsempahore.h). | ||
|
|
||
| --- | ||
|
|
||
| Simplified BSD License: | ||
|
|
||
| Copyright (c) 2013-2016, Cameron Desrochers. | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without modification, | ||
| are permitted provided that the following conditions are met: | ||
|
|
||
| - Redistributions of source code must retain the above copyright notice, this list of | ||
| conditions and the following disclaimer. | ||
| - Redistributions in binary form must reproduce the above copyright notice, this list of | ||
| conditions and the following disclaimer in the documentation and/or other materials | ||
| provided with the distribution. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
| EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
| MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
| THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
| OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
| TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| --- | ||
|
|
||
| I have also chosen to dual-license under the Boost Software License as an alternative to | ||
| the Simplified BSD license above: | ||
|
|
||
| Boost Software License - Version 1.0 - August 17th, 2003 | ||
|
|
||
| Permission is hereby granted, free of charge, to any person or organization | ||
| obtaining a copy of the software and accompanying documentation covered by | ||
| this license (the "Software") to use, reproduce, display, distribute, | ||
| execute, and transmit the Software, and to prepare derivative works of the | ||
| Software, and to permit third-parties to whom the Software is furnished to | ||
| do so, all subject to the following: | ||
|
|
||
| The copyright notices in the Software and this entire statement, including | ||
| the above license grant, this restriction and the following disclaimer, | ||
| must be included in all copies of the Software, in whole or in part, and | ||
| all derivative works of the Software, unless such copies or derivative | ||
| works are solely in the form of machine-executable object code generated by | ||
| a source language processor. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT | ||
| SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE | ||
| FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, | ||
| ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| #include "rec_client_core/topic_info.h" | ||
| #include "rec_client_core/upload_config.h" | ||
|
|
||
| #include <array> | ||
| #include <chrono> | ||
| #include <cstdint> | ||
| #include <algorithm> | ||
|
|
@@ -66,6 +67,59 @@ namespace eCAL | |
| { | ||
| namespace rec | ||
| { | ||
| class EcalRecImpl::ReceiveDispatchThread : public InterruptibleLoopThread | ||
| { | ||
| public: | ||
| ReceiveDispatchThread(EcalRecImpl& ecal_rec_impl_) | ||
| : InterruptibleLoopThread(std::chrono::milliseconds(10)) | ||
| , ecal_rec_impl(ecal_rec_impl_) | ||
| , token(ecal_rec_impl_.receive_dispatch_queue_) | ||
| { | ||
| } | ||
|
|
||
| protected: | ||
| // forward data from the queue to the actual buffer | ||
| void Loop() override | ||
| { | ||
| constexpr int max_items = 16; | ||
| std::array<std::shared_ptr<Frame>, max_items> frames; | ||
| size_t no_items = 0; | ||
| do | ||
| { | ||
| no_items = ecal_rec_impl.receive_dispatch_queue_.try_dequeue_bulk(token, frames.data(), frames.size()); | ||
| assert(no_items < max_items); | ||
|
|
||
| for (size_t i = 0; i < no_items; ++i) | ||
| { | ||
| auto& frame = frames[i]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index] auto& frame = frames[i];
^ |
||
|
|
||
| // Add to the pre-buffer (it is thread-safe by using a mutex internally) | ||
| ecal_rec_impl.pre_buffer_.push_back(frame); | ||
|
|
||
| { | ||
| // Add to the currently recording job (if there is any) | ||
| const std::shared_lock<decltype(ecal_rec_impl.recorder_mutex_)> recorder_lock(ecal_rec_impl.recorder_mutex_); | ||
| if (ecal_rec_impl.recording_recorder_job_ != nullptr) | ||
| { | ||
| ecal_rec_impl.recording_recorder_job_->AddFrame(frame); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| // Add to the subscriber statistics | ||
| const std::lock_guard<decltype(ecal_rec_impl.subscriber_throughput_mutex_)> subscriber_statistics_lock(ecal_rec_impl.subscriber_throughput_mutex_); | ||
| ecal_rec_impl.subscriber_throughput_statistics_.AddFrame(frame->data_.size()); | ||
|
KerstinKeller marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } while (no_items > 0); | ||
| } | ||
|
|
||
| private: | ||
| EcalRecImpl& ecal_rec_impl; | ||
| moodycamel::ConsumerToken token; | ||
| }; | ||
|
|
||
|
|
||
| EcalRecImpl::EcalRecImpl() | ||
| : addon_manager_(std::make_unique<AddonManager>([this](int64_t job_id, const std::string& addon_id, const RecAddonJobStatus& job_status) | ||
| { | ||
|
|
@@ -90,11 +144,15 @@ namespace eCAL | |
|
|
||
| monitoring_thread_ = std::make_unique<MonitoringThread>(*this); | ||
| monitoring_thread_->Start(); | ||
|
|
||
| receive_dispatch_thread = std::make_unique<ReceiveDispatchThread>(*this); | ||
| receive_dispatch_thread->Start(); | ||
| } | ||
|
|
||
| EcalRecImpl::~EcalRecImpl() | ||
| { | ||
| DisconnectFromEcal(); | ||
| receive_dispatch_thread->Interrupt(); | ||
| receive_dispatch_thread->Join(); | ||
|
|
||
| // Interrupt monitoring thread | ||
| monitoring_thread_->Interrupt(); | ||
|
|
@@ -723,28 +781,14 @@ namespace eCAL | |
|
|
||
| void EcalRecImpl::EcalMessageReceived(const eCAL::STopicId& topic_id_, const eCAL::SReceiveCallbackData& data_) | ||
| { | ||
| const thread_local moodycamel::ProducerToken token(receive_dispatch_queue_); | ||
|
|
||
| auto ecal_receive_time = eCAL::Time::ecal_clock::now(); | ||
| auto system_receive_time = std::chrono::steady_clock::now(); | ||
|
|
||
| std::shared_ptr<Frame> frame = std::make_shared<Frame>(&data_, topic_id_.topic_name, ecal_receive_time, system_receive_time); | ||
|
|
||
| // Add to the pre-buffer (it is thread-safe by using a mutex internally) | ||
| pre_buffer_.push_back(frame); | ||
|
|
||
| { | ||
| // Add to the currently recording job (if there is any) | ||
| std::shared_lock<decltype(recorder_mutex_)> recorder_lock(recorder_mutex_); | ||
| if (recording_recorder_job_ != nullptr) | ||
| { | ||
| recording_recorder_job_->AddFrame(std::move(frame)); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| // Add to the subscriber statistics | ||
| const std::lock_guard<decltype(subscriber_throughput_mutex_)> subscriber_statistics_lock(subscriber_throughput_mutex_); | ||
| subscriber_throughput_statistics_.AddFrame(data_.buffer_size); | ||
| } | ||
| receive_dispatch_queue_.enqueue(token, std::move(frame)); | ||
| } | ||
|
|
||
| Throughput EcalRecImpl::GetSubscriberThroughput() const | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| .. | ||
| THIS FILE IS AUTO-GENERATED AND SHOULD NOT BE EDITED MANUALLY. | ||
|
|
||
| .. include:: /include.txt | ||
|
|
||
| .. _thirdparty_licenses_concurrentqueue: | ||
|
|
||
| =============================================== | ||
| concurrentqueue | ||
| =============================================== | ||
|
|
||
| .. list-table:: | ||
| :widths: 20 80 | ||
| :header-rows: 0 | ||
|
|
||
| * - **License** | ||
|
|
||
| - BSD-2-Clause | ||
|
|
||
| * - **Copyright** | ||
|
|
||
| - Copyright (c) 2013-2016, Cameron Desrochers. | ||
|
|
||
| * - **Repository** | ||
|
|
||
| - https://github.com/cameron314/concurrentqueue | ||
|
|
||
| * - **Upstream version** [#upstreamversion]_ | ||
|
|
||
| - `593df78ec309be7a7b456b3334025ccade1d2d66 <https://github.com/cameron314/concurrentqueue/tree/593df78ec309be7a7b456b3334025ccade1d2d66>`_ | ||
|
|
||
| * - **Integration** | ||
|
|
||
| - | ||
|
|
||
| - |fa-github| Git Submodule :file:`/thirdparty/concurrentqueue/concurrentqueue` | ||
|
|
||
| - |fa-windows| Windows builds | ||
|
|
||
| - |fa-ubuntu| Linux builds | ||
|
|
||
| .. [#upstreamversion] *The actual version used for building may differ from the listed dependency version.* | ||
| *Especially Linux binaries are often built against system packages, if available.* | ||
| *Check build files for further information.* | ||
|
|
||
| License Files | ||
| ============= | ||
|
|
||
| :file:`LICENSE.md` | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| .. literalinclude:: concurrentqueue/LICENSE.md | ||
| :language: none |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.