SlideShare una empresa de Scribd logo
1 de 30
1ni.com
ni.com
ni.com
Spaghetti and Shared Variables
Jordan McBain, Ph.D., CLA
Dynamic Reactor Pattern for Distributed Systems in Control and Monitoring
4ni.com
Brose North America, Inc.
Mechatronic Systems and Drives forAutomobiles
Structures and components for vehicle seats
Systems for engine cooling,
electric motors and drives
Modules and
components
for vehicle doors
5ni.com
Spaghetti and Shared Variables
• Shared Variables are great for their designed use case, BUT
• Typical usage leads to “Spaghetti and Shared Variables”
• Building a large scale application needs more
o Service Oriented Architectures
o Open Standards (e.g. MIMOSA)
• Object Oriented Design Pattern
• Dynamic “Reactor Pattern” for LabVIEW
• Queue, FIFO, etc. instead of “pointers” to callbacks
• Online subscription to “published variables”
• Dynamic online creation of “published variables”
6ni.com
Shared Variables
NI’s perspective
7ni.com
Design Iterations
• Presented at South-East Michigan User Group Meeting (Dec 2014)
• Very rough sketch
• Deficiencies:
o Strings to help identify published variables
– Inefficient string comparisons
o Static published variable creation/destruction
– Or at least introducing potential for blocking
o Not ready for large scale application
o No consideration given to streaming
• Today’s presentation resolves most of these issues
8ni.com
Object-Oriented Paradigm
The Class
Class – “software module”
◦ A rigid interface specification
◦ Encapsulation
◦ Information Hiding
DataA: uint32
DataB: UserClass
[A,B]=MyFunc1(uint32, bool, dbl)
[E]=MyFunc2(bool, classA)
Class A
“struct”
Or cluster
Acces
Routines
(bunch o’
VI’s)
9ni.com
Object-Oriented Paradigm
Inheritance & Polymorphism
DataA: uint32
DataB: UserClass
Data:bool
Data1: int32
[A,B]=MyFunc1(uint32, bool, dbl)
[E]=MyFunc2(bool, classA)
[A]=MyFunc3(bool, dbl)
[E]=MyFunc4(bool, dbl)
Class D
Data: bool
[A]=MyFunc3(bool, dbl)
Class B
Data1: int32
DataA: uint32
DataB: UserClass
[E]=MyFunc4(bool, dbl)
[A,B]=MyFunc1(uint32, bool, dbl)
[E]=MyFunc2(bool, classA)
Class C
DataA: uint32
DataB: UserClass
[A,B]=MyFunc1(uint32, bool, dbl)
[E]=MyFunc2(bool, classA)
Class A
Multiple
Inheritance
Not Supported
In LabVIEW
10ni.com
Multi-Threaded Environment
Central Error
Handling
Publish:
- Error State
- Error Event
Logging
Publish:
- Logged Channel IDs
- Logging Rate
Channel Manager
Publish:
- Channel IDs
- Available Algorithms
- Available Libraries
BroadcasterProcess A
Publish:
- Process A_1
- Process A_2
Can I log error
events? Please!?
User Interface
Also I’d like to know
about Process A_1
Geez. I’d like to know about
available algorithms
Reuse note: Libraries Publish algorithms
Also, tell me about error
states!
I’d like to tell the Channel
manager to add an algorithm too
Publish:
- Run State
What is the run state?
May I assist
coordination?
11ni.com
Error
Handling
Logging Channel
Manager
Broadcaster Process A
CRIO1
Error
Handling
Logging Channel
Manager
Broadcaster Process B
CRIO2
GUI
Broadcaster
Central
Error
Handling
Central
Logging GUI
Hello, CRIO1
here! Anyone
out there?
Yup! CRIO 2
here!
CRIO1 &CRIO2,
I’m the GUI!
I want to be
everyone’s boss!
No way! We
don’t need
servers.
Let’s just be
peers!
12ni.com
Reactor Pattern
• Application should only block on a single
source of events
• Avoid context switching and synchronization
• Adding new services and published
variables should be easy
• Shield application code from complexity of
multi-threading & synchronization
[POSA2, 1999]
Four forces:
13ni.com
Reactor Pattern
• Synchronously wait on events from multiple sources
• Integrate demultiplexing and dispatching events to processing services
• Decouple event demultiplexing/dispatching from application-specific
processing
[POSA2, 1999]
Solution
14ni.com
Reactor Pattern
• Reactor class allows registration & removal of event handlers
• Reactor waits on a group of operating system mechanisms
• E.g. Files, sockets, etc.
• When OS mechanism triggers Reactor, the Reactor
• Looks up event handlers registered for that event
• Calls the handler’s call back via a “pointer” to the handler
o In LabVIEW a Data Value Reference
• Nice pattern for single threaded applications BUT for parallel apps:
Implementation Limitations
• Race Conditions
• Deadlock
• Non-preemptive
• Debugging
15ni.com
Design Problem
• In a multi-threaded environment,
threads may:
• Have data other threads want
• Want to know data from other
threads
• In a distributed environment, distributed
threads may:
• Have data other distributed threads want
• Want to know data from other distributed
threads
The same problem!
Possibly occurring at the same time!
Reuse Potential!
16ni.com
Problem Abstraction: Design Pattern
Broadcaster
Service
Hi, I am a
service
named
<????>
I will have
variables I want to
publish throughout
my life time
I will want to subscribe and
unsubscribe to other
variables during my life
time
Send me updates about other
variables via this COM scheme
Ok. No Problem. Tell me what
you want to know about via this
COM scheme
Service Service
Network
Broadcaster
Service
Service
Service
Let’s abstract network
(EtherNet, CAN, etc.)
details for our
services
17ni.com
Participants
• Data storage class
• Applications will create new ones to handle individual needs
• Must be registered to an aggregator to be of any use
• When aggregator is registered to broadcaster:
o Services can subscribe to receive information feeds
o Services can request to write to published variables
PublishedVariable
18ni.com
Participants
• Stores (“Aggregates”) Published Variables
• When a variable is updated, transmits to Broadcaster for dispersion
o Only transmits to Broadcaster with active subscriptions
• Service class inherits this
o So it can be both an Aggregator and a subscriber
Published Variable Aggregator
19ni.com
Participants
• Passes data between services depending on registration
• Network and Concurrency Abstraction Layer
Published Variable Broadcaster
Broadcaster
20ni.com
Participants
• Inherits Published Variable Broadcaster
• Interface hides COM scheme (e.g. queue)
• Transmits command objects to actual Broadcaster for processing
• COM Scheme transmits each operation’s parameters to only Broadcaster
• Inversion of control
• Each command object:
o Has a “Receiver” access routine that is friended to Broadcaster
• When Broadcaster receives object:
o Calls this “Receiver” and passes itself to the “Receiver”
o The Receiver calls the appropriate method in Broadcaster to get the work
done
Distributed Published Variable Broadcaster
Broadcaster
21ni.com
Participants
• PV Aggregator
• Hidden inside Broadcaster’s “Run Routine”
• Sends UDP multicast message announcing presence
• Has a published variable acting as a queue for newly discovered IP’s
PV Broadcaster: Multicaster
22ni.com
Participants
• Service (Subscriber + Aggregator)
• Subscribes to Multicaster’s “Discovered IP” PV
• Attempts to setup communication, if successful:
• Publishes this as “Registered IP” PV
o Multicaster subscribed
• Asynchronously launches an aggregator to represent all aggregator’s on
the distributed computer
o Think: Actor Framework
• Design Decision: Polls all “Registered IP’s” via TCP
• Makes local subscriptions for “Registered IP’s” and transmit via TCP
PV Broadcaster: Network Facade
23ni.com
Participants
• Abstracts the communication transmission/reception mechanism
• Choice of actual mechanism initialized on “Init()”
• Otherwise interface between child classes is the same
• Options
• User Events
• Queues
• FIFO’s
• Actor Framework “Queues”?
COM Scheme
24ni.com
Participants
• Objective for threads to block only on one source
o Must generalize the data type transmitted via communication scheme
• Child classes
o Broadcaster Configuration Settings
– Published Variables
o Aggregator Configuration Settings
• Configuration Settings
o Permits registration/deregistration of services and published variables
– Via communication scheme hidden behind interface
COM Element
25ni.com
26ni.com
Inversion of Control
• “The Hollywood Principle”
• Don’t Call Us, We Will Call You
• Like the Actor Framework
• Opportunity to use “Friends” and “Community Scope” in LabVIEW
• Communication Elements have method for Broadcaster & Aggregator
• Once called, they choose appropriate Method in Broadcaster/Aggregator
• Avoid if/thens and avoid BAD code:
27ni.com
Re-Use Potential
• Reuse between projects
• Reuse within the same project
• Example: Recursive use of “Aggregator Concept”
• Make “Channel Manager” an aggregator
o Channels in channel manager are also aggregators
o Channel manager runs in single thread of excecution
o Change messaging scheme to array based scheme
28ni.com
Future
• Message priorities
• Urgent messages
• Bit masked numeric id for VarID
• Aggr Details: Allow recursive AggrID
• Integration with Actor Framework
• Other Network Types
• CANopen, EtherCAT, etc.
• Streaming
Bit 0Bit NBit N+m
VarIDAggr IDBroadCasterID Aggr Details
Bit N+m+o
29ni.com
Conclusions
30ni.com

