SlideShare a Scribd company logo
1 of 26
Download to read offline
DDS 中的各種 Entities
(Entities in DCPS)
20170220
Taka Wang
In a Nutshell
• Introduce major entities in DCPS (Data-Centric Publish-Subscribe)
speci
fi
cation from the class diagram and implementation
viewpoints.
• Know the relationships and cardinalities among these entities.
• Discuss two ways (sync, async) to receive noti
fi
cation from DDS
middleware and common pitfalls.
• Summarize learning resources.
Take Aways For Busy People
• Create Few Domain Participants
• Create Entities Early
• Prefer Waitset over Listener
•
一
個 publisher/subscriber 上,可以有多個 datawriter/datareader
•
一
個 datawriter/datareader 只能對應
一
個 topic (concrete class),但
不同 datawriter/reader 可以對應同
一
個 topic
Let's Dive Right In
0. 也許你看過這張概念圖
但沒有深入了解各
自
的
目
的,也不知道彼此的association
總之就是照抄範例,創建
一
堆 entities,然後開始
用
reader, writer 讀寫
0.1 DCPS 的模組 (module) 組成
Infrastructure Module
Domain Module
Publication Module Subscription Module
Topic-De
fi
nition Module
內含 Entity
Entity 是上
面
四個模組的
abstract base class
Source Page
本
文
略過(不難理解),請參考此
頁
面
Entity is an Abstract Base Class
• An Entity is the common parent for the most important DDS-elements:
• DomainParticipant: Application connector to a Network Domain.
(是
用
來進入不同 Domain 的物件,不同 domain 間訊息不會互通,是隔離的)
• Topic: De
fi
nes the messages that will be transmitted across the network.
• DataWriter: Accessor to write typed data (Topic) into a Domain.
• DataReader: Accessor to read typed data (Topic) from a Domain.
• Publisher: Aggregation of DataWriter objects, used to disseminate data.
• Subscriber: Aggregation of DataReader objects, used to collect data.
1. Infrastructure Module
主要包括:
- Entity 這個抽象基類
- Listener 與 WaitSet 這
兩種互動模式
- Qos 與 Status 定義
Source Page
1.1. Conceptional DataReader
Listener
Listener 是 middleware
用
來非同步 (async) 的通知應
用
程式,有 status 改變了
Source Page
1.2. Listener Class Diagram
Source Page
• 所有的 Entity 都有對應的 Listener
• 例如 DataReaderListener 就是
Data Reader 的 Listener
• Listener 定義很多 Callback,
用
來
跟應
用
程式互動, 通知應
用
程式
Status 發
生
不同的改變
• 類似 exception handler 機制,如
果 Subscriber 已經處理這個狀態改
變,則上層的 DataReader 就不
用
處理這個改變。反之,
一
路往
parent 傳遞 (propagation)。
parent
1.3. Status and Waitset
• Topic, Subscriber, Data Reader 與 Data Writer 四種 Entity 上有對應
的 Status
• 請參考下列
頁
面
的 Class Diagram 與列表
• Status
• Waitset
1.4. Conceptional DataReader WaitSet
應
用
程式將關注的 Condition 丟進 waitset (步驟
一
),然後等待 StatusCondition
中任
一
trigger_value 從 FALSE 變成 TRUE (步驟
二
), 這時候應
用
程式主動去拿
等待的結果並做處理 (步驟三)。換句話說,應
用
程式是卡住等待狀態改變的。
步驟
一
通常在應
用
程式初始化設定,步驟
二
跟三通常放在應
用
程式主迴圈中等待
Source Page
2. Domain Module
主要包括:
- Domain Participant 這
個 Entity 抽象類 的
子
類
- Domain Participant
Factory 類
- Domain Participant
Listener 類
有很多
factory method
Source Page
2.1 Domain Participant
• 因為是 Entity 的
子
類,所以有 QosPolicies, StatusCondition 與 Listener (詳
見
1. Infrastructure
Module 的 class diagram)
• Domain Participant 扮演的
角
色
• 應
用
程式要進入特定 Domain,需要透過 Domain Participant 建立 Virtual network Link,做到
Physical Network 上不同 DDS 應
用
隔離互不
干
擾的效果。
• 是所有 Entities 的
工
廠 (
見
上
頁
的 Factory methods)
• 是所有 Entities (詳
見
0.) 的容器 (container)
• 沒有
自
己
專
用
的 Listener (domain listener) 去聽 domain 狀態變化,
而
是
用
來處理容器內所
有 Entities 沒有處理的狀態變化 (還記得1.1的
一
路往 parent 傳遞 (propagation) 嗎?)
Source Page
3. Subscription Module
主要包括下列四個重要的類別:
- Subscriber
- DataReader
- DataSample
- SampleInfo
Listener 與 Condition 請參考前
面
介紹
DataReader 加上 Subscriber 形
成 Subscription 概念
Source Page
3.1. Subscriber & Sample
• Subscriber 主要負責收集來
自
不同 Publisher 的資料
• DataReader 不負責從 Network 直接收資料,
而
是由 Subscriber 決
定何時、如何將資料傳到 DataReader
• Subscriber 只收所屬 Partition 的 samples
• Subscriber 也是 DataReaders 的
工
廠 (DomainParticipant 也是)
• SampleInfo
用
來描述 Sample 的相關狀態
Source Page
3.2 DataReader
• DataReader 是 abstract class, 針對特定 type,有各
自
的 concrete
data reader (例如 Foo Type 會由 preprocessor 產
生
FooDataReader)
• Typed DataReader
用
來存取對應 type 的 sample 與其對應的
SampleInfo
• DataReader 上有 Listeners, Conditions 與 Qos
Source Page
4. Publication Module
主要包括下列兩個重要的類別:
- Publisher
- DataWriter
DataWriter 加上 Publisher 形成
Publication 概念
Source Page
Discussion and Best Practices
Prefer Waitset over Listener
• 從
文
件上可以知道 Data Reader 有兩種接收資料的
方
式
• waitset: blocking (透過 condition variable 去卡,類似 Unix Select的
行
為)
• listener: non-blocking, aka. async (透過 register callback handler)
• 如果接收端 (application) 的 waiting loop 並沒有其他
工
作要做,只是等待資
料進來做後續處理,這時候請盡量使
用
waitset。這樣的 code 比較安全 (雖
然有 Context Switch 的 Overhead),除非 callback 內的處理非常快,追求
extreme 的效能才
用
listener (做 benchmark,
而
不是 production)
Why Waitset?
• Listener 的 callback 是被 DDS middleware 的 thread 呼叫的,但 DDS middleware thread 通常都在做
這些事情:
• 為各個 Data Reader 收資料
• 收發 metadata 給 Data Writer
• 處理 Deadline 與 Liveliness 之類的 Qos
• 呼叫 Callback 時,接收端的 main thread 雖然還在跑 (async),但 DDS middleware 的 thread 此時卡
住,要等 Callback 內的事情處理完 (寫檔、寫資料庫等等),造成下列後果:
• Data Readers 會漏資料
• 無法正確處理(通知別
人
) Liveliness 狀態
Notice from documents about listener
• PT: Something worth pointing out is that the handler code will
execute in a middleware thread. As a result, when using listeners
you should try to minimize the time spent in the listener itself.
• RTI: While a Listener is used to provide a callback for
asynchronous access, Conditions and WaitSets provide
synchronous data access. This means that you use a WaitSet to
block an application thread until data becomes available. This is
safer than using a listener because you do not have to worry about
blocking Connext's threads.
Entities management
• Create Few DomainParticipants (在
一
程式中,
一
個 Domain,
一
個 DP 就好),否則會浪
費很多系統資源,因為它主要
用
來:
• DomainParticipants
用
來尋找 Domain 中的其他 Entities,並管理這些關聯
• 創建 Thread
• Create Entities Early (不要等到要 Read/Write 才創建 DataWriter/DataReader,程式
一
開
始初始化時就應該創建)
• 需要幫
自
己
Allocate Queue
• 傳送 discovery 訊息通知其他程式,
自
己
已經存在於 Domain 中 (可想
而
知需要點時間)
Take Aways
• Create Few Domain Participants
• Create Entities Early
• Prefer Waitset over Listener
•
一
個 publisher/subscriber 上,可以有多個 datawriter/datareader
•
一
個 datawriter/datareader 只能對應
一
個 topic (concrete class),但
不同 datawriter/reader 可以對應同
一
個 topic
Reference
• Vortex Lite C99 API Reference Guide (了解 DCPS 概念與架構,推薦閱讀
而
不是只當作
API 查閱
文
件,與 ISO C++ 章節內容完全相同)
• Best Practices using RTI Connext DDS (同樣適
用
於 PT 的實作,推薦閱讀)
• Vortex - The DDS Tutorial (最輕量化的教學
文
件,短短20多
頁
,幫助你掌握八成重要的概
念)
• DataWriters/Publishers and DataReaders/Subscribers (清楚的解釋四種 Entities 的關係)
• RTI: WaitSet with Status Condition (介紹 Waitset 概念)
• PT: Reading and Writing Data (介紹 Waitset 與 Listener
用
法)
Thank you

