SlideShare a Scribd company logo
1 of 31
Download to read offline
Non-Blocking Strategies for FFI
Don’t Block me Now!
Pablo Tesone
Pharo Consortium Engineer
1
Guille Polito
CNRS UMR9189

CRIStAL, Inria

RMoD
Pablo Tesone
Pharo Consortium
Engineer
Guille Polito
CNRS Engineer

RMod Team
• 10 years of experience in industrial
applications

• PhD in Dynamic Software Update

• Interested in improving
development tools and the daily
development process. 

• Enthusiast of the object oriented
programming and their tools.
• Experience industrial on service-
oriented and mobile applications.

• PhD in Computer Science

• Main research interests are
modularity and development tools.

• In the Pharo community since 2010

• More noticeable contributions:
Pharo Bootstrap process and
Iceberg.
FFI? Foreign Function Interface
Image
VM
External Libraries
FFI
We can communicate with anything that
has a C API
Operating System API
!3
Unified FFI in a nutshell
UFFI handles:
- Look-up of functions
- Marshalling of arguments
- Execution
- Marshalling of the return values
Concurrency in Pharo
!5
P1 P2 P3
Interpreter
Thread
p1
p3
p1
p2
p2
VM Thread
Concurrency in Pharo
!6
P1 P2 P3
Interpreter
Thread
p1
p3
p1
p2
p2
VM
handles
process
scheduling
VM Thread
Concurrency in Pharo
!7
P1 P2 P3
Interpreter
Thread
p1
p3
p1
p2
p2
p1
int function(char* foo, int bar)
VM Thread
Concurrency in Pharo
!8
P1 P2 P3
Interpreter
Thread
p1
p3
p1
p2
p2
p1
Out
of
VM
VM
loses
control
int function(char* foo, int bar)
VM Thread
Conceptual Non-Blocking FFI
!9
P1 P2 P3
Interpreter
Thread
p1
p3
p1
p2
p2
p1
p3
p2
?
int function(char* foo, int bar)
VM Thread
Strategy #1: Thread per Call-out
!10
Interpreter
Thread
p1
p2
p1
p2
Thread 1
<<Spawn>>
<<Signal Semaphore>>
int function(char* foo, int bar)
P1 P2 VM Thread
Strategy #1: Thread per Call-out
!11
Interpreter
Thread
p1
p2
p1
p2
Thread 1
<<Spawn>>
<<Signal Semaphore>>
int function(char* foo, int bar)
P1 P2
• Simple
• Expensive to spawn threads
• Calls are not in the same thread
• Cannot reuse existing threads (e.g., UI threads)
Not all libraries are
designed equally
• Different requirements

• Must run in the main thread (Cocoa)

• Must run in a single thread (Gtk+3)

• Runs on any thread but not concurrent (libgit, sqlite)

• Is a Thread-safe Library