Más contenido relacionado

Destacado

Award winning Sales Pitch
Award winning Sales PitchAward winning Sales Pitch
Award winning Sales Pitch
Akin Akinboyewa
 
Erik Ohlsson_Thesis_Lund University
Erik Ohlsson_Thesis_Lund UniversityErik Ohlsson_Thesis_Lund University
Erik Ohlsson_Thesis_Lund University
Erik Ohlsson
 
Resume_Certificates
Resume_CertificatesResume_Certificates
Resume_Certificates
Damian Lyons
 
Môj psík-Dianka
Môj psík-DiankaMôj psík-Dianka
Môj psík-Dianka
irenkolcak
 
Tupac presentation
Tupac presentationTupac presentation
Tupac presentation
Royce Rowan
 

Destacado (16)

Инструменты развития личностного потенциала персонала компании
Инструменты развития личностного потенциала персонала компанииИнструменты развития личностного потенциала персонала компании
Инструменты развития личностного потенциала персонала компании
 
Award winning Sales Pitch
Award winning Sales PitchAward winning Sales Pitch
Award winning Sales Pitch
 
Erik Ohlsson_Thesis_Lund University
Erik Ohlsson_Thesis_Lund UniversityErik Ohlsson_Thesis_Lund University
Erik Ohlsson_Thesis_Lund University
 
