SlideShare a Scribd company logo
Flow-based programming
In Golang
25 April 2017
Thuc Le
Software Engineer
De nition
Flow-based Programing is a programing paradigm that de nes applications as networks of
black box processes which exchange data across prede ned connections by message
passing, where connections are speci ed externally to the processes.
- Paul Morrison
Core concepts
Process
The process is black box
The box doesn't care the outside world
Ports
Way the processes communicate with outside world
A process can have one or many inputs/outputs ports
The "black box" process looks like data factory
Connection
The connection is de ned externally to the processes
The blackbox processes can be reuse in other application by re-conected without any
changes.
The connections work as streams of structured data chunks, called information packages
(IPs)
Other notes:
More than one process can execute the same piece of code
Processes work asynchronously
Bene ts:
Improve the work ow visualization
When develop the process, we focus on components development. It's easier for coding
and testing.
When develop the network, we focus on application's ow.
FBP applications generally run in less elapsed time than conventional programs
Drawback
Complex the simple logic
Take time of CPU to setup of the network of processes before running
Go ow
Go ow
A library of golang to implement the Flow-based programming model.
https://github.com/trustmaster/go ow
Try with simple application:
Go ow - De ne processes
9 // START GREETING
10
11 type Greeter struct {
12 flow.Component
13 Name <-chan string // input port
14 Res chan<- string // output port
15
16 counter int
17 }
18
19 func (g *Greeter) OnName(name string) {
20 counter = counter + 1
21 greeting := fmt.Sprintf("Hello, %s!", name)
22 g.Res <- greeting //send the greeting to the output port/
23 }
24
25 // END GREETING
Go ow - De ne processes
27 // START PRINTER
28
29 type Printer struct {
30 flow.Component
31 Line <-chan string // inport
32 }
33
34 func (p *Printer) OnLine(line string) {
35 fmt.Println(line)
36 }
37
38 // END PRINTER
Go ow - Networking
40 // START NETWORKING
41
42 type GreetingApp struct {
43 flow.Graph
44 }
45
46 func NewGreetingApp() *GreetingApp {
47 // Init application
48 n := new(GreetingApp)
49 n.InitGraphState()
50
51 // Add processes into application
52 n.Add(new(Greeter), "greeter")
53 n.Add(new(Printer), "printer")
54
55 // Create the connection
56 n.Connect("greeter", "Res111", "printer", "Line")
57
58 // Create the Application port
59 n.MapInPort("In", "greeter", "Name")
60 return n
61 }
62
63 // END NETWORKING
Go ow - Run
69 // START RUN
70
71 func main() {
72 // Create the application
73 net := NewGreetingApp()
74
75 // Open the application port `In`
76 in := make(chan string)
77 net.SetInPort("In", in)
78 defer close(in)
79
80 // Run the application and push the name
81 flow.RunNet(net)
82 in <- "Thuc Le"
83 in <- "Lazada"
84
85 // Wait until the app has done its job
86 <-net.Wait()
87 }
88
89 // END RUN
Go ow - Benchmark
Run normally: 1.8-1.9 seconds
Run go ow: 1.5-1.7 seconds
Go ow - Concurrency model
Go ow 3 di erent concurrency models at process level
- Asynchronous
- Synchronous
- Pool of workers
greeter := new(Greeter)
// Sync mode
greeter.Component.Mode = flow.ComponentModeAsync
// Sync mode
greeter.Component.Mode = flow.ComponentModeSync
// Pool of workers mode
greeter.Component.Mode = flow.ComponentModePool
greeter.Component.PoolSize = 8 // 8 workers in the crew
Go ow - State lock
Support built-in lock in process
type StateExample struct {
flow.Component
In1 <-chan string
// lock
StateLock *sync.Mutex
// state
counter int
buffer [32]string
}
func (p *StateExample) OnIn2(item String) {
// We can safely modify fields here
p.buffer = append(item, s)
p.counter++
}
Go ow - Types of port
Go ow supports 3 types of ports: Input port, output port bi-direction port
type PortExample struct {
flow.Component
Foo <-chan int // receive-only inport
Bar chan<- int // send-only outport
Boo chan string // can be inport or outport
}
Support method raise when a connection is closed
func (p *Printer) OnLine(line string) {
fmt.Println(line)
}
func (c *ComponentType) OnLineClose() {
// Clean something
}
Thank you
Thuc Le
Software Engineer
ledongthuc@gmail.com(mailto:ledongthuc@gmail.com)
Flow based programming in golang

