SlideShare a Scribd company logo
Emerging Paradigms -
Server Side Event Driven
     Programming
            Kamal Hussain
  http://www.linkedin.com/in/hussainkamal/
Agenda
●   Linear Vs Nonlinear Code
●   Concurrency through threads and events
●   Event loop
●   PHP and Javascript
●   Node.js - closeup
●   Important concepts
We are used to ..
val client = new HttpClient()
val method = new GetMethod("http:
//www.google.com")

val statusCode = client.executeMethod
(method)

println("Server responded with %d" .
format(statusCode))
Event driven approach
var callback = function(data) {
   console.log("firing callback " +
data);
};

$.get('/endpoint', callback);

console.log('Did you see callback?');
Achieving scale and concurrency
● Multiple threads/processes
● Size the threadpool correctly
● Each thread is responsible for one task such
  as serving a request
● Asynchronous programming
Asynchronous with
threads/processes
Asynchronous with events
Problems with Threads
●   Hard to program
●   Memory requirements are high
●   Large overhead
●   Context switching
●   Priority inversion
Threads wait




      udemy.com
Cost of IO

L1 Cache 3 Cycles
L2 Cache 14 Cycles
    RAM 250 cycles
    Disk 41 000 000 cycles
 Network 240 000 000 cycles
Server Side Event Driven Programming
Event Loop Architecture




      courtsey: http://www.johanndutoit.net/
Writing synchronous Vs
Asynchronous
// Good: write files asynchronously
fs.writeFile('message.txt', 'Hello Node', function (err) {
 console.log("It's saved and the server remains responsive!");
});

// BAD: write files synchronously
fs.writeFileSync('message.txt', 'Hello Node');
console.log("It's saved, but you just blocked ALL requests!");


This can cause performance drop from thousands of requests/seconds to a few
dozen/second.
http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performance-tips-
linkedin-mobile
Tale of two languages
● PHP was invented in 1994 by Rasmus
  Lerdorfas as a replacement for CGI scripts
● PHP was a substitute for single-threaded C
  programs

● Brendan Eich developed Javascript in 1995
  for a completely different purpose. JS was
  designed to run within Netscape Navigator
  and was primarily designed to handle
  events.

PHP -> eventless, Javascript -> eventful
Node.js
● Ryan Dahl invented Node.js in 2009 as a
  continuation of Javascript heritage.

● Node.js is modeled after multi-task, multi-
  page handling of a web server.
What's Node.js?
"Node.js is a server-side software system designed for
writing scalable Internet applications, notably web servers.
Programs are written on the server side in JavaScript,
using event-driven, asynchronous I/O to minimize overhead
and maximize scalability."


      - from wikipedia
Node.js - asynchronous I/O
●   First class functions
●   Closures
●   Event loop
●   Callback counters

CPU intensive tasks are delegated to workers
PHP Way
$fp = fopen("fp.txt", 'w)
fwrite($fp, "hello world");
fclose($fp);
Node.js way
var fs = require('fs');

fs.open('fp.txt', 'w', 0666,
function(error, fp) {
  fw.write(fp, 'helloworld', null,
'utf-8', function() {
  fs.close(fp, function(error) {
    });
  });
});
Node.js simple example
var http = require('http');
http.createServer(function(req, res) {
  res.writeHead(200, {'Content-Type' :
'text/plain'});
  res.end("Hello Worldn");
}).listen(8000, "127.0.0.1");

console.log("Server running at http:
//127.0.0.1:8000");
Node.js Core APIs
Events
  EventTransmitter
  Event listener
  Event emitter
  Call back

Http

I/O
Node.js Workers

Synchronous call

Workers are blocked

Call returns
Workers Vs Events
Workers
 1 event per connection
 N workers per CPU

Events
  N connections per CPU
  1 process per CPU
Node.js Typical Applications
● Proxy

● API server
    ○ REST API calls
    ○ Simple transformations


See performance comparisons at:
http://www.slideshare.net/FabianFrankDe/nodejs-performance-case-study
Concepts to learn
First class functions
Lambdas - anonymous functions
Closures
Non-blocking IO
Deploying Node.js




http://www.slideshare.net/BenLin2/webconf-nodejsproductionarchitecture
Key takeaway



         Learn Javascript and
       functional programming.

         Future is brighter :)
Reference
● Node - Up and Running by Tom Hughes-Croucher,
    Mike Wilson - Oreilly
●   Node.js for PHP Developers - Oreilly
●   Javascript: The definitive guide - Oreilly
●   LinkedIn, Netflix Blogs
●   http://architects.dzone.com/articles/nodejs-php-
    programmers-1-event
●   https://www.udemy.com/lectures/understanding-the-
    nodejs-event-loop-91298
●   https://speakerdeck.com/guldenpt/before-start-coding-
    in-node-dot-js

More Related Content

What's hot (20)

PDF
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
PPTX
introduction to node.js
orkaplan
 
KEY
node.js: Javascript's in your backend
David Padbury
 
PDF
Nodejs in Production
William Bruno Moraes
 
PDF
Building servers with Node.js
ConFoo
 
PDF
Node.js Explained
Jeff Kunkle
 
PDF
Getting started with developing Nodejs
Phil Hawksworth
 
PPT
RESTful API In Node Js using Express
Jeetendra singh
 
PPTX
Node.js Workshop - Sela SDP 2015
Nir Noy
 
PDF
All aboard the NodeJS Express
David Boyer
 
PDF
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
PPTX
Introduction to Node js
Akshay Mathur
 
KEY
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
PDF
Nodejs Explained with Examples
Gabriele Lana
 
PDF
Node ppt
Tamil Selvan R S
 
PDF
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
PPTX
Intro to Node.js (v1)
Chris Cowan
 
PPT
Node js presentation
martincabrera
 
PPTX
Intro to node and non blocking io
Amy Hua
 
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
Introduction Node.js
Erik van Appeldoorn
 
introduction to node.js
orkaplan
 
node.js: Javascript's in your backend
David Padbury
 
Nodejs in Production
William Bruno Moraes
 
Building servers with Node.js
ConFoo
 
Node.js Explained
Jeff Kunkle
 
Getting started with developing Nodejs
Phil Hawksworth
 
RESTful API In Node Js using Express
Jeetendra singh
 
Node.js Workshop - Sela SDP 2015
Nir Noy
 
All aboard the NodeJS Express
David Boyer
 
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
Introduction to Node js
Akshay Mathur
 
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Nodejs Explained with Examples
Gabriele Lana
 
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
Intro to Node.js (v1)
Chris Cowan
 
Node js presentation
martincabrera
 
Intro to node and non blocking io
Amy Hua
 

Similar to Server Side Event Driven Programming (20)

PDF
Event driven programming -- Node.JS
Dimitri Teravanessian
 
PDF
Introduction to Node.js
Richard Lee
 
PDF
Node.js introduction
Parth Joshi
 
PPTX
Introduction to Node.js
Vikash Singh
 
PPTX
Nodejs
Vinod Kumar Marupu
 
PPTX
Proposal
Constantine Priemski
 
PPTX
Beginners Node.js
Khaled Mosharraf
 
ODP
Introduce about Nodejs - duyetdev.com
Van-Duyet Le
 
PPTX
An overview of node.js
valuebound
 
PPTX
Node.js: A Guided Tour
cacois
 
PPT
18_Node.js.ppt
KhalilSalhi7
 
PPTX
Node Session - 1
Bhavin Shah
 
PPT
Node
Manav Prasad
 
PDF
Tech io nodejs_20130531_v0.6
Ganesh Kondal
 
PPTX
Node
Ankit Chawla
 
PPT
18_Node.js.ppt
MaulikShah516542
 
PPT
New kid on the block node.js
Joel Divekar
 
PDF
Basic Understanding and Implement of Node.js
Gary Yeh
 
PDF
Introduction to Node JS.pdf
Bareen Shaikh
 
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
Event driven programming -- Node.JS
Dimitri Teravanessian
 
Introduction to Node.js
Richard Lee
 
Node.js introduction
Parth Joshi
 
Introduction to Node.js
Vikash Singh
 
Beginners Node.js
Khaled Mosharraf
 
Introduce about Nodejs - duyetdev.com
Van-Duyet Le
 
An overview of node.js
valuebound
 
Node.js: A Guided Tour
cacois
 
18_Node.js.ppt
KhalilSalhi7
 
Node Session - 1
Bhavin Shah
 
Tech io nodejs_20130531_v0.6
Ganesh Kondal
 
18_Node.js.ppt
MaulikShah516542
 
New kid on the block node.js
Joel Divekar
 
Basic Understanding and Implement of Node.js
Gary Yeh
 
Introduction to Node JS.pdf
Bareen Shaikh
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
Ad

Recently uploaded (20)

PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Ad

Server Side Event Driven Programming

  • 1. Emerging Paradigms - Server Side Event Driven Programming Kamal Hussain http://www.linkedin.com/in/hussainkamal/
  • 2. Agenda ● Linear Vs Nonlinear Code ● Concurrency through threads and events ● Event loop ● PHP and Javascript ● Node.js - closeup ● Important concepts
  • 3. We are used to .. val client = new HttpClient() val method = new GetMethod("http: //www.google.com") val statusCode = client.executeMethod (method) println("Server responded with %d" . format(statusCode))
  • 4. Event driven approach var callback = function(data) { console.log("firing callback " + data); }; $.get('/endpoint', callback); console.log('Did you see callback?');
  • 5. Achieving scale and concurrency ● Multiple threads/processes ● Size the threadpool correctly ● Each thread is responsible for one task such as serving a request ● Asynchronous programming
  • 8. Problems with Threads ● Hard to program ● Memory requirements are high ● Large overhead ● Context switching ● Priority inversion
  • 9. Threads wait udemy.com
  • 10. Cost of IO L1 Cache 3 Cycles L2 Cache 14 Cycles RAM 250 cycles Disk 41 000 000 cycles Network 240 000 000 cycles
  • 12. Event Loop Architecture courtsey: http://www.johanndutoit.net/
  • 13. Writing synchronous Vs Asynchronous // Good: write files asynchronously fs.writeFile('message.txt', 'Hello Node', function (err) { console.log("It's saved and the server remains responsive!"); }); // BAD: write files synchronously fs.writeFileSync('message.txt', 'Hello Node'); console.log("It's saved, but you just blocked ALL requests!"); This can cause performance drop from thousands of requests/seconds to a few dozen/second. http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performance-tips- linkedin-mobile
  • 14. Tale of two languages ● PHP was invented in 1994 by Rasmus Lerdorfas as a replacement for CGI scripts ● PHP was a substitute for single-threaded C programs ● Brendan Eich developed Javascript in 1995 for a completely different purpose. JS was designed to run within Netscape Navigator and was primarily designed to handle events. PHP -> eventless, Javascript -> eventful
  • 15. Node.js ● Ryan Dahl invented Node.js in 2009 as a continuation of Javascript heritage. ● Node.js is modeled after multi-task, multi- page handling of a web server.
  • 16. What's Node.js? "Node.js is a server-side software system designed for writing scalable Internet applications, notably web servers. Programs are written on the server side in JavaScript, using event-driven, asynchronous I/O to minimize overhead and maximize scalability." - from wikipedia
  • 17. Node.js - asynchronous I/O ● First class functions ● Closures ● Event loop ● Callback counters CPU intensive tasks are delegated to workers
  • 18. PHP Way $fp = fopen("fp.txt", 'w) fwrite($fp, "hello world"); fclose($fp);
  • 19. Node.js way var fs = require('fs'); fs.open('fp.txt', 'w', 0666, function(error, fp) { fw.write(fp, 'helloworld', null, 'utf-8', function() { fs.close(fp, function(error) { }); }); });
  • 20. Node.js simple example var http = require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type' : 'text/plain'}); res.end("Hello Worldn"); }).listen(8000, "127.0.0.1"); console.log("Server running at http: //127.0.0.1:8000");
  • 21. Node.js Core APIs Events EventTransmitter Event listener Event emitter Call back Http I/O
  • 22. Node.js Workers Synchronous call Workers are blocked Call returns
  • 23. Workers Vs Events Workers 1 event per connection N workers per CPU Events N connections per CPU 1 process per CPU
  • 24. Node.js Typical Applications ● Proxy ● API server ○ REST API calls ○ Simple transformations See performance comparisons at: http://www.slideshare.net/FabianFrankDe/nodejs-performance-case-study
  • 25. Concepts to learn First class functions Lambdas - anonymous functions Closures Non-blocking IO
  • 27. Key takeaway Learn Javascript and functional programming. Future is brighter :)
  • 28. Reference ● Node - Up and Running by Tom Hughes-Croucher, Mike Wilson - Oreilly ● Node.js for PHP Developers - Oreilly ● Javascript: The definitive guide - Oreilly ● LinkedIn, Netflix Blogs ● http://architects.dzone.com/articles/nodejs-php- programmers-1-event ● https://www.udemy.com/lectures/understanding-the- nodejs-event-loop-91298 ● https://speakerdeck.com/guldenpt/before-start-coding- in-node-dot-js