S J Pieterse CV 2016
S J Pieterse CV 2016S J Pieterse CV 2016
S J Pieterse CV 2016
 
An Unexpected Way to Grow Your Brand's Awareness
An Unexpected Way to Grow Your Brand's AwarenessAn Unexpected Way to Grow Your Brand's Awareness
An Unexpected Way to Grow Your Brand's Awareness
 
ARTICULO_sin trazar
ARTICULO_sin trazarARTICULO_sin trazar
ARTICULO_sin trazar
 
Resume_Certificates
Resume_CertificatesResume_Certificates
Resume_Certificates
 
SusanAustinResume
SusanAustinResumeSusanAustinResume
SusanAustinResume
 
Môj psík-Dianka
Môj psík-DiankaMôj psík-Dianka
Môj psík-Dianka
 
Shell button catalogue
Shell button catalogueShell button catalogue
Shell button catalogue
 
Shipping container homes Benefits
Shipping container homes Benefits Shipping container homes Benefits
Shipping container homes Benefits
 
TechSaints International Pvt. Ltd. - Technology Company Presentation.
TechSaints International Pvt. Ltd. - Technology Company Presentation.TechSaints International Pvt. Ltd. - Technology Company Presentation.
TechSaints International Pvt. Ltd. - Technology Company Presentation.
 