More Related Content

What's hot

Continuous performance: Load testing for developers with gatling @ JavaOne 2016
Continuous performance: Load testing for developers with gatling @ JavaOne 2016Continuous performance: Load testing for developers with gatling @ JavaOne 2016
Continuous performance: Load testing for developers with gatling @ JavaOne 2016
Tim van Eijndhoven
 
QA Fes 2016. Jacek Okrojek. Website performance from user perspective
QA Fes 2016. Jacek Okrojek. Website performance from user perspectiveQA Fes 2016. Jacek Okrojek. Website performance from user perspective
QA Fes 2016. Jacek Okrojek. Website performance from user perspective
QAFest
 
Igor Bondarenko - Process organization of the development modules specific to...
Igor Bondarenko - Process organization of the development modules specific to...Igor Bondarenko - Process organization of the development modules specific to...
Igor Bondarenko - Process organization of the development modules specific to...
Meet Magento Italy
 
Continuous performance: Load testing for developers with gatling
Continuous performance: Load testing for developers with gatlingContinuous performance: Load testing for developers with gatling
Continuous performance: Load testing for developers with gatling
Tim van Eijndhoven
 
140 releases per month
140 releases per month140 releases per month
140 releases per month
Manuel Vacelet
 
What does it take to be a performance tester?
What does it take to be a performance tester?What does it take to be a performance tester?
What does it take to be a performance tester?
SQALab
 
Bag it Tag It Put it : Project Tracking One Click away
Bag it Tag It Put it : Project Tracking One Click away Bag it Tag It Put it : Project Tracking One Click away
Bag it Tag It Put it : Project Tracking One Click away
Abhishek Bakshi
 
Metrics
MetricsMetrics
Metrics
Zach Cox
 
Overview of Gitlab usage
Overview of Gitlab usageOverview of Gitlab usage
Overview of Gitlab usage
OluDouglas
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
ikram_ahamed
 
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
Agile Testing Alliance
 
AutoDevBot API Monitoring
AutoDevBot API MonitoringAutoDevBot API Monitoring
AutoDevBot API Monitoring
Garland Kan
 
Blugento cloud foundry - components - principles
Blugento cloud foundry - components - principlesBlugento cloud foundry - components - principles
Blugento cloud foundry - components - principles
Thomas Fleck
 
ATAGTR2017 Performance Automation in Dev-Ops
ATAGTR2017 Performance Automation in Dev-OpsATAGTR2017 Performance Automation in Dev-Ops
ATAGTR2017 Performance Automation in Dev-Ops
Agile Testing Alliance
 
Black Tea Testing #2 - Performance testing: why? when? how?
Black Tea Testing #2 - Performance testing: why? when? how?Black Tea Testing #2 - Performance testing: why? when? how?
Black Tea Testing #2 - Performance testing: why? when? how?
Antonina_Burlachenko
 
Advantages of Rails Framework
Advantages of Rails FrameworkAdvantages of Rails Framework
Advantages of Rails Framework
Sathish Mariappan
 
Akka Persistence
Akka PersistenceAkka Persistence
Akka Persistence
Knoldus Inc.
 
TuleapCon 2019. DevOps in Tuleap
TuleapCon 2019. DevOps in TuleapTuleapCon 2019. DevOps in Tuleap
TuleapCon 2019. DevOps in Tuleap
Tuleap
 
Introduction to K6
Introduction to K6Introduction to K6
Introduction to K6
Knoldus Inc.
 

What's hot (20)

Continuous performance: Load testing for developers with gatling @ JavaOne 2016
Continuous performance: Load testing for developers with gatling @ JavaOne 2016Continuous performance: Load testing for developers with gatling @ JavaOne 2016
Continuous performance: Load testing for developers with gatling @ JavaOne 2016
 
