SlideShare a Scribd company logo
1 of 21
Download to read offline
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 2016Tim 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 perspectiveQAFest
 
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 gatlingTim van Eijndhoven
 
140 releases per month
140 releases per month140 releases per month
140 releases per monthManuel 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
 
Overview of Gitlab usage
Overview of Gitlab usageOverview of Gitlab usage
Overview of Gitlab usageOluDouglas
 
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-muleikram_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 MonitoringGarland Kan
 
Blugento cloud foundry - components - principles
Blugento cloud foundry - components - principlesBlugento cloud foundry - components - principles
Blugento cloud foundry - components - principlesThomas Fleck
 
ATAGTR2017 Performance Automation in Dev-Ops
ATAGTR2017 Performance Automation in Dev-OpsATAGTR2017 Performance Automation in Dev-Ops
ATAGTR2017 Performance Automation in Dev-OpsAgile 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 FrameworkSathish Mariappan
 
TuleapCon 2019. DevOps in Tuleap
TuleapCon 2019. DevOps in TuleapTuleapCon 2019. DevOps in Tuleap
TuleapCon 2019. DevOps in TuleapTuleap
 
Introduction to K6
Introduction to K6Introduction to K6
Introduction to K6Knoldus 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.0Anyscale
 
Inter Task Communication On Volatile Nodes
Inter Task Communication On Volatile NodesInter Task Communication On Volatile Nodes
Inter Task Communication On Volatile Nodesnagarajan_ka
 
Os2 2
Os2 2Os2 2
Os2 2issbp
 
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
 
Unit II - 1 - Operating System Process
Unit II - 1 - Operating System ProcessUnit II - 1 - Operating System Process
Unit II - 1 - Operating System Processcscarcas
 
cs8493 - operating systems unit 2
cs8493 - operating systems unit 2cs8493 - operating systems unit 2
cs8493 - operating systems unit 2SIMONTHOMAS 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
 

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
 
Processes
ProcessesProcesses
Processes
 
Operating System
Operating SystemOperating System
Operating System
 
process management.ppt
process management.pptprocess management.ppt
process management.ppt
 
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...
 

More from 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 testsAnton Stepanenko
 
Hand helper for manual testing
Hand helper for manual testingHand helper for manual testing
Hand helper for manual testingAnton Stepanenko
 
Нагрузочное тестирование по-живому
Нагрузочное тестирование по-живомуНагрузочное тестирование по-живому
Нагрузочное тестирование по-живому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

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 

Recently uploaded (20)

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 

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)