More Related Content

Similar to Entities in DCPS (DDS)

Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程appollo0312
 
Azure Data Lake 簡介
Azure Data Lake 簡介Azure Data Lake 簡介
Azure Data Lake 簡介Herman Wu
 
N-layer design & development
N-layer design & developmentN-layer design & development
N-layer design & developmentXuefeng Zhang
 
一次Web性能测试小结
一次Web性能测试小结一次Web性能测试小结
一次Web性能测试小结beiyu95
 
20140326联动优势数据访问层DAL架构和实践7(刘胜)工行交流
20140326联动优势数据访问层DAL架构和实践7(刘胜)工行交流20140326联动优势数据访问层DAL架构和实践7(刘胜)工行交流
20140326联动优势数据访问层DAL架构和实践7(刘胜)工行交流liu sheng
 
前端性能优化和自动化
前端性能优化和自动化前端性能优化和自动化
前端性能优化和自动化kaven yan
 
COSCUP 2019 - 開源大數據引擎 Greenplum
COSCUP 2019 - 開源大數據引擎 GreenplumCOSCUP 2019 - 開源大數據引擎 Greenplum
COSCUP 2019 - 開源大數據引擎 GreenplumOmni-Alex Chen
 
Taobao数据库这5年
Taobao数据库这5年Taobao数据库这5年
Taobao数据库这5年yp_fangdong
 
