SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
A deep dive into bridging
NodeJS with NET Core
Raffaele Rialdi
@raffaeler
raffaeler@vevy.com
https://www.linkedin.com/in/raffaelerialdi/
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Many thanks to our sponsors & partners!
GOLD
SILVER
PARTNERS
PLATINUM
POWERED BY
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Who am I?
• I am Raffaele Rialdi, Senior Software Architect in Vevy Europe – Italy
• I am also consultant in many industries
– manufacturing, racing, healthcare, financial, …
• But also Speaker in italian and international conferences
– Trainer as well
• And very proud to have been awarded as a Microsoft MVP
– Since 2003
@raffaeler
raffaeler@vevy.com
github.com/raffaeler
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
NodeJS and .NET? What do you mean?
• We do NOT want to
serialize the data across
processes
– Too easy ☺
– Poor performance 
• All the code in the same
process
– Hard way ☺☺
– Good performance ☺
NodeJS
Process
Json Serialize
C#
Process
One Process
NodeJS
Code
C#
Code
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
.NET Code
Introducing xcore
Javascript / Typescript code
xcorexcore C++ xcore .NET
.NET Core
V8
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
xcore in action
• Load and initialize xcore
• Load the .net metadata
– Just the first needed class
• Create an instance
• Call methods
• Walk the graph
– new metadata is
loaded automatically
• Asynchronous calls
(and much more!)
var xcore = require('bindings')('xcore');
xcore.initialize(__dirname + "Sample",
"SampleLibrary.dll", "SampleLibrary.Initializer");
xcore.loadClass("SampleLibrary.OrderSample.
OrderManager, SampleLibrary");
var om = new xcore.OrderManager("raf");
console.log(om.Add("Hello, ", "world"));
console.log(om.SelectedOrder.Name);
om.AddAsync(2, 3, function(res){
console.log(res);
});
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Node.js® is a well-known runtime environment for javascript
• It leverages the power of "V8", the engine of Google Chrome
– V8 conforms to the ECMAScript 262 standard
– runs cross-platforms
• NodeJs has a vivid ecosystem with tons of 3rd party libraries
• V8 can be extended with native addons (C++):
– When you need more performance
– To access operating system's resources and services
– To interoperate with external systems / hardware
Node.JS and V8 https://nodejs.org
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Including the libraries
• Declare the Entry-Point using
the NODE_MODULE macro
• Implement the entry-point and
declare javascript-friendly
methods
• The "Method" will be available
as "hello" to javascript
The basic structure of a C++ V8 addon
#include <node.h>
#include <v8.h>
NODE_MODULE(addon, init)
void init(Local<Object> exports)
{
NODE_SET_METHOD(exports, "hello", Method);
}
void Method(const FunctionCallbackInfo<Value>& args)
{
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(
String::NewFromUtf8(isolate, "world"));
}
// javascript code
const addon = require('./myAddon');
console.log(addon.hello()); // 'world'
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
V8 Object Wrapping
• By deriving the ObjectWrap class, we can expose objects to JS
• Object members are added dynamically
– Constructors, methods, properties, indexers
– Just set the members spcifying the class name
• All member are static void functions
– Their input parameter is a "const FunctionCallbackInfo<Value>& args"
• The args contain the runtime values of the arguments
– The wrapper instance is get using ObjectWrap:Unwrap
– The return value is set using "args.GetReturnValue().Set(…);"
exports->Set(v8className, constructorTemplate->GetFunction());
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• LibUV is the threading library used by NodeJs and V8
• The JS code must be always executed in the main thread
• .NET methods returning Task<T> must to be marshalled back to the
main thread
• The LibUV library gives a very basic support for enqueuing
messages in its threads
Threading and the libuv threading library
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Demo: a simple V8 plugin
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Hosting the CoreCLR
• What does it mean hosting the CLR?
– A native (C++) application can load the CLR, some assemblies and
run managed (.NET) code
– SQL Server is a great example of native application hosting the CLR
– You can do it too!
• The CLR in .NET Framework could be hosted only on
Windows
– It is based on the COM infrastructure
• Net Core can be hosted as well but cross-platform
– It mimics the COM interfaces, but the infrastructure is not COM-
dependent
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Demo: loading the CLR
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
XCORE WRAP UP
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Metadata for the CLR type is loaded
–The C++ layer dynamically add the class definition to V8
• A member is invoked
–The C++ layer gets the arguments of the call
–A Reverse PInvoke is done to C#
–The instance identifier is retrieved from a global table
–If not available, the marshaller code is generated
–The code is invoked
xcore execution flow
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• The call was synchronous
–The return value is marshalled back to C++ and V8
• The call was asynchronous
–In C++ the return value is queued in LibUV main thread
• The call was an exception
–It is propagated to the caller
xcore execution flow
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Performance profile
• There are still many possible improvements
• The add use-case is not realistic
– it just measures infrastructure and marshalling
– 4 marshalling involved: (JS  C++  .NET  C++  JS)
1 Million calls
js: 6.156 ms
c++: 56.352 ms
.net: 1294.254 ms
console.time("net");
for(var i=0; i<loop; i++)
{
om.NetAdd(i, i);
}
console.timeEnd("net");
console.time("c++");
for(var i=0; i<loop; i++)
{
xcore.add(i, i);
}
console.timeEnd("c++");
console.time("js");
for(var i=0; i<loop; i++)
{
LocalAdd(i, i);
}
console.timeEnd("js");
js: 6.156ms c++: 56.352ms .net: 1294.254ms
var om = new xcore.OrderManager();
om.Add(2, 2); // jitting
LocalAdd(2,2); // jitting
xcore.add(2, 2); // jitting
var loop = 1000000; // 1 Million
function LocalAdd(x, y)
{ return x + y; }
prepare the benchmark local javascript C++ only xcore + C#
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Use-cases
1. Node.js applications
2. UI created with the Electron framework
– Ability to create .NET ViewModels for Angular (by Google)
3. Using JS to script Windows Powershell
4. Nativescript Mobile applications
– Nativescript is a project by Progress Software Corporation
https://www.nativescript.org/
5. Anything else based on V8
http://electron.atom.io
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Questions?
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

The fight for surviving in the IoT world - Radu Vunvulea
The fight for surviving in the IoT world - Radu VunvuleaThe fight for surviving in the IoT world - Radu Vunvulea
The fight for surviving in the IoT world - Radu Vunvulea
 
Blockchain for mere mortals - understand the fundamentals and start building ...
Blockchain for mere mortals - understand the fundamentals and start building ...Blockchain for mere mortals - understand the fundamentals and start building ...
Blockchain for mere mortals - understand the fundamentals and start building ...
 
Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017
 
Modern cybersecurity threats, and shiny new tools to help deal with them - T...
 Modern cybersecurity threats, and shiny new tools to help deal with them - T... Modern cybersecurity threats, and shiny new tools to help deal with them - T...
Modern cybersecurity threats, and shiny new tools to help deal with them - T...
 
Kubernetes - Cloud Native Application Orchestration - Catalin Jora
Kubernetes - Cloud Native Application Orchestration - Catalin JoraKubernetes - Cloud Native Application Orchestration - Catalin Jora
Kubernetes - Cloud Native Application Orchestration - Catalin Jora
 
ITCamp 2017 - Florin Coros - Decide between In-Process or Inter-Processes Com...
ITCamp 2017 - Florin Coros - Decide between In-Process or Inter-Processes Com...ITCamp 2017 - Florin Coros - Decide between In-Process or Inter-Processes Com...
ITCamp 2017 - Florin Coros - Decide between In-Process or Inter-Processes Com...
 
ITCamp 2017 - Laurent Ellerbach - Bot. You said bot? Let's build a bot then...
ITCamp 2017 - Laurent Ellerbach - Bot. You said bot? Let's build a bot then...ITCamp 2017 - Laurent Ellerbach - Bot. You said bot? Let's build a bot then...
ITCamp 2017 - Laurent Ellerbach - Bot. You said bot? Let's build a bot then...
 
Windows 10 Creators Update: what’s on tap for business users - Ionut Balan
Windows 10 Creators Update: what’s on tap for business users - Ionut BalanWindows 10 Creators Update: what’s on tap for business users - Ionut Balan
Windows 10 Creators Update: what’s on tap for business users - Ionut Balan
 
The Microsoft Cloud and Server Strategy - Ben Armstrong
The Microsoft Cloud and Server Strategy - Ben ArmstrongThe Microsoft Cloud and Server Strategy - Ben Armstrong
The Microsoft Cloud and Server Strategy - Ben Armstrong
 
BUILD with Microsoft - Radu Stefan
 BUILD with Microsoft - Radu Stefan BUILD with Microsoft - Radu Stefan
BUILD with Microsoft - Radu Stefan
 
Provisioning Windows instances at scale on Azure, AWS and OpenStack - Adrian ...
Provisioning Windows instances at scale on Azure, AWS and OpenStack - Adrian ...Provisioning Windows instances at scale on Azure, AWS and OpenStack - Adrian ...
Provisioning Windows instances at scale on Azure, AWS and OpenStack - Adrian ...
 
2016, A New Era of OS and Cloud Security - Tudor Damian
2016, A New Era of OS and Cloud Security - Tudor Damian2016, A New Era of OS and Cloud Security - Tudor Damian
2016, A New Era of OS and Cloud Security - Tudor Damian
 
Xamarin Under The Hood - Dan Ardelean
 Xamarin Under The Hood - Dan Ardelean Xamarin Under The Hood - Dan Ardelean
Xamarin Under The Hood - Dan Ardelean
 
Migrating to Continuous Delivery with TFS 2017 - Liviu Mandras-Iura
 Migrating to Continuous Delivery with TFS 2017 - Liviu Mandras-Iura Migrating to Continuous Delivery with TFS 2017 - Liviu Mandras-Iura
Migrating to Continuous Delivery with TFS 2017 - Liviu Mandras-Iura
 
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
 
Building and Managing your Virtual Datacenter using PowerShell DSC - Florin L...
Building and Managing your Virtual Datacenter using PowerShell DSC - Florin L...Building and Managing your Virtual Datacenter using PowerShell DSC - Florin L...
Building and Managing your Virtual Datacenter using PowerShell DSC - Florin L...
 
#NoAgile - Dan Suciu
 #NoAgile - Dan Suciu #NoAgile - Dan Suciu
#NoAgile - Dan Suciu
 
Developing PowerShell Tools - Razvan Rusu
Developing PowerShell Tools - Razvan RusuDeveloping PowerShell Tools - Razvan Rusu
Developing PowerShell Tools - Razvan Rusu
 
What's New in Hyper-V 2016 - Thomas Maurer
What's New in Hyper-V 2016 - Thomas MaurerWhat's New in Hyper-V 2016 - Thomas Maurer
What's New in Hyper-V 2016 - Thomas Maurer
 
Execution Plans in practice - how to make SQL Server queries faster - Damian ...
Execution Plans in practice - how to make SQL Server queries faster - Damian ...Execution Plans in practice - how to make SQL Server queries faster - Damian ...
Execution Plans in practice - how to make SQL Server queries faster - Damian ...
 

Andere mochten auch

Andere mochten auch (13)

Columnstore indexes - best practices for the ETL process - Damian Widera
Columnstore indexes - best practices for the ETL process - Damian WideraColumnstore indexes - best practices for the ETL process - Damian Widera
Columnstore indexes - best practices for the ETL process - Damian Widera
 
Scaling face recognition with big data - Bogdan Bocse
 Scaling face recognition with big data - Bogdan Bocse Scaling face recognition with big data - Bogdan Bocse
Scaling face recognition with big data - Bogdan Bocse
 
Forget Process, Focus on People - Peter Leeson
Forget Process, Focus on People - Peter LeesonForget Process, Focus on People - Peter Leeson
Forget Process, Focus on People - Peter Leeson
 
Big Data Solutions in Azure - David Giard
Big Data Solutions in Azure - David GiardBig Data Solutions in Azure - David Giard
Big Data Solutions in Azure - David Giard
 
The Secret of Engaging Presentations - Boris Hristov
The Secret of Engaging Presentations - Boris HristovThe Secret of Engaging Presentations - Boris Hristov
The Secret of Engaging Presentations - Boris Hristov
 
The Vision of Computer Vision: The bold promise of teaching computers to unde...
The Vision of Computer Vision: The bold promise of teaching computers to unde...The Vision of Computer Vision: The bold promise of teaching computers to unde...
The Vision of Computer Vision: The bold promise of teaching computers to unde...
 
From Developer to Data Scientist - Gaines Kergosien
From Developer to Data Scientist - Gaines KergosienFrom Developer to Data Scientist - Gaines Kergosien
From Developer to Data Scientist - Gaines Kergosien
 
One Azure Monitor to Rule Them All? (IT Camp 2017, Cluj, RO)
One Azure Monitor to Rule Them All? (IT Camp 2017, Cluj, RO)One Azure Monitor to Rule Them All? (IT Camp 2017, Cluj, RO)
One Azure Monitor to Rule Them All? (IT Camp 2017, Cluj, RO)
 
Great all this new stuff, but how do I convince my management - Erwin Derksen
 Great all this new stuff, but how do I convince my management - Erwin Derksen Great all this new stuff, but how do I convince my management - Erwin Derksen
Great all this new stuff, but how do I convince my management - Erwin Derksen
 
Building Powerful Applications with AngularJS 2 and TypeScript - David Giard
Building Powerful Applications with AngularJS 2 and TypeScript - David GiardBuilding Powerful Applications with AngularJS 2 and TypeScript - David Giard
Building Powerful Applications with AngularJS 2 and TypeScript - David Giard
 
Storage Spaces Direct - the new Microsoft SDS star - Carsten Rachfahl
Storage Spaces Direct - the new Microsoft SDS star - Carsten RachfahlStorage Spaces Direct - the new Microsoft SDS star - Carsten Rachfahl
Storage Spaces Direct - the new Microsoft SDS star - Carsten Rachfahl
 
7 Habits of Highly Paid Developers - Gaines Kergosien
7 Habits of Highly Paid Developers - Gaines Kergosien7 Habits of Highly Paid Developers - Gaines Kergosien
7 Habits of Highly Paid Developers - Gaines Kergosien
 
ITCamp 2017 - Ciprian Sorlea - Fostering Heroes
ITCamp 2017 - Ciprian Sorlea - Fostering HeroesITCamp 2017 - Ciprian Sorlea - Fostering Heroes
ITCamp 2017 - Ciprian Sorlea - Fostering Heroes
 

Ähnlich wie ITCamp 2017 - Raffaele Rialdi - A Deep Dive Into Bridging Node-js with .NET Core

Serving Deep Learning Models At Scale With RedisAI: Luca Antiga
Serving Deep Learning Models At Scale With RedisAI: Luca AntigaServing Deep Learning Models At Scale With RedisAI: Luca Antiga
Serving Deep Learning Models At Scale With RedisAI: Luca Antiga
Redis Labs
 

Ähnlich wie ITCamp 2017 - Raffaele Rialdi - A Deep Dive Into Bridging Node-js with .NET Core (20)

Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
 
Deep Dive into the Microsoft OpenStack CI Infrastructure (Alessandro Pilotti)
Deep Dive into the Microsoft OpenStack CI Infrastructure (Alessandro Pilotti)Deep Dive into the Microsoft OpenStack CI Infrastructure (Alessandro Pilotti)
Deep Dive into the Microsoft OpenStack CI Infrastructure (Alessandro Pilotti)
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
Node.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel AvivNode.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel Aviv
 
ZaloPay Merchant Platform on K8S on-premise
ZaloPay Merchant Platform on K8S on-premiseZaloPay Merchant Platform on K8S on-premise
ZaloPay Merchant Platform on K8S on-premise
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - Intro
 
Creating Web and Mobile Apps with Angular 2 - George Saadeh
Creating Web and Mobile Apps with Angular 2 - George SaadehCreating Web and Mobile Apps with Angular 2 - George Saadeh
Creating Web and Mobile Apps with Angular 2 - George Saadeh
 
NET core 2 e i fratelli
NET core 2 e i fratelliNET core 2 e i fratelli
NET core 2 e i fratelli
 
Busy Developers Guide to AngularJS (Tiberiu Covaci)
Busy Developers Guide to AngularJS (Tiberiu Covaci)Busy Developers Guide to AngularJS (Tiberiu Covaci)
Busy Developers Guide to AngularJS (Tiberiu Covaci)
 
DevOpsCon 2015 - DevOps in Mobile Games
DevOpsCon 2015 - DevOps in Mobile GamesDevOpsCon 2015 - DevOps in Mobile Games
DevOpsCon 2015 - DevOps in Mobile Games
 
Old code doesn't stink
Old code doesn't stinkOld code doesn't stink
Old code doesn't stink
 
Cockatrice: A Hardware Design Environment with Elixir
Cockatrice: A Hardware Design Environment with ElixirCockatrice: A Hardware Design Environment with Elixir
Cockatrice: A Hardware Design Environment with Elixir
 
The fight for surviving in the IoT world
The fight for surviving in the IoT worldThe fight for surviving in the IoT world
The fight for surviving in the IoT world
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
Engage 2019: Introduction to Node-Red
Engage 2019: Introduction to Node-RedEngage 2019: Introduction to Node-Red
Engage 2019: Introduction to Node-Red
 
Serving Deep Learning Models At Scale With RedisAI: Luca Antiga
Serving Deep Learning Models At Scale With RedisAI: Luca AntigaServing Deep Learning Models At Scale With RedisAI: Luca Antiga
Serving Deep Learning Models At Scale With RedisAI: Luca Antiga
 
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
TensorFlow meetup: Keras - Pytorch - TensorFlow.jsTensorFlow meetup: Keras - Pytorch - TensorFlow.js
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
 
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
 

Mehr von ITCamp

ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UXITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp
 

Mehr von ITCamp (20)

ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
 
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
 
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Peter Leeson - Managing SkillsITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Peter Leeson - Managing Skills
 
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Mihai Tataran - Governing your Cloud ResourcesITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
 
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UXITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
 
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Coros - Implementing Clean ArchitectureITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
 
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
 
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp 2019 - Florin Flestea -  How 3rd Level support experience influenced m...ITCamp 2019 - Florin Flestea -  How 3rd Level support experience influenced m...
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
 
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
 
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The EnterpriseITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
 
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal TrendsITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
 
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data LakeITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
 
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andy Cross - Business Outcomes from AIITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andy Cross - Business Outcomes from AI
 
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud StoryITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
 
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
 
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
 
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go NowITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
 
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2019 - Peter Leeson - Vitruvian QualityITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2019 - Peter Leeson - Vitruvian Quality
 
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World ApplicationITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
 
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

ITCamp 2017 - Raffaele Rialdi - A Deep Dive Into Bridging Node-js with .NET Core

  • 1. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals A deep dive into bridging NodeJS with NET Core Raffaele Rialdi @raffaeler raffaeler@vevy.com https://www.linkedin.com/in/raffaelerialdi/
  • 2. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Many thanks to our sponsors & partners! GOLD SILVER PARTNERS PLATINUM POWERED BY
  • 3. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Who am I? • I am Raffaele Rialdi, Senior Software Architect in Vevy Europe – Italy • I am also consultant in many industries – manufacturing, racing, healthcare, financial, … • But also Speaker in italian and international conferences – Trainer as well • And very proud to have been awarded as a Microsoft MVP – Since 2003 @raffaeler raffaeler@vevy.com github.com/raffaeler
  • 4. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals NodeJS and .NET? What do you mean? • We do NOT want to serialize the data across processes – Too easy ☺ – Poor performance  • All the code in the same process – Hard way ☺☺ – Good performance ☺ NodeJS Process Json Serialize C# Process One Process NodeJS Code C# Code
  • 5. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals .NET Code Introducing xcore Javascript / Typescript code xcorexcore C++ xcore .NET .NET Core V8
  • 6. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals xcore in action • Load and initialize xcore • Load the .net metadata – Just the first needed class • Create an instance • Call methods • Walk the graph – new metadata is loaded automatically • Asynchronous calls (and much more!) var xcore = require('bindings')('xcore'); xcore.initialize(__dirname + "Sample", "SampleLibrary.dll", "SampleLibrary.Initializer"); xcore.loadClass("SampleLibrary.OrderSample. OrderManager, SampleLibrary"); var om = new xcore.OrderManager("raf"); console.log(om.Add("Hello, ", "world")); console.log(om.SelectedOrder.Name); om.AddAsync(2, 3, function(res){ console.log(res); });
  • 7. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Node.js® is a well-known runtime environment for javascript • It leverages the power of "V8", the engine of Google Chrome – V8 conforms to the ECMAScript 262 standard – runs cross-platforms • NodeJs has a vivid ecosystem with tons of 3rd party libraries • V8 can be extended with native addons (C++): – When you need more performance – To access operating system's resources and services – To interoperate with external systems / hardware Node.JS and V8 https://nodejs.org
  • 8. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Including the libraries • Declare the Entry-Point using the NODE_MODULE macro • Implement the entry-point and declare javascript-friendly methods • The "Method" will be available as "hello" to javascript The basic structure of a C++ V8 addon #include <node.h> #include <v8.h> NODE_MODULE(addon, init) void init(Local<Object> exports) { NODE_SET_METHOD(exports, "hello", Method); } void Method(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); args.GetReturnValue().Set( String::NewFromUtf8(isolate, "world")); } // javascript code const addon = require('./myAddon'); console.log(addon.hello()); // 'world'
  • 9. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals V8 Object Wrapping • By deriving the ObjectWrap class, we can expose objects to JS • Object members are added dynamically – Constructors, methods, properties, indexers – Just set the members spcifying the class name • All member are static void functions – Their input parameter is a "const FunctionCallbackInfo<Value>& args" • The args contain the runtime values of the arguments – The wrapper instance is get using ObjectWrap:Unwrap – The return value is set using "args.GetReturnValue().Set(…);" exports->Set(v8className, constructorTemplate->GetFunction());
  • 10. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • LibUV is the threading library used by NodeJs and V8 • The JS code must be always executed in the main thread • .NET methods returning Task<T> must to be marshalled back to the main thread • The LibUV library gives a very basic support for enqueuing messages in its threads Threading and the libuv threading library
  • 11. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Demo: a simple V8 plugin
  • 12. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Hosting the CoreCLR • What does it mean hosting the CLR? – A native (C++) application can load the CLR, some assemblies and run managed (.NET) code – SQL Server is a great example of native application hosting the CLR – You can do it too! • The CLR in .NET Framework could be hosted only on Windows – It is based on the COM infrastructure • Net Core can be hosted as well but cross-platform – It mimics the COM interfaces, but the infrastructure is not COM- dependent
  • 13. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Demo: loading the CLR
  • 14. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals XCORE WRAP UP
  • 15. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Metadata for the CLR type is loaded –The C++ layer dynamically add the class definition to V8 • A member is invoked –The C++ layer gets the arguments of the call –A Reverse PInvoke is done to C# –The instance identifier is retrieved from a global table –If not available, the marshaller code is generated –The code is invoked xcore execution flow
  • 16. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • The call was synchronous –The return value is marshalled back to C++ and V8 • The call was asynchronous –In C++ the return value is queued in LibUV main thread • The call was an exception –It is propagated to the caller xcore execution flow
  • 17. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Performance profile • There are still many possible improvements • The add use-case is not realistic – it just measures infrastructure and marshalling – 4 marshalling involved: (JS  C++  .NET  C++  JS) 1 Million calls js: 6.156 ms c++: 56.352 ms .net: 1294.254 ms console.time("net"); for(var i=0; i<loop; i++) { om.NetAdd(i, i); } console.timeEnd("net"); console.time("c++"); for(var i=0; i<loop; i++) { xcore.add(i, i); } console.timeEnd("c++"); console.time("js"); for(var i=0; i<loop; i++) { LocalAdd(i, i); } console.timeEnd("js"); js: 6.156ms c++: 56.352ms .net: 1294.254ms var om = new xcore.OrderManager(); om.Add(2, 2); // jitting LocalAdd(2,2); // jitting xcore.add(2, 2); // jitting var loop = 1000000; // 1 Million function LocalAdd(x, y) { return x + y; } prepare the benchmark local javascript C++ only xcore + C#
  • 18. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Use-cases 1. Node.js applications 2. UI created with the Electron framework – Ability to create .NET ViewModels for Angular (by Google) 3. Using JS to script Windows Powershell 4. Nativescript Mobile applications – Nativescript is a project by Progress Software Corporation https://www.nativescript.org/ 5. Anything else based on V8 http://electron.atom.io
  • 19. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Questions? Thank you!