QA Fes 2016. Jacek Okrojek. Website performance from user perspective
QA Fes 2016. Jacek Okrojek. Website performance from user perspectiveQA Fes 2016. Jacek Okrojek. Website performance from user perspective
QA Fes 2016. Jacek Okrojek. Website performance from user perspective
 
Igor Bondarenko - Process organization of the development modules specific to...
Igor Bondarenko - Process organization of the development modules specific to...Igor Bondarenko - Process organization of the development modules specific to...
Igor Bondarenko - Process organization of the development modules specific to...
 
Continuous performance: Load testing for developers with gatling
Continuous performance: Load testing for developers with gatlingContinuous performance: Load testing for developers with gatling
Continuous performance: Load testing for developers with gatling
 
1.qtp basics
1.qtp basics1.qtp basics
1.qtp basics
 
140 releases per month
140 releases per month140 releases per month
140 releases per month
 
What does it take to be a performance tester?
What does it take to be a performance tester?What does it take to be a performance tester?
What does it take to be a performance tester?
 
Bag it Tag It Put it : Project Tracking One Click away
Bag it Tag It Put it : Project Tracking One Click away Bag it Tag It Put it : Project Tracking One Click away
Bag it Tag It Put it : Project Tracking One Click away
 
Metrics
MetricsMetrics
Metrics
 
Overview of Gitlab usage
Overview of Gitlab usageOverview of Gitlab usage
Overview of Gitlab usage
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
 
AutoDevBot API Monitoring
AutoDevBot API MonitoringAutoDevBot API Monitoring
AutoDevBot API Monitoring
 
Blugento cloud foundry - components - principles
Blugento cloud foundry - components - principlesBlugento cloud foundry - components - principles
Blugento cloud foundry - components - principles
 
ATAGTR2017 Performance Automation in Dev-Ops
ATAGTR2017 Performance Automation in Dev-OpsATAGTR2017 Performance Automation in Dev-Ops
ATAGTR2017 Performance Automation in Dev-Ops
 
Black Tea Testing #2 - Performance testing: why? when? how?
Black Tea Testing #2 - Performance testing: why? when? how?Black Tea Testing #2 - Performance testing: why? when? how?
Black Tea Testing #2 - Performance testing: why? when? how?
 
Advantages of Rails Framework
Advantages of Rails FrameworkAdvantages of Rails Framework
Advantages of Rails Framework
 
Akka Persistence
Akka PersistenceAkka Persistence
Akka Persistence
 
TuleapCon 2019. DevOps in Tuleap
TuleapCon 2019. DevOps in TuleapTuleapCon 2019. DevOps in Tuleap
TuleapCon 2019. DevOps in Tuleap
 
Introduction to K6
Introduction to K6Introduction to K6
Introduction to K6
 

Similar to Flow based programming in golang

Continuous Application with Structured Streaming 2.0
Continuous Application with Structured Streaming 2.0Continuous Application with Structured Streaming 2.0
Continuous Application with Structured Streaming 2.0
Anyscale
 
Inter Task Communication On Volatile Nodes
Inter Task Communication On Volatile NodesInter Task Communication On Volatile Nodes
Inter Task Communication On Volatile Nodes
nagarajan_ka
 
Os2 2
Os2 2Os2 2
Os2 2issbp
 
Os lab final
Os lab finalOs lab final
Os lab final
LakshmiSarvani6
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104swena_gupta
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104swena_gupta
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104swena_gupta
 
3 processes
3 processes3 processes
3 processes
BaliThorat1
 
Unit II - 1 - Operating System Process
Unit II - 1 - Operating System ProcessUnit II - 1 - Operating System Process
Unit II - 1 - Operating System Process
cscarcas
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
csomab4u
 
Lecture_Process.ppt
Lecture_Process.pptLecture_Process.ppt
Lecture_Process.ppt
RahulKumarYadav87
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
Sami Mughal
 
ch3 s ppt
ch3 s                                  pptch3 s                                  ppt
ch3 s ppt
DhruvilSTATUS
 
