SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
Server-Side JS @ StartHQ
Node, Fibers, Common Node etc.
Fibers
● lightweight threads
● co-operative multitasking
○ still using one event loop
● individual stack, shared heap
○ require a bit of additional memory for stacks
● similar to generators (in ES6)
○ but no need to mark each yielding method
Fibers usage example
function sleep(ms) {
var fiber = Fiber.current;
setTimeout(function() {
fiber.run();
}, ms);
Fiber.yield();
}
Sleep: Async. vs. Sync.
console.log('before');
setTimeout(function() {
console.log('after 1s');
}, 1000);
console.log('before');
sleep(1000);
console.log('after 1s');
CommonJS
● Set of specifications
○ Modules, Packages, Unit Testing
○ Binary, IO, Filesystem, JSGI, etc.
● Implemented by RingoJS and others
○ Ringo runs on top of the JVM
● Node supports the first 3, but not others
because they assume sync. I/O
Common Node
● Implements CommonJS specs using Fibers
on top of Node
● Allows for code reuse with RingoJS
● Simplifies business logic & debugging
○ supports for, exceptions etc. for flow control
● Performance: 80%-120% of Node
○ Uses a bit more memory e.g. 28MB vs. 32MB
Benchmarks
Node Streams
var body = [];
stream.on('data', function (chunk) {
body.push(chunk);
})
stream.on('end', function () {
callback(body);
});
Node Streams2
var body = [];
stream.on('readable', function () {
body.push(stream.read());
})
stream.on('end', function () {
callback(body);
});
Common Node Streams
var body = [], chunk;
while(chunk = stream.read(null)) {
body.push(chunk);
}
return body;
OR
return stream.read();
Ecosystem
● Ringo modules
● Common Utils
● Mongo Sync
● Stick
● Wrapping Node packages
Common Node at StartHQ
● Use it for everything
○ API, static resources
○ background processing
○ command line tools
● Extractors API
● Sentry stack traces
Pitfalls
● Trying to yield or resume outside fiber
● Using async libs with fibers, such as Express
● Writing to global variables
● Separate fiber instance per dependency
● Unreliable third party packages
○ Throws into event loop & crashed program
GitHub Links
● laverdet/node-fibers
● olegp/common-node
● olegp/notes
● starthq/extractor
Thank you!
@alexlamsl

Contenu connexe

Plus de Oleg Podsechin

What every developer can learn from startups
What every developer can learn from startupsWhat every developer can learn from startups
What every developer can learn from startupsOleg Podsechin
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
Current State of Server Side JavaScript
Current State of Server Side JavaScriptCurrent State of Server Side JavaScript
Current State of Server Side JavaScriptOleg Podsechin
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScriptOleg Podsechin
 
Grid and Cloud Computing Intro
Grid and Cloud Computing IntroGrid and Cloud Computing Intro
Grid and Cloud Computing IntroOleg Podsechin
 

Plus de Oleg Podsechin (11)

Lean and mean MongoDB
Lean and mean MongoDBLean and mean MongoDB
Lean and mean MongoDB
 
RingoJS
RingoJSRingoJS
RingoJS
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
What every developer can learn from startups
What every developer can learn from startupsWhat every developer can learn from startups
What every developer can learn from startups
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Current State of Server Side JavaScript
Current State of Server Side JavaScriptCurrent State of Server Side JavaScript
Current State of Server Side JavaScript
 
On Platforms
On PlatformsOn Platforms
On Platforms
 
Common Node
Common NodeCommon Node
Common Node
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
 
RingoJS
RingoJSRingoJS
RingoJS
 
Grid and Cloud Computing Intro
Grid and Cloud Computing IntroGrid and Cloud Computing Intro
Grid and Cloud Computing Intro
 

Dernier

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
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 RobisonAnna Loughnan Colquhoun
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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 DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Dernier (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Using Common Node to build StartHQ

  • 1. Server-Side JS @ StartHQ Node, Fibers, Common Node etc.
  • 2. Fibers ● lightweight threads ● co-operative multitasking ○ still using one event loop ● individual stack, shared heap ○ require a bit of additional memory for stacks ● similar to generators (in ES6) ○ but no need to mark each yielding method
  • 3. Fibers usage example function sleep(ms) { var fiber = Fiber.current; setTimeout(function() { fiber.run(); }, ms); Fiber.yield(); }
  • 4. Sleep: Async. vs. Sync. console.log('before'); setTimeout(function() { console.log('after 1s'); }, 1000); console.log('before'); sleep(1000); console.log('after 1s');
  • 5. CommonJS ● Set of specifications ○ Modules, Packages, Unit Testing ○ Binary, IO, Filesystem, JSGI, etc. ● Implemented by RingoJS and others ○ Ringo runs on top of the JVM ● Node supports the first 3, but not others because they assume sync. I/O
  • 6. Common Node ● Implements CommonJS specs using Fibers on top of Node ● Allows for code reuse with RingoJS ● Simplifies business logic & debugging ○ supports for, exceptions etc. for flow control ● Performance: 80%-120% of Node ○ Uses a bit more memory e.g. 28MB vs. 32MB
  • 8. Node Streams var body = []; stream.on('data', function (chunk) { body.push(chunk); }) stream.on('end', function () { callback(body); });
  • 9. Node Streams2 var body = []; stream.on('readable', function () { body.push(stream.read()); }) stream.on('end', function () { callback(body); });
  • 10. Common Node Streams var body = [], chunk; while(chunk = stream.read(null)) { body.push(chunk); } return body; OR return stream.read();
  • 11. Ecosystem ● Ringo modules ● Common Utils ● Mongo Sync ● Stick ● Wrapping Node packages
  • 12. Common Node at StartHQ ● Use it for everything ○ API, static resources ○ background processing ○ command line tools ● Extractors API ● Sentry stack traces
  • 13. Pitfalls ● Trying to yield or resume outside fiber ● Using async libs with fibers, such as Express ● Writing to global variables ● Separate fiber instance per dependency ● Unreliable third party packages ○ Throws into event loop & crashed program
  • 14. GitHub Links ● laverdet/node-fibers ● olegp/common-node ● olegp/notes ● starthq/extractor