How to Boost Revenue with a More Strategic Sales Compensation Plan
How to Boost Revenue with a More Strategic Sales Compensation PlanHow to Boost Revenue with a More Strategic Sales Compensation Plan
How to Boost Revenue with a More Strategic Sales Compensation Plan
 
Tupac presentation
Tupac presentationTupac presentation
Tupac presentation
 
3.1. wout baert
3.1. wout baert3.1. wout baert
3.1. wout baert
 
PayLeap _ PROcillo 1
PayLeap _ PROcillo 1PayLeap _ PROcillo 1
PayLeap _ PROcillo 1
 

Similar a Dynamic Reactor Pattern for Distributed Systems in Control and Monitoring

Foundational Design Patterns for Multi-Purpose Applications
Foundational Design Patterns for Multi-Purpose ApplicationsFoundational Design Patterns for Multi-Purpose Applications
Foundational Design Patterns for Multi-Purpose Applications
Ching-Hwa Yu
 
Managing infrastructure with Application Policy by Mike Cohen
Managing infrastructure with Application Policy by Mike CohenManaging infrastructure with Application Policy by Mike Cohen
Managing infrastructure with Application Policy by Mike Cohen
buildacloud
 
Crafting Consumable APIs
Crafting Consumable APIsCrafting Consumable APIs
Crafting Consumable APIs
WSO2
 

Similar a Dynamic Reactor Pattern for Distributed Systems in Control and Monitoring (20)

Foundational Design Patterns for Multi-Purpose Applications
Foundational Design Patterns for Multi-Purpose ApplicationsFoundational Design Patterns for Multi-Purpose Applications
Foundational Design Patterns for Multi-Purpose Applications
 
Adding Real-time Features to PHP Applications
Adding Real-time Features to PHP ApplicationsAdding Real-time Features to PHP Applications
Adding Real-time Features to PHP Applications
 
HPC Controls Future
HPC Controls FutureHPC Controls Future
HPC Controls Future
 
Small Cells Service
Small Cells ServiceSmall Cells Service
Small Cells Service
 
Open access network
Open access networkOpen access network
Open access network
 
Managing infrastructure with Application Policy by Mike Cohen
Managing infrastructure with Application Policy by Mike CohenManaging infrastructure with Application Policy by Mike Cohen
Managing infrastructure with Application Policy by Mike Cohen
 
Colt inter-provider SDN NNIs and APIs
Colt inter-provider SDN NNIs and APIsColt inter-provider SDN NNIs and APIs
Colt inter-provider SDN NNIs and APIs
 
Realtime Applications with Laravel - LaravelLive India Online Meetup Jun 2020
Realtime Applications with Laravel - LaravelLive India Online Meetup Jun 2020Realtime Applications with Laravel - LaravelLive India Online Meetup Jun 2020
Realtime Applications with Laravel - LaravelLive India Online Meetup Jun 2020
 
Microservices.pdf
Microservices.pdfMicroservices.pdf
Microservices.pdf
 
API310 - How to refactor a monolith to serverless in 8 steps
API310 - How to refactor a monolith to serverless in 8 stepsAPI310 - How to refactor a monolith to serverless in 8 steps
API310 - How to refactor a monolith to serverless in 8 steps
 
Dubbo and Weidian's practice on micro-service architecture
Dubbo and Weidian's practice on micro-service architectureDubbo and Weidian's practice on micro-service architecture
Dubbo and Weidian's practice on micro-service architecture
 
OpenDaylight Update (June 2018)
OpenDaylight Update (June 2018)OpenDaylight Update (June 2018)
OpenDaylight Update (June 2018)
 
Crafting Consumable APIs
Crafting Consumable APIsCrafting Consumable APIs
Crafting Consumable APIs
 