• ….
!12
We need different
Strategies to choose from
!13
We need to choose different
strategies for each library
Strategy #2: Worker Threads
!14
Interpreter
Thread
p1
p2
p1
p2
Worker #1
<<Enqueue>>
Call out Queue
of Worker #1
<<Signal Semaphore>>
int function(char* foo, int bar)
P1 P2 VM Thread
Strategy #2: Worker Threads
!15
Interpreter
Thread
p1
p2
p1
p2
Worker #1
<<Enqueue>>
Call out Queue
of Worker #1
<<Signal Semaphore>>
int function(char* foo, int bar)
P1 P2
• Simple
• Group related calls
• No thread spawn overhead
• Expensive Callouts (synchronising queue)
• Do not support main thread!
Strategy #3: VM Thread Runner
!16
P1 P2 P3
Interpreter
Thread
p1
p3
p1
p2
p2
int function(char* foo, int bar)
p1
VM Thread
Strategy #3: VM Thread Runner
!17
P1 P2 P3
Interpreter
Thread
p1
p3
p1
p2
p2
int function(char* foo, int bar)
p1
• Simpler
• Group related calls
• No thread spawn overhead
• Backward compatibility
• Blocking
Strategy #4: Main Thread Runner
Interpreter
Thread
p1
p2
p1
p2
Worker #1
<<Enqueue>>
Call out Queue
of Worker #1
<<Signal Semaphore>>
int function(char* foo, int bar)
P1 P2 VM Thread
Strategy #4: Main Thread Runner
Interpreter
Thread
p1
p2
p1
p2
Worker #1
<<Enqueue>>
Call out Queue
of Worker #1
<<Signal Semaphore>>
int function(char* foo, int bar)
P1 P2
• Simple
• Group related calls
• No thread spawn overhead
• Supports main thread
• Expensive Callouts (synchronising queue)
• VM should be run in separate thread
Strategy #5: Global Interpreter Lock
int function(char* foo, int bar)
P1 P2
Interpreter
#1
Interpreter
#2
!20
VM Thread #1 VM Thread #2
Strategy #5: Global Interpreter Lock
int function(char* foo, int bar)
P1 P2
Interpreter
#1
Interpreter
#2
!21
• Group related calls
• No thread spawn overhead
• No Backward compatibility
• Application should be written with threading
in mind
• Requires VM modification
Strategy #6: Thread-safe interpreters
int function(char* foo, int bar)
!22
P1 P2
Interpreter
#1
Interpreter
#2
VM Thread #1 VM Thread #2
Strategy #6: Thread-safe interpreters
int function(char* foo, int bar)
!23
P1 P2
Interpreter
#1
Interpreter
#2
• Does not exist for Pharo
• Requires extensive modification of VM,
Plugins and Image core libraries
• Application should be written with threading
in mind
• Real multithreading not only for FFI
Implementations
!24
Queue Based FFI
(Pharo Threaded FFI Plugin)
GILda VM
(Global Interpreter Lock VM)
Strategy #1: Thread per Call-out
Strategy #2: Worker Threads
Strategy #3: VM Thread Runner
Strategy #5: Global Interpreter Lock
Strategy #4: Main Thread Runner
Future???
Strategy #6: Thread-safe
interpreters
Implementations
!25
Queue Based FFI
(Pharo Threaded FFI Plugin)
GILda VM
(Global Interpreter Lock VM)
Strategy #1: Thread per Call-out
Strategy #2: Worker Threads
Strategy #3: VM Thread Runner
Strategy #5: Global Interpreter Lock
Strategy #4: Main Thread Runner
Future???
Strategy #6: Thread-safe
interpreters
Transparency through
UFFI
!26
Your Program
Unified FFI
Pharo Threaded FFI
Pharo Threaded FFI Plugin
S#1 S#2 S#3 S#4
Squeak FFI
Squeak FFI
Plugin
Library
Decision Table
!27
Same Thread Worker Threads
Long Calls
Blocking Parallel
Short Calls
Little Overhead Lots of Overhead
OPTIMIZATIONS
Implementations
!28
GILda VM
(Global Interpreter Lock VM)
Strategy #5: Global Interpreter Lock
Queue Based FFI
(Pharo Threaded FFI Plugin)
Strategy #1: Thread per Call-out
Strategy #2: Worker Threads
Strategy #3: VM Thread Runner
Strategy #4: Main Thread Runner
Future???
Strategy #6: Thread-safe
interpreters
More Details
IWST - Virtual Machines Session
Thursday 11:00 am
Start Using It!
!29
Metacello new
baseline: ‘ThreadedFFI'
repository:
‘github://pharo-project/threadedFFI-Plugin/src';
load
pharo-project/threadedFFI-Plugin
Only in Pharo 8 + Headless VM
Conclusion
• Beta Version (In usage for Gtk+)

• Transparent for the user

• Strategies selected in the Image

• Uses LibFFI

• Re-entrant Callback support

• Tests!
!30
Preliminar results
• All marshalling image side + Lib FFI

• Short call

• Same thread 27 us

• Single worker thread 6791 us

• 2 Parallel long Calls (1 second per call)

• Same Thread 2001.9 ms

• Different working threads 1006.4ms

More Related Content

Similar to Non-Blocking Strategies for FFI