20120613联动优势数据访问层DAL架构和实践4(刘胜)最新特性
20120613联动优势数据访问层DAL架构和实践4(刘胜)最新特性20120613联动优势数据访问层DAL架构和实践4(刘胜)最新特性
20120613联动优势数据访问层DAL架构和实践4(刘胜)最新特性liu sheng
 
網站設計100步
網站設計100步網站設計100步
網站設計100步evercislide
 
数据库性能诊断的七种武器
数据库性能诊断的七种武器数据库性能诊断的七种武器
数据库性能诊断的七种武器Leyi (Kamus) Zhang
 
数据库系统设计漫谈
数据库系统设计漫谈数据库系统设计漫谈
数据库系统设计漫谈james tong
 
Java SE 7 技術手冊投影片第 14 章 - 整合資料庫
Java SE 7 技術手冊投影片第 14 章 - 整合資料庫Java SE 7 技術手冊投影片第 14 章 - 整合資料庫
Java SE 7 技術手冊投影片第 14 章 - 整合資料庫Justin Lin
 
zookeeper-internals
zookeeper-internalszookeeper-internals
zookeeper-internalsLiu Shaohui
 
選擇正確的Solution 來建置現代化的雲端資料倉儲
選擇正確的Solution 來建置現代化的雲端資料倉儲選擇正確的Solution 來建置現代化的雲端資料倉儲
選擇正確的Solution 來建置現代化的雲端資料倉儲Herman Wu
 