QCon 2015 - Microservices Track Notes
QCon 2015 - Microservices Track Notes QCon 2015 - Microservices Track Notes
QCon 2015 - Microservices Track Notes
 
Istio Triangle Kubernetes Meetup Aug 2019
Istio Triangle Kubernetes Meetup Aug 2019Istio Triangle Kubernetes Meetup Aug 2019
Istio Triangle Kubernetes Meetup Aug 2019
 
Kubernetes on the Edge / 在邊緣的K8S
Kubernetes on the Edge / 在邊緣的K8SKubernetes on the Edge / 在邊緣的K8S
Kubernetes on the Edge / 在邊緣的K8S
 
Cloud Foundry Technical Overview at IBM Interconnect 2016
Cloud Foundry Technical Overview at IBM Interconnect 2016Cloud Foundry Technical Overview at IBM Interconnect 2016
Cloud Foundry Technical Overview at IBM Interconnect 2016
 
Incremental Queries and Transformations for Engineering Critical Systems
Incremental Queries and Transformations for Engineering Critical SystemsIncremental Queries and Transformations for Engineering Critical Systems
Incremental Queries and Transformations for Engineering Critical Systems
 
1200 wsrr & iib - advanced integration - final
1200   wsrr & iib - advanced integration - final1200   wsrr & iib - advanced integration - final
1200 wsrr & iib - advanced integration - final
 
Patterns of Distributed Application Design
Patterns of Distributed Application DesignPatterns of Distributed Application Design
Patterns of Distributed Application Design
 

Más de Jordan McBain (7)

Object oriented design patterns for distributed systems
Object oriented design patterns for distributed systemsObject oriented design patterns for distributed systems
Object oriented design patterns for distributed systems
 
Condition Monitoring of Variable Speed Machinery
Condition Monitoring of Variable Speed MachineryCondition Monitoring of Variable Speed Machinery
Condition Monitoring of Variable Speed Machinery
 
Principal Component Analysis For Novelty Detection
Principal Component Analysis For Novelty DetectionPrincipal Component Analysis For Novelty Detection
Principal Component Analysis For Novelty Detection
 
Software Architecture For Condition Monitoring Of Mobile Underground
Software Architecture For Condition Monitoring Of Mobile UndergroundSoftware Architecture For Condition Monitoring Of Mobile Underground
Software Architecture For Condition Monitoring Of Mobile Underground
 
Condition Monitoring Of Unsteadily Operating Equipment
Condition Monitoring Of Unsteadily Operating EquipmentCondition Monitoring Of Unsteadily Operating Equipment
Condition Monitoring Of Unsteadily Operating Equipment
 
CBM Variable Speed Machinery
CBM Variable Speed MachineryCBM Variable Speed Machinery
CBM Variable Speed Machinery
 
Condition Monitoring of Variable State Machinery
Condition Monitoring of Variable State MachineryCondition Monitoring of Variable State Machinery
Condition Monitoring of Variable State Machinery
 