Improving the Pharo VM
Improving the Pharo VMImproving the Pharo VM
Improving the Pharo VMFAST
 
Present and Future of the Pharo VM: Headless and Beyond
 Present and Future of the Pharo VM: Headless and Beyond Present and Future of the Pharo VM: Headless and Beyond
Present and Future of the Pharo VM: Headless and BeyondESUG
 
ITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream Projects
ITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream ProjectsITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream Projects
ITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream ProjectsITCamp
 
What is (not) Pharo 8?
What is (not) Pharo 8?What is (not) Pharo 8?
What is (not) Pharo 8?FAST
 
[Rakuten TechConf2014] [E-4] Rakuten Front-end Framework Project
[Rakuten TechConf2014] [E-4] Rakuten Front-end Framework Project[Rakuten TechConf2014] [E-4] Rakuten Front-end Framework Project
[Rakuten TechConf2014] [E-4] Rakuten Front-end Framework ProjectRakuten Group, Inc.
 
Presentation 3 software developer in rfid
Presentation 3 software developer in rfidPresentation 3 software developer in rfid
Presentation 3 software developer in rfidMouhanad Alkhaldi
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSCisco Russia
 
GildaVM: a Non-Blocking I/O Architecture for the Cog VM
GildaVM: a Non-Blocking I/O Architecture for the Cog VMGildaVM: a Non-Blocking I/O Architecture for the Cog VM
GildaVM: a Non-Blocking I/O Architecture for the Cog VMESUG
 
Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)lennartkats
 
Pharo Consortium: A roadmap to solid evolution
Pharo Consortium: A roadmap to solid evolutionPharo Consortium: A roadmap to solid evolution
Pharo Consortium: A roadmap to solid evolutionESUG
 
Pharo: A roadmap to solid evolution.
Pharo: A roadmap to solid evolution.Pharo: A roadmap to solid evolution.
Pharo: A roadmap to solid evolution.Esteban Lorenzano
 
FFR GreenKiller - Automatic kernel-mode malware analysis system
FFR GreenKiller - Automatic kernel-mode malware analysis systemFFR GreenKiller - Automatic kernel-mode malware analysis system
FFR GreenKiller - Automatic kernel-mode malware analysis systemFFRI, Inc.
 
Industrialise PHP ~ ZendCon Europe 2013
Industrialise PHP ~ ZendCon Europe 2013Industrialise PHP ~ ZendCon Europe 2013
Industrialise PHP ~ ZendCon Europe 2013ekino
 
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...Maksim Shudrak
 
Zero bugs found? Hold my beer AFL! how to improve coverage-guided fuzzing and...
Zero bugs found? Hold my beer AFL! how to improve coverage-guided fuzzing and...Zero bugs found? Hold my beer AFL! how to improve coverage-guided fuzzing and...
Zero bugs found? Hold my beer AFL! how to improve coverage-guided fuzzing and...Maksim Shudrak
 
DEF CON 27 - MAKSIM SHUDRAK - zero bugs found hold my beer afl how to improve...
DEF CON 27 - MAKSIM SHUDRAK - zero bugs found hold my beer afl how to improve...DEF CON 27 - MAKSIM SHUDRAK - zero bugs found hold my beer afl how to improve...
DEF CON 27 - MAKSIM SHUDRAK - zero bugs found hold my beer afl how to improve...Felipe Prado
 
44CON London 2015 - Reverse engineering and exploiting font rasterizers: the ...
44CON London 2015 - Reverse engineering and exploiting font rasterizers: the ...44CON London 2015 - Reverse engineering and exploiting font rasterizers: the ...
44CON London 2015 - Reverse engineering and exploiting font rasterizers: the ...44CON
 