Dci vs aggregate_dddtw_2021-0.3-16-9
Dci vs aggregate_dddtw_2021-0.3-16-9Dci vs aggregate_dddtw_2021-0.3-16-9
Dci vs aggregate_dddtw_2021-0.3-16-9teddysoft
 
深入研究 Windows 系統服務 效能調校與故障排除
深入研究 Windows 系統服務    效能調校與故障排除深入研究 Windows 系統服務    效能調校與故障排除
深入研究 Windows 系統服務 效能調校與故障排除5045033
 
The Construction and Practice of Apache Pegasus in Offline and Online Scenari...
The Construction and Practice of Apache Pegasus in Offline and Online Scenari...The Construction and Practice of Apache Pegasus in Offline and Online Scenari...
The Construction and Practice of Apache Pegasus in Offline and Online Scenari...acelyc1112009
 
Web development with zend framework
Web development with zend frameworkWeb development with zend framework
Web development with zend frameworkthinkinlamp
 
Couchbase introduction - Chinese
Couchbase introduction - Chinese Couchbase introduction - Chinese
Couchbase introduction - Chinese Vickie Zeng
 

Similar to Entities in DCPS (DDS) (20)

Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程
 
Azure Data Lake 簡介
Azure Data Lake 簡介Azure Data Lake 簡介
Azure Data Lake 簡介
 
N-layer design & development
N-layer design & developmentN-layer design & development
N-layer design & development
 
一次Web性能测试小结
一次Web性能测试小结一次Web性能测试小结
一次Web性能测试小结
 
20140326联动优势数据访问层DAL架构和实践7(刘胜)工行交流
20140326联动优势数据访问层DAL架构和实践7(刘胜)工行交流20140326联动优势数据访问层DAL架构和实践7(刘胜)工行交流
20140326联动优势数据访问层DAL架构和实践7(刘胜)工行交流
 
前端性能优化和自动化
前端性能优化和自动化前端性能优化和自动化
前端性能优化和自动化
 
COSCUP 2019 - 開源大數據引擎 Greenplum
COSCUP 2019 - 開源大數據引擎 GreenplumCOSCUP 2019 - 開源大數據引擎 Greenplum
COSCUP 2019 - 開源大數據引擎 Greenplum
 
Taobao数据库这5年
Taobao数据库这5年Taobao数据库这5年
Taobao数据库这5年
 
20120613联动优势数据访问层DAL架构和实践4(刘胜)最新特性
20120613联动优势数据访问层DAL架构和实践4(刘胜)最新特性20120613联动优势数据访问层DAL架构和实践4(刘胜)最新特性
20120613联动优势数据访问层DAL架构和实践4(刘胜)最新特性
 
網站設計100步
網站設計100步網站設計100步
網站設計100步
 
数据库性能诊断的七种武器
数据库性能诊断的七种武器数据库性能诊断的七种武器
数据库性能诊断的七种武器
 
数据库系统设计漫谈
数据库系统设计漫谈数据库系统设计漫谈
数据库系统设计漫谈
 
Java SE 7 技術手冊投影片第 14 章 - 整合資料庫
Java SE 7 技術手冊投影片第 14 章 - 整合資料庫Java SE 7 技術手冊投影片第 14 章 - 整合資料庫
Java SE 7 技術手冊投影片第 14 章 - 整合資料庫
 
zookeeper-internals
zookeeper-internalszookeeper-internals
zookeeper-internals
 
選擇正確的Solution 來建置現代化的雲端資料倉儲
選擇正確的Solution 來建置現代化的雲端資料倉儲選擇正確的Solution 來建置現代化的雲端資料倉儲
選擇正確的Solution 來建置現代化的雲端資料倉儲
 
Dci vs aggregate_dddtw_2021-0.3-16-9
Dci vs aggregate_dddtw_2021-0.3-16-9Dci vs aggregate_dddtw_2021-0.3-16-9
Dci vs aggregate_dddtw_2021-0.3-16-9
 