cs8493 - operating systems unit 2
cs8493 - operating systems unit 2cs8493 - operating systems unit 2
cs8493 - operating systems unit 2
SIMONTHOMAS S
 
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
SanjeevKumarSinha13
 
Processes
ProcessesProcesses
Processes
K Gowsic Gowsic
 
Operating System
Operating SystemOperating System
Operating System
Indhu Periys
 
process management.ppt
process management.pptprocess management.ppt
process management.ppt
ShubhamGoel184057
 

Similar to Flow based programming in golang (20)

Continuous Application with Structured Streaming 2.0
Continuous Application with Structured Streaming 2.0Continuous Application with Structured Streaming 2.0
Continuous Application with Structured Streaming 2.0
 
Inter Task Communication On Volatile Nodes
Inter Task Communication On Volatile NodesInter Task Communication On Volatile Nodes
Inter Task Communication On Volatile Nodes
 
Os2 2
Os2 2Os2 2
Os2 2
 
Os lab final
Os lab finalOs lab final
Os lab final
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104
 
3 processes
3 processes3 processes
3 processes
 
Unit II - 1 - Operating System Process
Unit II - 1 - Operating System ProcessUnit II - 1 - Operating System Process
Unit II - 1 - Operating System Process
 
ch3 (1).ppt
ch3 (1).pptch3 (1).ppt
ch3 (1).ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Lecture_Process.ppt
Lecture_Process.pptLecture_Process.ppt
Lecture_Process.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3 s ppt
ch3 s                                  pptch3 s                                  ppt
ch3 s ppt
 
cs8493 - operating systems unit 2
cs8493 - operating systems unit 2cs8493 - operating systems unit 2
cs8493 - operating systems unit 2
 
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
 
Processes
ProcessesProcesses
Processes
 
Operating System
Operating SystemOperating System
Operating System
 
process management.ppt
process management.pptprocess management.ppt
process management.ppt
 

More from Anton Stepanenko

Seamy side of autotests
Seamy side of autotestsSeamy side of autotests
Seamy side of autotests
Anton Stepanenko
 
Functional monitoring
Functional monitoringFunctional monitoring
Functional monitoring
Anton Stepanenko
 
Speeding up UI tests, profiling of UI tests
Speeding up UI tests, profiling of UI testsSpeeding up UI tests, profiling of UI tests
Speeding up UI tests, profiling of UI tests
Anton Stepanenko
 
Hand helper for manual testing
Hand helper for manual testingHand helper for manual testing
Hand helper for manual testing
Anton Stepanenko
 
Нагрузочное тестирование по-живому
Нагрузочное тестирование по-живомуНагрузочное тестирование по-живому
Нагрузочное тестирование по-живому
Anton Stepanenko
 
GO Monitoring at lazada
GO Monitoring at lazadaGO Monitoring at lazada
GO Monitoring at lazada
Anton Stepanenko
 

More from Anton Stepanenko (6)

Seamy side of autotests
Seamy side of autotestsSeamy side of autotests
Seamy side of autotests
 
Functional monitoring
Functional monitoringFunctional monitoring
Functional monitoring
 
Speeding up UI tests, profiling of UI tests
Speeding up UI tests, profiling of UI testsSpeeding up UI tests, profiling of UI tests
Speeding up UI tests, profiling of UI tests
 
Hand helper for manual testing
Hand helper for manual testingHand helper for manual testing
Hand helper for manual testing
 
Нагрузочное тестирование по-живому
Нагрузочное тестирование по-живомуНагрузочное тестирование по-живому
Нагрузочное тестирование по-живому
 
GO Monitoring at lazada
GO Monitoring at lazadaGO Monitoring at lazada
GO Monitoring at lazada
 

Recently uploaded

Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 

Recently uploaded (20)

Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 