Programming on Windows 8.1: The New Stream and Storage Paradigm (Raffaele Ria...
Programming on Windows 8.1: The New Stream and Storage Paradigm (Raffaele Ria...Programming on Windows 8.1: The New Stream and Storage Paradigm (Raffaele Ria...
Programming on Windows 8.1: The New Stream and Storage Paradigm (Raffaele Ria...ITCamp
 
OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11OpenSAF Foundation
 
Pharo IoT Installation Improvements and Continuous Integration
Pharo IoT Installation Improvements and Continuous IntegrationPharo IoT Installation Improvements and Continuous Integration
Pharo IoT Installation Improvements and Continuous IntegrationAllex Oliveira
 

Similar to Non-Blocking Strategies for FFI (20)

Improving the Pharo VM
Improving the Pharo VMImproving the Pharo VM
Improving the Pharo VM
 
Present and Future of the Pharo VM: Headless and Beyond
 Present and Future of the Pharo VM: Headless and Beyond Present and Future of the Pharo VM: Headless and Beyond
Present and Future of the Pharo VM: Headless and Beyond
 
ITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream Projects
ITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream ProjectsITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream Projects
ITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream Projects
 
What is (not) Pharo 8?
What is (not) Pharo 8?What is (not) Pharo 8?
What is (not) Pharo 8?
 
[Rakuten TechConf2014] [E-4] Rakuten Front-end Framework Project
[Rakuten TechConf2014] [E-4] Rakuten Front-end Framework Project[Rakuten TechConf2014] [E-4] Rakuten Front-end Framework Project
[Rakuten TechConf2014] [E-4] Rakuten Front-end Framework Project
 
Presentation 3 software developer in rfid
Presentation 3 software developer in rfidPresentation 3 software developer in rfid
Presentation 3 software developer in rfid
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
 
GildaVM: a Non-Blocking I/O Architecture for the Cog VM
GildaVM: a Non-Blocking I/O Architecture for the Cog VMGildaVM: a Non-Blocking I/O Architecture for the Cog VM
GildaVM: a Non-Blocking I/O Architecture for the Cog VM
 
Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)
 
Pharo Consortium: A roadmap to solid evolution
Pharo Consortium: A roadmap to solid evolutionPharo Consortium: A roadmap to solid evolution
Pharo Consortium: A roadmap to solid evolution
 
Pharo: A roadmap to solid evolution.
Pharo: A roadmap to solid evolution.Pharo: A roadmap to solid evolution.
Pharo: A roadmap to solid evolution.
 
FFR GreenKiller - Automatic kernel-mode malware analysis system
FFR GreenKiller - Automatic kernel-mode malware analysis systemFFR GreenKiller - Automatic kernel-mode malware analysis system
FFR GreenKiller - Automatic kernel-mode malware analysis system
 
Industrialise PHP ~ ZendCon Europe 2013
Industrialise PHP ~ ZendCon Europe 2013Industrialise PHP ~ ZendCon Europe 2013
Industrialise PHP ~ ZendCon Europe 2013
 
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
 
Zero bugs found? Hold my beer AFL! how to improve coverage-guided fuzzing and...
Zero bugs found? Hold my beer AFL! how to improve coverage-guided fuzzing and...Zero bugs found? Hold my beer AFL! how to improve coverage-guided fuzzing and...
Zero bugs found? Hold my beer AFL! how to improve coverage-guided fuzzing and...
 
DEF CON 27 - MAKSIM SHUDRAK - zero bugs found hold my beer afl how to improve...
DEF CON 27 - MAKSIM SHUDRAK - zero bugs found hold my beer afl how to improve...DEF CON 27 - MAKSIM SHUDRAK - zero bugs found hold my beer afl how to improve...
DEF CON 27 - MAKSIM SHUDRAK - zero bugs found hold my beer afl how to improve...
 
44CON London 2015 - Reverse engineering and exploiting font rasterizers: the ...
44CON London 2015 - Reverse engineering and exploiting font rasterizers: the ...44CON London 2015 - Reverse engineering and exploiting font rasterizers: the ...
44CON London 2015 - Reverse engineering and exploiting font rasterizers: the ...
 
Programming on Windows 8.1: The New Stream and Storage Paradigm (Raffaele Ria...
Programming on Windows 8.1: The New Stream and Storage Paradigm (Raffaele Ria...Programming on Windows 8.1: The New Stream and Storage Paradigm (Raffaele Ria...
Programming on Windows 8.1: The New Stream and Storage Paradigm (Raffaele Ria...
 
OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11
 
Pharo IoT Installation Improvements and Continuous Integration
Pharo IoT Installation Improvements and Continuous IntegrationPharo IoT Installation Improvements and Continuous Integration
Pharo IoT Installation Improvements and Continuous Integration
 

More from ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

More from ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Recently uploaded

VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 

Recently uploaded (20)

VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 

Non-Blocking Strategies for FFI

  • 1. Non-Blocking Strategies for FFI Don’t Block me Now! Pablo Tesone Pharo Consortium Engineer 1 Guille Polito CNRS UMR9189 CRIStAL, Inria RMoD
  • 2. Pablo Tesone Pharo Consortium Engineer Guille Polito CNRS Engineer RMod Team • 10 years of experience in industrial applications • PhD in Dynamic Software Update • Interested in improving development tools and the daily development process. • Enthusiast of the object oriented programming and their tools. • Experience industrial on service- oriented and mobile applications. • PhD in Computer Science • Main research interests are modularity and development tools. • In the Pharo community since 2010 • More noticeable contributions: Pharo Bootstrap process and Iceberg.
  • 3. FFI? Foreign Function Interface Image VM External Libraries FFI We can communicate with anything that has a C API Operating System API !3
  • 4. Unified FFI in a nutshell UFFI handles: - Look-up of functions - Marshalling of arguments - Execution - Marshalling of the return values
  • 5. Concurrency in Pharo !5 P1 P2 P3 Interpreter Thread p1 p3 p1 p2 p2 VM Thread
  • 6. Concurrency in Pharo !6 P1 P2 P3 Interpreter Thread p1 p3 p1 p2 p2 VM handles process scheduling VM Thread
  • 7. Concurrency in Pharo !7 P1 P2 P3 Interpreter Thread p1 p3 p1 p2 p2 p1 int function(char* foo, int bar) VM Thread
  • 8. Concurrency in Pharo !8 P1 P2 P3 Interpreter Thread p1 p3 p1 p2 p2 p1 Out of VM VM loses control int function(char* foo, int bar) VM Thread
  • 9. Conceptual Non-Blocking FFI !9 P1 P2 P3 Interpreter Thread p1 p3 p1 p2 p2 p1 p3 p2 ? int function(char* foo, int bar) VM Thread
  • 10. Strategy #1: Thread per Call-out !10 Interpreter Thread p1 p2 p1 p2 Thread 1 <<Spawn>> <<Signal Semaphore>> int function(char* foo, int bar) P1 P2 VM Thread
  • 11. Strategy #1: Thread per Call-out !11 Interpreter Thread p1 p2 p1 p2 Thread 1 <<Spawn>> <<Signal Semaphore>> int function(char* foo, int bar) P1 P2 • Simple • Expensive to spawn threads • Calls are not in the same thread • Cannot reuse existing threads (e.g., UI threads)
  • 12. Not all libraries are designed equally • Different requirements • Must run in the main thread (Cocoa) • Must run in a single thread (Gtk+3) • Runs on any thread but not concurrent (libgit, sqlite) • Is a Thread-safe Library • …. !12
  • 13. We need different Strategies to choose from !13 We need to choose different strategies for each library
  • 14. Strategy #2: Worker Threads !14 Interpreter Thread p1 p2 p1 p2 Worker #1 <<Enqueue>> Call out Queue of Worker #1 <<Signal Semaphore>> int function(char* foo, int bar) P1 P2 VM Thread
  • 15. Strategy #2: Worker Threads !15 Interpreter Thread p1 p2 p1 p2 Worker #1 <<Enqueue>> Call out Queue of Worker #1 <<Signal Semaphore>> int function(char* foo, int bar) P1 P2 • Simple • Group related calls • No thread spawn overhead • Expensive Callouts (synchronising queue) • Do not support main thread!
  • 16. Strategy #3: VM Thread Runner !16 P1 P2 P3 Interpreter Thread p1 p3 p1 p2 p2 int function(char* foo, int bar) p1 VM Thread
  • 17. Strategy #3: VM Thread Runner !17 P1 P2 P3 Interpreter Thread p1 p3 p1 p2 p2 int function(char* foo, int bar) p1 • Simpler • Group related calls • No thread spawn overhead • Backward compatibility • Blocking
  • 18. Strategy #4: Main Thread Runner Interpreter Thread p1 p2 p1 p2 Worker #1 <<Enqueue>> Call out Queue of Worker #1 <<Signal Semaphore>> int function(char* foo, int bar) P1 P2 VM Thread
  • 19. Strategy #4: Main Thread Runner Interpreter Thread p1 p2 p1 p2 Worker #1 <<Enqueue>> Call out Queue of Worker #1 <<Signal Semaphore>> int function(char* foo, int bar) P1 P2 • Simple • Group related calls • No thread spawn overhead • Supports main thread • Expensive Callouts (synchronising queue) • VM should be run in separate thread
  • 20. Strategy #5: Global Interpreter Lock int function(char* foo, int bar) P1 P2 Interpreter #1 Interpreter #2 !20 VM Thread #1 VM Thread #2
  • 21. Strategy #5: Global Interpreter Lock int function(char* foo, int bar) P1 P2 Interpreter #1 Interpreter #2 !21 • Group related calls • No thread spawn overhead • No Backward compatibility • Application should be written with threading in mind • Requires VM modification
  • 22. Strategy #6: Thread-safe interpreters int function(char* foo, int bar) !22 P1 P2 Interpreter #1 Interpreter #2 VM Thread #1 VM Thread #2
  • 23. Strategy #6: Thread-safe interpreters int function(char* foo, int bar) !23 P1 P2 Interpreter #1 Interpreter #2 • Does not exist for Pharo • Requires extensive modification of VM, Plugins and Image core libraries • Application should be written with threading in mind • Real multithreading not only for FFI
  • 24. Implementations !24 Queue Based FFI (Pharo Threaded FFI Plugin) GILda VM (Global Interpreter Lock VM) Strategy #1: Thread per Call-out Strategy #2: Worker Threads Strategy #3: VM Thread Runner Strategy #5: Global Interpreter Lock Strategy #4: Main Thread Runner Future??? Strategy #6: Thread-safe interpreters
  • 25. Implementations !25 Queue Based FFI (Pharo Threaded FFI Plugin) GILda VM (Global Interpreter Lock VM) Strategy #1: Thread per Call-out Strategy #2: Worker Threads Strategy #3: VM Thread Runner Strategy #5: Global Interpreter Lock Strategy #4: Main Thread Runner Future??? Strategy #6: Thread-safe interpreters
  • 26. Transparency through UFFI !26 Your Program Unified FFI Pharo Threaded FFI Pharo Threaded FFI Plugin S#1 S#2 S#3 S#4 Squeak FFI Squeak FFI Plugin Library
  • 27. Decision Table !27 Same Thread Worker Threads Long Calls Blocking Parallel Short Calls Little Overhead Lots of Overhead OPTIMIZATIONS
  • 28. Implementations !28 GILda VM (Global Interpreter Lock VM) Strategy #5: Global Interpreter Lock Queue Based FFI (Pharo Threaded FFI Plugin) Strategy #1: Thread per Call-out Strategy #2: Worker Threads Strategy #3: VM Thread Runner Strategy #4: Main Thread Runner Future??? Strategy #6: Thread-safe interpreters More Details IWST - Virtual Machines Session Thursday 11:00 am
  • 29. Start Using It! !29 Metacello new baseline: ‘ThreadedFFI' repository: ‘github://pharo-project/threadedFFI-Plugin/src'; load pharo-project/threadedFFI-Plugin Only in Pharo 8 + Headless VM
  • 30. Conclusion • Beta Version (In usage for Gtk+) • Transparent for the user • Strategies selected in the Image • Uses LibFFI • Re-entrant Callback support • Tests! !30
  • 31. Preliminar results • All marshalling image side + Lib FFI • Short call • Same thread 27 us • Single worker thread 6791 us • 2 Parallel long Calls (1 second per call) • Same Thread 2001.9 ms • Different working threads 1006.4ms