深入研究 Windows 系統服務 效能調校與故障排除
深入研究 Windows 系統服務    效能調校與故障排除深入研究 Windows 系統服務    效能調校與故障排除
深入研究 Windows 系統服務 效能調校與故障排除
 
The Construction and Practice of Apache Pegasus in Offline and Online Scenari...
The Construction and Practice of Apache Pegasus in Offline and Online Scenari...The Construction and Practice of Apache Pegasus in Offline and Online Scenari...
The Construction and Practice of Apache Pegasus in Offline and Online Scenari...
 
Web development with zend framework
Web development with zend frameworkWeb development with zend framework
Web development with zend framework
 
Couchbase introduction - Chinese
Couchbase introduction - Chinese Couchbase introduction - Chinese
Couchbase introduction - Chinese
 

More from Jamie (Taka) Wang

More from Jamie (Taka) Wang (20)

20200606_insight_Ignition
20200606_insight_Ignition20200606_insight_Ignition
20200606_insight_Ignition
 
20200727_Insight workstation
20200727_Insight workstation20200727_Insight workstation
20200727_Insight workstation
 
20200723_insight_release_plan
20200723_insight_release_plan20200723_insight_release_plan
20200723_insight_release_plan
 
20210105_量產技轉
20210105_量產技轉20210105_量產技轉
20210105_量產技轉
 
20200808自營電商平台策略討論
20200808自營電商平台策略討論20200808自營電商平台策略討論
20200808自營電商平台策略討論
 
20200427_hardware
20200427_hardware20200427_hardware
20200427_hardware
 
20200429_ec
20200429_ec20200429_ec
20200429_ec
 
20200607_insight_sync
20200607_insight_sync20200607_insight_sync
20200607_insight_sync
 
20220113_product_day
20220113_product_day20220113_product_day
20220113_product_day
 
20200429_software
20200429_software20200429_software
20200429_software
 
20200602_insight_business
20200602_insight_business20200602_insight_business
20200602_insight_business
 
20200408_gen11_sequence_diagram
20200408_gen11_sequence_diagram20200408_gen11_sequence_diagram
20200408_gen11_sequence_diagram
 
20190827_activity_diagram
20190827_activity_diagram20190827_activity_diagram
20190827_activity_diagram
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
20161220 - microservice
20161220 - microservice20161220 - microservice
20161220 - microservice
 
20160217 - Overview of Vortex Intelligent Data Sharing Platform
20160217 - Overview of Vortex Intelligent Data Sharing Platform20160217 - Overview of Vortex Intelligent Data Sharing Platform
20160217 - Overview of Vortex Intelligent Data Sharing Platform
 
20151111 - IoT Sync Up
20151111 - IoT Sync Up20151111 - IoT Sync Up
20151111 - IoT Sync Up
 
20151207 - iot strategy
20151207 - iot strategy20151207 - iot strategy
20151207 - iot strategy
 
20141210 - Microservice Container
20141210 - Microservice Container20141210 - Microservice Container
20141210 - Microservice Container
 
20161027 - edge part2
20161027 - edge part220161027 - edge part2
20161027 - edge part2
 