Flow based programming in golang

  • 1. Flow-based programming In Golang 25 April 2017 Thuc Le Software Engineer
  • 2. De nition Flow-based Programing is a programing paradigm that de nes applications as networks of black box processes which exchange data across prede ned connections by message passing, where connections are speci ed externally to the processes. - Paul Morrison
  • 4. Process The process is black box The box doesn't care the outside world
  • 5. Ports Way the processes communicate with outside world A process can have one or many inputs/outputs ports The "black box" process looks like data factory
  • 6. Connection The connection is de ned externally to the processes The blackbox processes can be reuse in other application by re-conected without any changes. The connections work as streams of structured data chunks, called information packages (IPs)
  • 7. Other notes: More than one process can execute the same piece of code Processes work asynchronously
  • 8. Bene ts: Improve the work ow visualization When develop the process, we focus on components development. It's easier for coding and testing. When develop the network, we focus on application's ow. FBP applications generally run in less elapsed time than conventional programs
  • 9. Drawback Complex the simple logic Take time of CPU to setup of the network of processes before running
  • 10. Go ow
  • 11. Go ow A library of golang to implement the Flow-based programming model. https://github.com/trustmaster/go ow Try with simple application:
  • 12. Go ow - De ne processes 9 // START GREETING 10 11 type Greeter struct { 12 flow.Component 13 Name <-chan string // input port 14 Res chan<- string // output port 15 16 counter int 17 } 18 19 func (g *Greeter) OnName(name string) { 20 counter = counter + 1 21 greeting := fmt.Sprintf("Hello, %s!", name) 22 g.Res <- greeting //send the greeting to the output port/ 23 } 24 25 // END GREETING
  • 13. Go ow - De ne processes 27 // START PRINTER 28 29 type Printer struct { 30 flow.Component 31 Line <-chan string // inport 32 } 33 34 func (p *Printer) OnLine(line string) { 35 fmt.Println(line) 36 } 37 38 // END PRINTER
  • 14. Go ow - Networking 40 // START NETWORKING 41 42 type GreetingApp struct { 43 flow.Graph 44 } 45 46 func NewGreetingApp() *GreetingApp { 47 // Init application 48 n := new(GreetingApp) 49 n.InitGraphState() 50 51 // Add processes into application 52 n.Add(new(Greeter), "greeter") 53 n.Add(new(Printer), "printer") 54 55 // Create the connection 56 n.Connect("greeter", "Res111", "printer", "Line") 57 58 // Create the Application port 59 n.MapInPort("In", "greeter", "Name") 60 return n 61 } 62 63 // END NETWORKING
  • 15. Go ow - Run 69 // START RUN 70 71 func main() { 72 // Create the application 73 net := NewGreetingApp() 74 75 // Open the application port `In` 76 in := make(chan string) 77 net.SetInPort("In", in) 78 defer close(in) 79 80 // Run the application and push the name 81 flow.RunNet(net) 82 in <- "Thuc Le" 83 in <- "Lazada" 84 85 // Wait until the app has done its job 86 <-net.Wait() 87 } 88 89 // END RUN
  • 16. Go ow - Benchmark Run normally: 1.8-1.9 seconds Run go ow: 1.5-1.7 seconds
  • 17. Go ow - Concurrency model Go ow 3 di erent concurrency models at process level - Asynchronous - Synchronous - Pool of workers greeter := new(Greeter) // Sync mode greeter.Component.Mode = flow.ComponentModeAsync // Sync mode greeter.Component.Mode = flow.ComponentModeSync // Pool of workers mode greeter.Component.Mode = flow.ComponentModePool greeter.Component.PoolSize = 8 // 8 workers in the crew
  • 18. Go ow - State lock Support built-in lock in process type StateExample struct { flow.Component In1 <-chan string // lock StateLock *sync.Mutex // state counter int buffer [32]string } func (p *StateExample) OnIn2(item String) { // We can safely modify fields here p.buffer = append(item, s) p.counter++ }
  • 19. Go ow - Types of port Go ow supports 3 types of ports: Input port, output port bi-direction port type PortExample struct { flow.Component Foo <-chan int // receive-only inport Bar chan<- int // send-only outport Boo chan string // can be inport or outport } Support method raise when a connection is closed func (p *Printer) OnLine(line string) { fmt.Println(line) } func (c *ComponentType) OnLineClose() { // Clean something }
  • 20. Thank you Thuc Le Software Engineer ledongthuc@gmail.com(mailto:ledongthuc@gmail.com)