Java has been the historical leader for enterprise web application development. However, Node.js is rapidly gaining in popularity for developing mobile apps, APIs and web applications. Java and Node.js are complimentary tools for enterprise web application development and this session will highlight the strengths and complimentary nature of each.
Presented at IBM InterConnect 2016
2. IMPORTANT info regarding IBM speaker guidelines and disclaimers
• If your presentation has forward looking content, it is mandatory that you put the forward disclaimer as
slide 2 in your presentation (this is the “Please Note” slide, third slide down in this template).
• All presentations, whether they have future content or not, must include the mandatory “Notices and
Disclaimers” – slides 8 and 9 in the template. Insert these slides just before the “Thank You” slide in
your deck.
• Please refer to the FAQ document in the Speaker Kit regarding additional legal guidance for use of
photos, logos, customer references and analyst information.
• It is recommended to have your material reviewed by Legal if you have any concerns regarding your
content.
• Please submit your final presentation, using the instructions in the online Speaker Kit, by February
5th, 2016. Post your final file in native format using the following naming convention: session code.ppt
(For example, 1576.ppt)
• Disclosures regarding forward guidance is embedded in the tool and also available through this link:
• https://w3-03.ibm.com/finance/finsubp.nsf/WebPages/N01FF08SoftwareRevenueRecognitionGuidelinesRelatedtoProductDisclosures
• Please remove these instructions before finalizing your presentation.
2
3. Please Note:
3
• IBM’s statements regarding its plans, directions, and intent are subject to change or withdrawal without notice at IBM’s sole discretion.
• Information regarding potential future products is intended to outline our general product direction and it should not be relied on in
making a purchasing decision.
• The information mentioned regarding potential future products is not a commitment, promise, or legal obligation to deliver any
material, code or functionality. Information about potential future products may not be incorporated into any contract.
• The development, release, and timing of any future features or functionality described for our products remains at our sole discretion.
• Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual
throughput or performance that any user will experience will vary depending upon many factors, including considerations such as the
amount of multiprogramming in the user’s job stream, the I/O configuration, the storage configuration, and the workload processed.
Therefore, no assurance can be given that an individual user will achieve results similar to those stated here.
10. 10
var cluster = require('cluster');
var cpus = require('os').cpus().length;
var http = require('http');
if (cluster.isMaster) {
for (var i = 0; i < cpus; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log("Worker" + worker.pid + "died");
});
} else {
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World!n");
response.end();
}).listen(8080);
}
Writing a HTTP Server
11. 11
var cluster = require('cluster');
var cpus = require('os').cpus().length;
var http = require('http');
if (cluster.isMaster) {
for (var i = 0; i < cpus; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log("Worker" + worker.pid + "died");
});
} else {
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World!n");
response.end();
}).listen(8080);
}
And Clustering It….
12. 12
● One thread (or process) per connection
- Each thread waits on a response
- Scalability determined by the number
of threads
● Each thread:
- consumes memory
- is relatively idle
● Concurrency determined by number of
depot workers
Typical Java Approach to Scalable I/O
13. 13
● One thread multiplexes for multiple requests
- No waiting for a response
- Handles return from I/O when notified
● Scalability determined by:
- CPU usage
- “Back end” responsiveness
● Concurrency determined by how fast the
food server can work
Node.js approach to Scalable I/O
17. 17
● The web has moved from Web Sites to Web Applications
From Web Sites to Web Apps
18. ● JavaScript is ubiquitous in the browser
- Supported in every browser
- Integration with HTML and CSS
● JavaScript is not affected by negative publicity....
18
Unless it is absolutely necessary to run Java in web browsers, disable it as
described below, even after updating to 7u11. This will help mitigate other Java
vulnerabilities that may be discovered in the future.
This and previous Java vulnerabilities have been widely targeted by attackers, and
new Java vulnerabilities are likely to be discovered. To defend against this and future
Java vulnerabilities, consider disabling Java in web browsers…
Programming in the Browser
19. 19
FullStack JavaScript Development
● Reuse of programming skills and teams
● Reuse of skills for both client and server side code
● Reuse of “isomorphic” code components
● Reuse of code for both client and server
● Write One Run Anywhere
● Faster user experience performance
● Use of server side rendering
20. 20
Server Side Rendering
● Pre-Initialisation of the client UI on
the server:
● Improves time for the first
elements appearing in the UI
● Has additional benefits:
● Search Engine Indexing
● Easier code maintenance
22. 22
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
23. 23
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
24. 24
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
25. 25
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
26. 26
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
27. 27
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
String a = new String(“5”);
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = ‘5’;
var b = 3;
add(a, b);
> node app.js
> 8
28. 28
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
String a = new String(“5”);
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = ‘5’;
var b = 3;
add(a, b);
> node app.js
> 8
29. 29
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
String a = new String(“5”);
int b = 3;
add(a, b);
}
> javac app.java
Error: incompatible types: String
cannot be converted to int
add(a, b);
^
var add = function (a, b) {
console.log(a + b);
}
var a = ‘5’;
var b = 3;
add(a, b);
> node app.js
> 8
30. 30
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
String a = new String(“5”);
int b = 3;
add(a, b);
}
> javac app.java
Error: incompatible types: String
cannot be converted to int
add(a, b);
^
var add = function (a, b) {
console.log(a + b);
}
var a = ‘5’;
var b = 3;
add(a, b);
> node app.js
> 53
33. 33
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // String minus String = Integer??
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
34. 34
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // String minus String = Integer??
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
35. 35
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
36. 36
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
37. 37
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
38. 38
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
39. 39
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
40. 40
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
41. 41
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // Multiple plus must cause String to number conversion
42. 42
JavaScript Calculations
> '5' + - '5'
'5-2' // I can just about see that works
> var x = 3
undefined
> '5' – x + x
5 // Ok, that makes sense
> var x = 3
undefined
> '5' + x - x
50 // What???
43. 43
JavaScript Calculations
> '5' + - '5'
'5-2' // I can just about see that works
> var x = 3
> '5' – x + x
5 // Ok, that makes sense
> var x = 3
undefined
> '5' + x - x
50 // What???
44. 44
JavaScript Calculations
> '5' + - '5'
'5-2' // I can just about see that works
> var x = 3
> '5' – x + x
5 // Ok, that makes sense
> var x = 3
> '5' + x - x
50 // What???
46. ● JSON serialization of a newly
instantiated object
● Maps
- Key of message
- Value of Hello, World!
● Example response:
46
Results from TechEmpower.com Round 9 tests (2014-05-01)
JSON Serialisation
47. ● JSON serialization of a newly
instantiated object
● Maps
- Key of message
- Value of Hello, World!
● Example response:
47
Results from TechEmpower.com Round 9 tests (2014-05-01)
JSON Serialisation
Java
JavaScript
49. ● Fetches single row from simple
database table
● Row serialized as JSON
● Example response:
49
Results from TechEmpower.com Round 9 tests (2014-05-01)
Single Query
50. ● Fetches single row from simple
database table
● Row serialized as JSON
● Example response:
50
Results from TechEmpower.com Round 9 tests (2014-05-01)
Single Query
Java
JavaScript
56. 56
Node.js Web App Performance vs. Java
-100
-80
-60
-40
-20
0
20
40
-18
Node.js Performance
(Compared to Java)
JSON Serialization
Single Query
Multiple Queries
%ageofJavaPerformance
57. ● Fetches multiple rows from a table
● Converts rows to objects and
modifies one attribute of each object
● Updates each associated row and
serializes as JSON
● Example Response:
57
Results from TechEmpower.com Round 9 tests (2014-05-01)
Data Updates
58. ● Fetches multiple rows from a table
● Converts rows to objects and
modifies one attribute of each object
● Updates each associated row and
serializes as JSON
● Example Response:
58
Results from TechEmpower.com Round 9 tests (2014-05-01)
Data Updates
Java
JavaScript
59. 59
Node.js Web App Performance vs. Java
-100
-80
-60
-40
-20
0
20
40
-18
Node.js Performance
(Compared to Java)
JSON Serialization
Single Query
Multiple Queries
%ageofJavaPerformance
60. 60
Node.js Web App Performance vs. Java
-100
-80
-60
-40
-20
0
20
40
28
Node.js Performance
(Compared to Java)
JSON Serialization
Single Query
Multiple Queries
Data Updates
%ageofJavaPerformance
61. 61
Node.js Web App Performance vs. Java
-100
-80
-60
-40
-20
0
20
40
28
Node.js Performance
(Compared to Java)
JSON Serialization
Single Query
Multiple Queries
Data Updates
%ageofJavaPerformance
More
Computation
More
I/O
62. 6217*IBM created open sourced benchmark, being considered for endorsement by Node Foundation
Node.js Web App Performance
• Results from Acme Air*:
− Flight booking benchmark that includes large I/O component
− https://github.com/acmeair/acmeair
63. 63
● JIT Compilers thrive on certainty
● Allows functions to be implemented as efficiently as possible
● Dynamic typing forces the JIT to do more work:
● Variables could be function, or data
● Variables must be tested to determine how to handle them
● Variable types can change over time
Variable Typing and Just-In-Time (JIT) Compilation
70. 70
Just-In-Time (JIT) Compilation: The ‘+’ operator
var add = function (a, b) {
return (a + b);
}
Check
type of
A
String NumberString
Check
type of
B
Number
71. 71
Just-In-Time (JIT) Compilation: The ‘+’ operator
var add = function (a, b) {
return (a + b);
}
Check
type of
A
String NumberString
Check
type of
B
Number
Concatenate
72. 72
Just-In-Time (JIT) Compilation: The ‘+’ operator
var add = function (a, b) {
return (a + b);
}
Check
type of
A
String NumberString
Check
type of
B
Number
Concatenate
Concatenate
73. 73
Just-In-Time (JIT) Compilation: The ‘+’ operator
var add = function (a, b) {
return (a + b);
}
Check
type of
A
String NumberString
Check
type of
B
Number
Concatenate
Concatenate
String
Check
type of
B
Number
74. 74
Just-In-Time (JIT) Compilation: The ‘+’ operator
var add = function (a, b) {
return (a + b);
}
Check
type of
A
String NumberString
Check
type of
B
Number
Concatenate
Concatenate
String
Check
type of
B
Number
Concatenate
75. 75
Just-In-Time (JIT) Compilation: The ‘+’ operator
var add = function (a, b) {
return (a + b);
}
Check
type of
A
String NumberString
Check
type of
B
Number
Concatenate
Concatenate
String
Check
type of
B
Number
Concatenate
Floating
Point or
Normal
NormalFloat
76. 76
Just-In-Time (JIT) Compilation: The ‘+’ operator
var add = function (a, b) {
return (a + b);
}
Check
type of
A
String NumberString
Check
type of
B
Number
Concatenate
Concatenate
String
Check
type of
B
Number
Concatenate
Floating
Point or
Normal
NormalFloat Add Instruction
77. 77
Just-In-Time (JIT) Compilation: The ‘+’ operator
var add = function (a, b) {
return (a + b);
}
Check
type of
A
String NumberString
Check
type of
B
Number
Concatenate
Concatenate
String
Check
type of
B
Number
Concatenate
Floating
Point or
Normal
NormalFloat Add InstructionFloat Calculation
78. 78
Dynamically vs. Statically Typed Languages
-70
-60
-50
-40
-30
-20
-10
0
Dynamic vs Statically Typed Language Performance
JSON
Single
Multi
Updates
Bestdynamiccomparedtobeststaticasbaseline
● Best statically typed language much better than best dynamic
80. 80
“Do one thing, and do it well”
● Services are small and targeted to their task
● Services are organized around capabilities
● Services are self contained, storing their own data
Microservices Paradigm
82. 82
Choosing the Right Language for the Service
0
500
1000
1500
2000
2500
3000
regex-dna
n-body
binary-trees spectral-norm
fannkuch-redux
reverse-com
plim
ent
k-nucleo>de
fasta
Volume of Code
Node.js
Java
83. 83
Node.js
0
- 4x
+ 1/3x
Node.jsPerformanceRelativetoJava
CPU Bound I/O Bound
* based on TechEmpower benchmark results
Application Performance
(higher is better)
Choosing the Right Language for the Service
0
500
1000
1500
2000
2500
3000
regex-dna
n-body
binary-trees spectral-norm
fannkuch-redux
reverse-com
plim
ent
k-nucleo>de
fasta
Volume of Code
Node.js
Java
84. 84
Node.js
0
- 4x
+ 1/3x
Node.jsPerformanceRelativetoJava
CPU Bound I/O Bound
* based on TechEmpower benchmark results
Application Performance
(higher is better)
Choosing the Right Language for the Service
0
500
1000
1500
2000
2500
3000
regex-dna
n-body
binary-trees spectral-norm
fannkuch-redux
reverse-com
plim
ent
k-nucleo>de
fasta
Volume of Code
Node.js
Java
Error: incompatible types
ClassCastException
85. 85
● Higher performance for I/O
● Easier async programming
● Fullstack/isomorphic development
Choosing the Right Language for the Service
86. 86
Choosing the Right Language for the Service
● Higher processing performance
● Type safety for calculations
● Rich processing frameworks
87. 87
● Highly performant, scalable rich web applications
● Highly performant, reliable transaction processing
● Self-contained micro-service components
Choosing the Right Language for the Service
+
114. Notices and Disclaimers Con’t.
114
Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not
tested those products in connection with this publication and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products.
Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. IBM does not warrant the quality of any third-party products, or the
ability of any such third-party products to interoperate with IBM’s products. IBM EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The provision of the information contained h erein is not intended to, and does not, grant any right or license under any IBM patents, copyrights, trademarks or other intellectual
property right.
IBM, the IBM logo, ibm.com, Aspera®, Bluemix, Blueworks Live, CICS, Clearcase, Cognos®, DOORS®, Emptoris®, Enterprise Document Management System™, FASP®,
FileNet®, Global Business Services ®, Global Technology Services ®, IBM ExperienceOne™, IBM SmartCloud®, IBM Social Business®, Information on Demand, ILOG,
Maximo®, MQIntegrator®, MQSeries®, Netcool®, OMEGAMON, OpenPower, PureAnalytics™, PureApplication®, pureCluster™, PureCoverage®, PureData®,
PureExperience®, PureFlex®, pureQuery®, pureScale®, PureSystems®, QRadar®, Rational®, Rhapsody®, Smarter Commerce®, SoDA, SPSS, Sterling Commerce®,
StoredIQ, Tealeaf®, Tivoli®, Trusteer®, Unica®, urban{code}®, Watson, WebSphere®, Worklight®, X-Force® and System z® Z/OS, are trademarks of International Business
Machines Corporation, registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM
trademarks is available on the Web at "Copyright and trademark information" at: www.ibm.com/legal/copytrade.shtml.
115. Thank You
Your Feedback is Important!
Access the InterConnect 2016 Conference Attendee
Portal to complete your session surveys from your
smartphone,
laptop or conference kiosk.