Entities in DCPS (DDS)

  • 1. DDS 中的各種 Entities (Entities in DCPS) 20170220 Taka Wang
  • 2. In a Nutshell • Introduce major entities in DCPS (Data-Centric Publish-Subscribe) speci fi cation from the class diagram and implementation viewpoints. • Know the relationships and cardinalities among these entities. • Discuss two ways (sync, async) to receive noti fi cation from DDS middleware and common pitfalls. • Summarize learning resources.
  • 3. Take Aways For Busy People • Create Few Domain Participants • Create Entities Early • Prefer Waitset over Listener • 一 個 publisher/subscriber 上,可以有多個 datawriter/datareader • 一 個 datawriter/datareader 只能對應 一 個 topic (concrete class),但 不同 datawriter/reader 可以對應同 一 個 topic
  • 6. 0.1 DCPS 的模組 (module) 組成 Infrastructure Module Domain Module Publication Module Subscription Module Topic-De fi nition Module 內含 Entity Entity 是上 面 四個模組的 abstract base class Source Page 本 文 略過(不難理解),請參考此 頁 面
  • 7. Entity is an Abstract Base Class • An Entity is the common parent for the most important DDS-elements: • DomainParticipant: Application connector to a Network Domain. (是 用 來進入不同 Domain 的物件,不同 domain 間訊息不會互通,是隔離的) • Topic: De fi nes the messages that will be transmitted across the network. • DataWriter: Accessor to write typed data (Topic) into a Domain. • DataReader: Accessor to read typed data (Topic) from a Domain. • Publisher: Aggregation of DataWriter objects, used to disseminate data. • Subscriber: Aggregation of DataReader objects, used to collect data.
  • 8. 1. Infrastructure Module 主要包括: - Entity 這個抽象基類 - Listener 與 WaitSet 這 兩種互動模式 - Qos 與 Status 定義 Source Page
  • 9. 1.1. Conceptional DataReader Listener Listener 是 middleware 用 來非同步 (async) 的通知應 用 程式,有 status 改變了 Source Page
  • 10. 1.2. Listener Class Diagram Source Page • 所有的 Entity 都有對應的 Listener • 例如 DataReaderListener 就是 Data Reader 的 Listener • Listener 定義很多 Callback, 用 來 跟應 用 程式互動, 通知應 用 程式 Status 發 生 不同的改變 • 類似 exception handler 機制,如 果 Subscriber 已經處理這個狀態改 變,則上層的 DataReader 就不 用 處理這個改變。反之, 一 路往 parent 傳遞 (propagation)。 parent
  • 11. 1.3. Status and Waitset • Topic, Subscriber, Data Reader 與 Data Writer 四種 Entity 上有對應 的 Status • 請參考下列 頁 面 的 Class Diagram 與列表 • Status • Waitset
  • 12. 1.4. Conceptional DataReader WaitSet 應 用 程式將關注的 Condition 丟進 waitset (步驟 一 ),然後等待 StatusCondition 中任 一 trigger_value 從 FALSE 變成 TRUE (步驟 二 ), 這時候應 用 程式主動去拿 等待的結果並做處理 (步驟三)。換句話說,應 用 程式是卡住等待狀態改變的。 步驟 一 通常在應 用 程式初始化設定,步驟 二 跟三通常放在應 用 程式主迴圈中等待 Source Page
  • 13. 2. Domain Module 主要包括: - Domain Participant 這 個 Entity 抽象類 的 子 類 - Domain Participant Factory 類 - Domain Participant Listener 類 有很多 factory method Source Page
  • 14. 2.1 Domain Participant • 因為是 Entity 的 子 類,所以有 QosPolicies, StatusCondition 與 Listener (詳 見 1. Infrastructure Module 的 class diagram) • Domain Participant 扮演的 角 色 • 應 用 程式要進入特定 Domain,需要透過 Domain Participant 建立 Virtual network Link,做到 Physical Network 上不同 DDS 應 用 隔離互不 干 擾的效果。 • 是所有 Entities 的 工 廠 ( 見 上 頁 的 Factory methods) • 是所有 Entities (詳 見 0.) 的容器 (container) • 沒有 自 己 專 用 的 Listener (domain listener) 去聽 domain 狀態變化, 而 是 用 來處理容器內所 有 Entities 沒有處理的狀態變化 (還記得1.1的 一 路往 parent 傳遞 (propagation) 嗎?) Source Page
  • 15. 3. Subscription Module 主要包括下列四個重要的類別: - Subscriber - DataReader - DataSample - SampleInfo Listener 與 Condition 請參考前 面 介紹 DataReader 加上 Subscriber 形 成 Subscription 概念 Source Page
  • 16. 3.1. Subscriber & Sample • Subscriber 主要負責收集來 自 不同 Publisher 的資料 • DataReader 不負責從 Network 直接收資料, 而 是由 Subscriber 決 定何時、如何將資料傳到 DataReader • Subscriber 只收所屬 Partition 的 samples • Subscriber 也是 DataReaders 的 工 廠 (DomainParticipant 也是) • SampleInfo 用 來描述 Sample 的相關狀態 Source Page
  • 17. 3.2 DataReader • DataReader 是 abstract class, 針對特定 type,有各 自 的 concrete data reader (例如 Foo Type 會由 preprocessor 產 生 FooDataReader) • Typed DataReader 用 來存取對應 type 的 sample 與其對應的 SampleInfo • DataReader 上有 Listeners, Conditions 與 Qos Source Page
  • 18. 4. Publication Module 主要包括下列兩個重要的類別: - Publisher - DataWriter DataWriter 加上 Publisher 形成 Publication 概念 Source Page
  • 19. Discussion and Best Practices
  • 20. Prefer Waitset over Listener • 從 文 件上可以知道 Data Reader 有兩種接收資料的 方 式 • waitset: blocking (透過 condition variable 去卡,類似 Unix Select的 行 為) • listener: non-blocking, aka. async (透過 register callback handler) • 如果接收端 (application) 的 waiting loop 並沒有其他 工 作要做,只是等待資 料進來做後續處理,這時候請盡量使 用 waitset。這樣的 code 比較安全 (雖 然有 Context Switch 的 Overhead),除非 callback 內的處理非常快,追求 extreme 的效能才 用 listener (做 benchmark, 而 不是 production)
  • 21. Why Waitset? • Listener 的 callback 是被 DDS middleware 的 thread 呼叫的,但 DDS middleware thread 通常都在做 這些事情: • 為各個 Data Reader 收資料 • 收發 metadata 給 Data Writer • 處理 Deadline 與 Liveliness 之類的 Qos • 呼叫 Callback 時,接收端的 main thread 雖然還在跑 (async),但 DDS middleware 的 thread 此時卡 住,要等 Callback 內的事情處理完 (寫檔、寫資料庫等等),造成下列後果: • Data Readers 會漏資料 • 無法正確處理(通知別 人 ) Liveliness 狀態
  • 22. Notice from documents about listener • PT: Something worth pointing out is that the handler code will execute in a middleware thread. As a result, when using listeners you should try to minimize the time spent in the listener itself. • RTI: While a Listener is used to provide a callback for asynchronous access, Conditions and WaitSets provide synchronous data access. This means that you use a WaitSet to block an application thread until data becomes available. This is safer than using a listener because you do not have to worry about blocking Connext's threads.
  • 23. Entities management • Create Few DomainParticipants (在 一 程式中, 一 個 Domain, 一 個 DP 就好),否則會浪 費很多系統資源,因為它主要 用 來: • DomainParticipants 用 來尋找 Domain 中的其他 Entities,並管理這些關聯 • 創建 Thread • Create Entities Early (不要等到要 Read/Write 才創建 DataWriter/DataReader,程式 一 開 始初始化時就應該創建) • 需要幫 自 己 Allocate Queue • 傳送 discovery 訊息通知其他程式, 自 己 已經存在於 Domain 中 (可想 而 知需要點時間)
  • 24. Take Aways • Create Few Domain Participants • Create Entities Early • Prefer Waitset over Listener • 一 個 publisher/subscriber 上,可以有多個 datawriter/datareader • 一 個 datawriter/datareader 只能對應 一 個 topic (concrete class),但 不同 datawriter/reader 可以對應同 一 個 topic
  • 25. Reference • Vortex Lite C99 API Reference Guide (了解 DCPS 概念與架構,推薦閱讀 而 不是只當作 API 查閱 文 件,與 ISO C++ 章節內容完全相同) • Best Practices using RTI Connext DDS (同樣適 用 於 PT 的實作,推薦閱讀) • Vortex - The DDS Tutorial (最輕量化的教學 文 件,短短20多 頁 ,幫助你掌握八成重要的概 念) • DataWriters/Publishers and DataReaders/Subscribers (清楚的解釋四種 Entities 的關係) • RTI: WaitSet with Status Condition (介紹 Waitset 概念) • PT: Reading and Writing Data (介紹 Waitset 與 Listener 用 法)