Último

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Dynamic Reactor Pattern for Distributed Systems in Control and Monitoring

  • 3. ni.com Spaghetti and Shared Variables Jordan McBain, Ph.D., CLA Dynamic Reactor Pattern for Distributed Systems in Control and Monitoring
  • 4. 4ni.com Brose North America, Inc. Mechatronic Systems and Drives forAutomobiles Structures and components for vehicle seats Systems for engine cooling, electric motors and drives Modules and components for vehicle doors
  • 5. 5ni.com Spaghetti and Shared Variables • Shared Variables are great for their designed use case, BUT • Typical usage leads to “Spaghetti and Shared Variables” • Building a large scale application needs more o Service Oriented Architectures o Open Standards (e.g. MIMOSA) • Object Oriented Design Pattern • Dynamic “Reactor Pattern” for LabVIEW • Queue, FIFO, etc. instead of “pointers” to callbacks • Online subscription to “published variables” • Dynamic online creation of “published variables”
  • 7. 7ni.com Design Iterations • Presented at South-East Michigan User Group Meeting (Dec 2014) • Very rough sketch • Deficiencies: o Strings to help identify published variables – Inefficient string comparisons o Static published variable creation/destruction – Or at least introducing potential for blocking o Not ready for large scale application o No consideration given to streaming • Today’s presentation resolves most of these issues
  • 8. 8ni.com Object-Oriented Paradigm The Class Class – “software module” ◦ A rigid interface specification ◦ Encapsulation ◦ Information Hiding DataA: uint32 DataB: UserClass [A,B]=MyFunc1(uint32, bool, dbl) [E]=MyFunc2(bool, classA) Class A “struct” Or cluster Acces Routines (bunch o’ VI’s)
  • 9. 9ni.com Object-Oriented Paradigm Inheritance & Polymorphism DataA: uint32 DataB: UserClass Data:bool Data1: int32 [A,B]=MyFunc1(uint32, bool, dbl) [E]=MyFunc2(bool, classA) [A]=MyFunc3(bool, dbl) [E]=MyFunc4(bool, dbl) Class D Data: bool [A]=MyFunc3(bool, dbl) Class B Data1: int32 DataA: uint32 DataB: UserClass [E]=MyFunc4(bool, dbl) [A,B]=MyFunc1(uint32, bool, dbl) [E]=MyFunc2(bool, classA) Class C DataA: uint32 DataB: UserClass [A,B]=MyFunc1(uint32, bool, dbl) [E]=MyFunc2(bool, classA) Class A Multiple Inheritance Not Supported In LabVIEW
  • 10. 10ni.com Multi-Threaded Environment Central Error Handling Publish: - Error State - Error Event Logging Publish: - Logged Channel IDs - Logging Rate Channel Manager Publish: - Channel IDs - Available Algorithms - Available Libraries BroadcasterProcess A Publish: - Process A_1 - Process A_2 Can I log error events? Please!? User Interface Also I’d like to know about Process A_1 Geez. I’d like to know about available algorithms Reuse note: Libraries Publish algorithms Also, tell me about error states! I’d like to tell the Channel manager to add an algorithm too Publish: - Run State What is the run state? May I assist coordination?
  • 11. 11ni.com Error Handling Logging Channel Manager Broadcaster Process A CRIO1 Error Handling Logging Channel Manager Broadcaster Process B CRIO2 GUI Broadcaster Central Error Handling Central Logging GUI Hello, CRIO1 here! Anyone out there? Yup! CRIO 2 here! CRIO1 &CRIO2, I’m the GUI! I want to be everyone’s boss! No way! We don’t need servers. Let’s just be peers!
  • 12. 12ni.com Reactor Pattern • Application should only block on a single source of events • Avoid context switching and synchronization • Adding new services and published variables should be easy • Shield application code from complexity of multi-threading & synchronization [POSA2, 1999] Four forces:
  • 13. 13ni.com Reactor Pattern • Synchronously wait on events from multiple sources • Integrate demultiplexing and dispatching events to processing services • Decouple event demultiplexing/dispatching from application-specific processing [POSA2, 1999] Solution
  • 14. 14ni.com Reactor Pattern • Reactor class allows registration & removal of event handlers • Reactor waits on a group of operating system mechanisms • E.g. Files, sockets, etc. • When OS mechanism triggers Reactor, the Reactor • Looks up event handlers registered for that event • Calls the handler’s call back via a “pointer” to the handler o In LabVIEW a Data Value Reference • Nice pattern for single threaded applications BUT for parallel apps: Implementation Limitations • Race Conditions • Deadlock • Non-preemptive • Debugging
  • 15. 15ni.com Design Problem • In a multi-threaded environment, threads may: • Have data other threads want • Want to know data from other threads • In a distributed environment, distributed threads may: • Have data other distributed threads want • Want to know data from other distributed threads The same problem! Possibly occurring at the same time! Reuse Potential!
  • 16. 16ni.com Problem Abstraction: Design Pattern Broadcaster Service Hi, I am a service named <????> I will have variables I want to publish throughout my life time I will want to subscribe and unsubscribe to other variables during my life time Send me updates about other variables via this COM scheme Ok. No Problem. Tell me what you want to know about via this COM scheme Service Service Network Broadcaster Service Service Service Let’s abstract network (EtherNet, CAN, etc.) details for our services
  • 17. 17ni.com Participants • Data storage class • Applications will create new ones to handle individual needs • Must be registered to an aggregator to be of any use • When aggregator is registered to broadcaster: o Services can subscribe to receive information feeds o Services can request to write to published variables PublishedVariable
  • 18. 18ni.com Participants • Stores (“Aggregates”) Published Variables • When a variable is updated, transmits to Broadcaster for dispersion o Only transmits to Broadcaster with active subscriptions • Service class inherits this o So it can be both an Aggregator and a subscriber Published Variable Aggregator
  • 19. 19ni.com Participants • Passes data between services depending on registration • Network and Concurrency Abstraction Layer Published Variable Broadcaster Broadcaster
  • 20. 20ni.com Participants • Inherits Published Variable Broadcaster • Interface hides COM scheme (e.g. queue) • Transmits command objects to actual Broadcaster for processing • COM Scheme transmits each operation’s parameters to only Broadcaster • Inversion of control • Each command object: o Has a “Receiver” access routine that is friended to Broadcaster • When Broadcaster receives object: o Calls this “Receiver” and passes itself to the “Receiver” o The Receiver calls the appropriate method in Broadcaster to get the work done Distributed Published Variable Broadcaster Broadcaster
  • 21. 21ni.com Participants • PV Aggregator • Hidden inside Broadcaster’s “Run Routine” • Sends UDP multicast message announcing presence • Has a published variable acting as a queue for newly discovered IP’s PV Broadcaster: Multicaster
  • 22. 22ni.com Participants • Service (Subscriber + Aggregator) • Subscribes to Multicaster’s “Discovered IP” PV • Attempts to setup communication, if successful: • Publishes this as “Registered IP” PV o Multicaster subscribed • Asynchronously launches an aggregator to represent all aggregator’s on the distributed computer o Think: Actor Framework • Design Decision: Polls all “Registered IP’s” via TCP • Makes local subscriptions for “Registered IP’s” and transmit via TCP PV Broadcaster: Network Facade
  • 23. 23ni.com Participants • Abstracts the communication transmission/reception mechanism • Choice of actual mechanism initialized on “Init()” • Otherwise interface between child classes is the same • Options • User Events • Queues • FIFO’s • Actor Framework “Queues”? COM Scheme
  • 24. 24ni.com Participants • Objective for threads to block only on one source o Must generalize the data type transmitted via communication scheme • Child classes o Broadcaster Configuration Settings – Published Variables o Aggregator Configuration Settings • Configuration Settings o Permits registration/deregistration of services and published variables – Via communication scheme hidden behind interface COM Element
  • 26. 26ni.com Inversion of Control • “The Hollywood Principle” • Don’t Call Us, We Will Call You • Like the Actor Framework • Opportunity to use “Friends” and “Community Scope” in LabVIEW • Communication Elements have method for Broadcaster & Aggregator • Once called, they choose appropriate Method in Broadcaster/Aggregator • Avoid if/thens and avoid BAD code:
  • 27. 27ni.com Re-Use Potential • Reuse between projects • Reuse within the same project • Example: Recursive use of “Aggregator Concept” • Make “Channel Manager” an aggregator o Channels in channel manager are also aggregators o Channel manager runs in single thread of excecution o Change messaging scheme to array based scheme
  • 28. 28ni.com Future • Message priorities • Urgent messages • Bit masked numeric id for VarID • Aggr Details: Allow recursive AggrID • Integration with Actor Framework • Other Network Types • CANopen, EtherCAT, etc. • Streaming Bit 0Bit NBit N+m VarIDAggr IDBroadCasterID Aggr Details Bit N+m+o

Notas del editor

  1. 4